Build & integrate
MCP gateway
Model Context Protocol JSON-RPC at POST /api/mcp — evaluate and fetch evaluations from MCP clients; mcp_trace on run bundles.
MCP gateway (Model Context Protocol)
AgentNexusAPI exposes a Streamable HTTP–compatible MCP endpoint so AI clients (Cursor, Claude Desktop, custom agents) can call governance as standard tools instead of hand-rolled REST. This complements direct POST /api/v1/evaluate: the MCP path is optimized for agent loops and records MCP trace metadata on evaluations for audit.
Industry momentum: vendors such as Hoop.dev are investing in MCP-centric agent operations; shipping a thin, standards-shaped gateway early keeps integrations portable.
Endpoint
- URL:
POST /api/mcpon your deployment origin (e.g.https://your-app.example/api/mcp). - Protocol: JSON-RPC 2.0 over HTTP. This build returns JSON bodies only (no server-sent event stream). Clients must still send MCP’s required
Acceptheader (see below). - Auth: Same as REST —
Authorization: Bearer <api_key>orx-api-key: <api_key>.
Required headers
Per MCP Streamable HTTP:
Accept: application/json, text/event-streamContent-Type: application/json
Security
- Origin allowlist (recommended in production): set
MCP_ALLOWED_ORIGINSto a comma-separated list of allowedOriginvalues (e.g.https://app.cursor.sh). Empty or unset → origin check skipped (browserOriginmay still be absent for non-browser clients). - API keys gate every JSON-RPC request (notifications without
idare the exception; see below).
JSON-RPC methods
| Method | Purpose |
|---|---|
initialize | Returns protocolVersion 2025-03-26, capabilities.tools, serverInfo. |
notifications/initialized | No id field → HTTP 202 empty body (lifecycle ack). |
tools/list | Lists MCP tools (see below). |
tools/call | Invokes a tool. |
ping | Health check; returns {}. |
Batch arrays are not supported in this version (send one message per request).
Tools
agentnexus_evaluate
Same semantics as POST /api/v1/evaluate. Arguments:
policy_name(string, required)payload_scope(object, required)agent_id(optional)webhook_url(optional)mcp_session_id/mcp_client_name(optional correlation — stored undercontext_json.mcp_traceandrun_bundle.mcp_trace)idempotency_key(optional → forwarded asIdempotency-Key)tool_calls/artifacts(optional, same caps as REST)
The gateway adds gateway, gateway_jsonrpc_id, and gateway_request_id to mcp_trace.
Tool result is JSON text:
{ "httpStatus": 200, "body": { "evaluation_id": "...", "status": "..." } }
On HTTP error, isError is true (MCP tools/call result).
agentnexus_get_evaluation
evaluation_id(UUID) — must belong to the API key’s workspace.
Returns evaluation row fields including context_json and run_bundle (can be large).
REST: context.mcp_trace
Even without MCP, you may set context.mcp_trace on POST /api/v1/evaluate with:
session_id,client_name,request_id,parent_span_id- optional
gateway,gateway_jsonrpc_id,gateway_request_idif you proxy through your own gateway
Idempotency: mcp_trace is excluded from the idempotency fingerprint so retries with different trace metadata still match the same Idempotency-Key + payload.
Example: tools/call
POST /api/mcp HTTP/1.1
Host: your-deployment.example
Authorization: Bearer YOUR_API_KEY
Accept: application/json, text/event-stream
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "agentnexus_evaluate",
"arguments": {
"policy_name": "payments-default",
"payload_scope": { "amount": 50, "currency": "USD" },
"mcp_session_id": "cursor-session-abc",
"mcp_client_name": "Cursor"
}
}
}
Client setup (Cursor, Claude Desktop, stdio)
Copy-and-paste examples and the stdio bridge live in integrations/mcp-stdio-bridge/:
| File | Purpose |
|---|---|
cursor-mcp.http.json.example | Cursor HTTP MCP: url points at https://…/api/mcp plus headers. |
cursor-mcp.stdio.json.example | Cursor stdio MCP: runs agentnexus-mcp-bridge.mjs with env vars. |
claude_desktop_config.fragment.json.example | Merge into Claude Desktop mcpServers (stdio only). |
agentnexus-mcp-bridge.mjs | Forwards each JSON-RPC line from stdin to POST /api/mcp (Node 18+). |
README.md | Env vars, manual test, config paths. |
If a Cursor build does not accept remote url servers, use the stdio example and the bridge.
Operational notes
- The MCP handler forwards to
POST /api/v1/evaluateover HTTP usingNEXT_PUBLIC_APP_URL(orVERCEL_URL/ localhost). Ensure that URL is reachable from the server process (default on Vercel). - Rate limits:
/api/mcpshares the same Edge evaluate IP bucket as/api/v1/evaluatewhen Upstash is configured; per–API-key limits still apply inside the evaluate route.
Related
- Production readiness
- Framework integrations
- OpenAPI
/openapi.yaml— REST contracts; MCP is JSON-RPC and not fully described there.