Guides · MCP
Connecting MCP clients
Authentication, the JSON-RPC exchange, error mapping and approvals for clients of the MCP gateway.
Authenticate#
The gateway accepts the same bearer credentials as every other GebSecure endpoint:
- an access token of the agent (EdDSA JWT) — obtained from
POST {api}/v1/auth/tokenwith the agent's client secret or aprivate_key_jwtassertion. The SDKs do this for you:await gs.getAccessToken()(TypeScript),client.get_access_token()(Python),client.AccessToken(ctx)(Go),GetAccessTokenAsync()(.NET); - an API key (
gsk_…).
Access tokens are short-lived (ACCESS_TOKEN_TTL, 10 minutes by default); fetch a fresh one per request through
the SDK, which caches it. Requests without valid credentials get HTTP 401 with
WWW-Authenticate: Bearer resource_metadata="{gateway}/.well-known/oauth-protected-resource", as the MCP
authorization specification requires.
TOKEN=$(curl -s "$GEBSECURE_API_URL/v1/auth/token" -H 'content-type: application/json' \
-d "{\"grant_type\":\"client_credentials\",\"client_secret\":\"$GEBSECURE_CLIENT_SECRET\"}" | jq -r .access_token)The exchange#
Requests are JSON-RPC 2.0 POSTs with content-type: application/json. This is the client of the
MCP quickstart:
const gs = new GebSecure(); // GEBSECURE_CLIENT_SECRET → short-lived access tokens (cached, refreshed)
const endpoint = `${gs.gatewayUrl}/v1/mcp/${process.env.MCP_SERVER_SLUG ?? 'demo'}`; // or /v1/mcp for every server
let sessionId: string | undefined;
interface RpcResponse {
result?: { content?: { type: string; text?: string }[]; isError?: boolean; tools?: { name: string }[]; _meta?: { gebsecure?: Record<string, unknown> } };
error?: { code: number; message: string };
}
async function rpc(method: string, params: Record<string, unknown> = {}): Promise<RpcResponse> {
const res = await fetch(endpoint, {
method: 'POST',
headers: {
authorization: `Bearer ${await gs.getAccessToken()}`,
'content-type': 'application/json',
accept: 'application/json, text/event-stream',
...(sessionId ? { 'mcp-session-id': sessionId } : {}),
},
body: JSON.stringify({ jsonrpc: '2.0', id: randomUUID(), method, params }),
});
if (!res.ok) throw new Error(`${method} → HTTP ${res.status}: ${await res.text()}`);
if (method === 'initialize') sessionId = res.headers.get('mcp-session-id') ?? undefined;
return (await res.json()) as RpcResponse;
}
const init = await rpc('initialize', { protocolVersion: '2025-06-18', clientInfo: { name: 'quickstart', version: '1.0.0' }, capabilities: {} });
if (init.error) throw new Error(init.error.message);curl -si "$GEBSECURE_GATEWAY_URL/v1/mcp/demo" -H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","clientInfo":{"name":"curl","version":"1"},"capabilities":{}}}'
# HTTP/1.1 200 … mcp-session-id: <session id>
curl -s "$GEBSECURE_GATEWAY_URL/v1/mcp/demo" -H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-H "mcp-session-id: <session id>" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_forecast","arguments":{"city":"Lisbon"}}}'Notifications (messages without id) are acknowledged with HTTP 202. A batch may hold up to 50 messages.
Results and errors#
GebSecure decisions about a tool call are returned as a successful JSON-RPC result that is a tool error, so the model reads the reason and does not retry blindly:
{
"content": [{ "type": "text", "text": "Human approval is required before delete_note can run (…). Approval apr_… is pending; retry the identical call after it is approved." }],
"isError": true,
"_meta": { "gebsecure": { "decision": "APPROVAL_REQUIRED", "approvalId": "apr_…", "approvalUrl": "…", "expiresAt": "…" } }
}| Outcome | _meta.gebsecure |
Text starts with |
|---|---|---|
| Policy denial | {decision: "DENY", decisionId} |
GebSecure denied this call: |
| Approval required | {decision: "APPROVAL_REQUIRED", approvalId, approvalUrl, expiresAt} |
Human approval is required before … |
| Outbound DLP block (sensitive arguments) | {reason: "dlp_blocked"} |
GebSecure blocked this call: the arguments contain sensitive data (…) |
| Inbound DLP block | — | GebSecure withheld this result: it contains sensitive data. |
Prompt injection in the result (BLOCK) |
{detectionId} |
GebSecure withheld this result: it contains prompt-injection content. |
| Sanitized result | sanitized |
the sanitized content |
| Upstream server error | — | MCP server error: … |
Problems that are not decisions are JSON-RPC errors:
| Code | Cause |
|---|---|
-32000 |
missing Mcp-Session-Id |
-32001 |
forbidden — e.g. the tool is quarantined (is quarantined (definition changed; pending review)), blocked or not allowed by the server configuration |
-32002 |
rate_limited — the per-agent, per-server limit (rateLimitPerMinute) |
-32602 |
not_found or validation_failed — unknown server/session, or arguments that do not match the tool's pinned input schema |
-32601 |
unsupported method |
-32603 |
any other error |
Approvals#
When a call needs approval, a reviewer decides in the console, Slack or the API (see
Approvals). The client then sends the identical call again: the gateway builds
the snapshot hash from the principal, tool, resource attributes and arguments, finds the approved, unexpired
request for that hash and consumes it. The approval is single use — a further identical call needs a new
approval — and different arguments never match. An explicit DENY still wins over an approval.
Approvals are matched automatically only for agents bound to an environment (the normal case for registered agents).
Aggregated endpoint#
POST {gateway}/v1/mcp combines every server the agent may use. Tools and prompts are prefixed with the server
slug and a double underscore — demo__get_forecast — and resources carry _meta.server; pass params.server to
resources/read.