Skip to main content

Module api_mcp

Module api_mcp 

Source
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:

  1. Reads the discovery file (mtime-cached).
  2. Issues a short-timeout GET <url>/health against the MCP server.
  3. Returns a uniform JSON shape the UI can use to drive the status badge.

Structs§

ReqwestHealthProbe
Default reqwest-backed probe with a 500ms timeout.
TestServerRequest
Wire shape posted by ConfigV2’s McpServerEntry — tolerant of unset fields for the transport the user didn’t select. We translate to McpServerConfig before handing off to the existing client.

Traits§

HealthProbe
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 /health endpoint (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 McpServerConfig ready to connect.