Expand description
/api/mcp/* — discovery + health proxy for the in-process MCP server.
The MCP server now runs as a tokio task inside the main construct daemon
(see gateway::run_gateway), not as a separate construct-mcp process. It
binds an ephemeral port and writes the real URL to
~/.construct/mcp.json; the frontend reads that instead of hardcoding a
port.
This module exposes GET /api/mcp/discovery which:
- Reads the discovery file (mtime-cached).
- Issues a short-timeout
GET <url>/healthagainst the MCP server. - Returns a uniform JSON shape the UI can use to drive the status badge.
Structs§
- Reqwest
Health Probe - Default
reqwest-backed probe with a 500ms timeout. - Test
Server Request - Wire shape posted by ConfigV2’s
McpServerEntry— tolerant of unset fields for the transport the user didn’t select. We translate toMcpServerConfigbefore handing off to the existing client.
Traits§
- Health
Probe - Health probe interface — trivially mockable in tests.
Functions§
- build_
discovery_ payload - Core decision logic, factored so tests can inject fakes.
- handle_
api_ mcp_ call - POST /api/mcp/call — proxy to the MCP server’s
POST /mcp(JSON-RPC 2.0). - handle_
api_ mcp_ discovery - GET /api/mcp/discovery
- handle_
api_ mcp_ health - GET /api/mcp/health — direct proxy to the MCP server’s
/healthendpoint (convenience for the UI). Not required for session setup. - handle_
api_ mcp_ servers_ test - POST /api/mcp/servers/test
- handle_
api_ mcp_ session_ create - POST /api/mcp/session — proxy to the MCP server’s
POST /session. - handle_
api_ mcp_ session_ events - GET /api/mcp/session/{id}/events — SSE passthrough.
- request_
to_ config - Validate the request and build an
McpServerConfigready to connect.