MCP server
POST /v1/mcp — Streamable HTTP Model Context Protocol endpoint that exposes your Cocobox connections as tools to any MCP client.
The Cocobox MCP server lets any Model Context Protocol-aware client (GitHub Copilot in VS Code, Cursor, Zed, opencode, Claude Code, …) call your Cocobox connections as tools — securely, with full audit logging, and with the same sk-coco-* key as the rest of the API.
https://api.cocobox.io/v1/mcp Authenticated with Authorization: Bearer sk-coco-… Transport
Cocobox implements the MCP Streamable HTTP transport:
- All client → server calls are HTTP
POSTto/v1/mcp. - Server → client streaming uses chunked
text/event-streamresponses. - Sessions are tracked via the
Mcp-Session-Idrequest and response header.
Authentication
Send Authorization: Bearer sk-coco-… (or x-api-key) on every request. The key must have tools_enabled: true — otherwise the server returns 403 tools_disabled. See Authentication.
Session lifecycle
-
Initialize. First request sets up a session.
POST /v1/mcp HTTP/1.1 Authorization: Bearer sk-coco-… Content-Type: application/json { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": { "name": "vscode-copilot", "version": "1.95.0" } } }The server responds with capabilities and
Mcp-Session-Idin the response headers (cached for 1 hour in Redis). -
Subsequent calls must include
Mcp-Session-Id: <id>. Calls without it on a non-initialize method return404 Session not found or expired. -
Tool listing.
tools/listreturns the current catalog (see Reference → MCP tools). -
Tool calls.
tools/callwith the tool name and arguments. The server runs the tool against your connection (validating per-key scopes) and returns the result — possibly streaming. -
Close. Idle sessions expire after 1 hour. Clients can re-initialize at any time.
Available tools
| Tool | Purpose |
|---|---|
sql_list_connections | List the user’s connections (id, name, dialect, host, default DB). |
sql_describe | Describe a table (columns, types, indexes, foreign keys). |
sql_list_tables | List tables in a database/schema. |
sql_run | Execute a read-only SQL query. Server-side guard rejects DML/DDL by default. |
sql_explain | Run EXPLAIN on a query. |
sql_history | Recent queries from the user’s history. |
See Reference → MCP tools for full schemas, examples, and error semantics.
Examples
{
"mcp": {
"cocobox": {
"type": "remote",
"url": "https://api.cocobox.io/v1/mcp",
"headers": {
"Authorization": "Bearer ${COCOBOX_API_KEY}"
}
}
}
} {
"mcpServers": {
"cocobox": {
"type": "http",
"url": "https://api.cocobox.io/v1/mcp",
"headers": {
"Authorization": "Bearer ${COCOBOX_API_KEY}"
}
}
}
} {
"servers": {
"cocobox": {
"type": "http",
"url": "https://api.cocobox.io/v1/mcp",
"headers": {
"Authorization": "Bearer ${env:COCOBOX_API_KEY}"
}
}
}
} curl https://api.cocobox.io/v1/mcp \
-H "Authorization: Bearer $COCOBOX_API_KEY" \
-H "Content-Type: application/json" \
-i \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": { "name": "curl", "version": "8.4" }
}
}' Error envelope
Errors are returned as JSON-RPC 2.0 errors:
{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32602, "message": "Invalid params: connection_id is required" } }
HTTP-level errors (auth, missing session) use the standard Cocobox envelope:
{ "status": 403, "error": "tools_disabled", "message": "tools_enabled is false for this API key" }
What’s next
- Reference → MCP tools — full schemas + samples for every tool.
- Integrations → GitHub Copilot (VS Code).
- Integrations → Claude Code.
- Integrations → opencode.