Reference
REST API and MCP Capabilities
This page documents the currently implemented HTTP API and MCP tools in Chantra, with request examples that map to the running code.
REST API: http://localhost:8080
MCP endpoint: http://localhost:8090/mcp
MCP compatibility alias: http://localhost:8090/sse
MCP discovery: http://localhost:8090/.well-known/mcp-server
MCP health: http://localhost:8090/healthz
Channel URLs in create responses use CHANNEL_HOSTNAME and are independent from REST/MCP bind addresses.
Access Model
No user registration or bearer auth is required. Channel management and publishing are authorized by X-Publish-Token. Private channel reads use a read token.
# Create channel (public)
curl -X POST http://localhost:8080/v1/channels \
-H 'Content-Type: application/json' \
-d '{"name":"orders","visibility":"private"}'
# Publish (requires publish token)
curl -X POST http://localhost:8080/v1/channels/$CHANNEL_ID/publish \
-H "X-Publish-Token: $PUBLISH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"payload":"order.created"}'
Error Shape
On API errors, responses use a consistent JSON envelope:
{
"error": {
"code": "invalid_input",
"message": "invalid request payload"
}
}
Common codes: invalid_json, invalid_input, unauthorized, forbidden, not_found, conflict.
REST Endpoints
- GET
/healthz Service health check.
- POST
/v1/channels Create channel with name, visibility, optional description and default_ttl_seconds.
- GET
/v1/channels/{channelID} Get channel details (X-Publish-Token required).
- DELETE
/v1/channels/{channelID} Soft-delete channel (X-Publish-Token required).
- POST
/v1/channels/{channelID}/publish Publish message (X-Publish-Token required).
- POST
/v1/channels/{channelID}/read-grants Create read grant (X-Publish-Token required), optional label and RFC3339 expires_at, returns one-time raw_token.
- POST
/v1/channels/{channelID}/read-grants/{grantID}/revoke Revoke read grant (X-Publish-Token required).
- SSE channel URL:
https://chantra.io/channel/v1/{public|private}/{channelID} (supports Last-Event-ID).
- Internal MCP read backend:
GET /internal/v1/channels/{channelID}/messages with after_message_id, limit.
REST Usage Example
Create a channel, create a read grant, then consume directly over SSE channel URL.
# Create channel
curl -X POST http://localhost:8080/v1/channels \
-H 'Content-Type: application/json' \
-d '{
"name":"orders",
"visibility":"private",
"description":"Order events for agents",
"default_ttl_seconds":3600
}'
# Create read grant
curl -X POST http://localhost:8080/v1/channels/$CHANNEL_ID/read-grants \
-H "X-Publish-Token: $PUBLISH_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"label":"support-agent"}'
# Read SSE (public)
curl -sS -N "https://chantra.io/channel/v1/public/$CHANNEL_ID"
# Read SSE (private)
curl -sS -N "https://chantra.io/channel/v1/private/$CHANNEL_ID" \
-H "Authorization: Bearer $READ_TOKEN"
MCP Tools
Available server tools for agent workflows:
create_channel Create a channel.
delete_channel Delete owned channel.
publish_message Publish payload to owned channel, optional metadata and TTL.
create_read_grant Issue read token for private channel.
revoke_read_grant Revoke read grant by ID.
get_channel Get owned channel details.
read_channel_messages Read channel messages via internal read backend.
MCP Tool Parameters
create_channel Required: name, visibility. Optional: description, default_ttl_seconds.
delete_channel Required: publish_token, channel_id.
publish_message Required: publish_token, channel_id, payload. Optional: metadata, ttl_seconds.
create_read_grant Required: publish_token, channel_id. Optional: label, expires_at (RFC3339).
revoke_read_grant Required: publish_token, channel_id, grant_id.
get_channel Required: publish_token, channel_id.
read_channel_messages Required: channel_id. Optional: read_token, after_message_id, limit.
MCP Usage Examples
Tool argument payloads for typical operations:
{
"tool": "create_channel",
"arguments": {
"name": "orders",
"visibility": "private",
"description": "Order events for agents",
"default_ttl_seconds": 3600
}
}
{
"tool": "publish_message",
"arguments": {
"publish_token": "pub_...",
"channel_id": "7bb4ecca-9a04-4c7e-84e0-2f55967a21d5",
"payload": "{\"event\":\"order.created\"}",
"metadata": {"source":"checkout-service"},
"ttl_seconds": 900
}
}
{
"tool": "read_channel_messages",
"arguments": {
"channel_id": "7bb4ecca-9a04-4c7e-84e0-2f55967a21d5",
"read_token": "rdg_...",
"after_message_id": "019e07c2-c7b9-7820-9c5e-222d299ffacb",
"limit": 100
}
}