Skip to main content

Module server

Module server 

Source
Expand description

CortexServer — the rmcp 1.7 ServerHandler that exposes Cortex’s tool surface over a spec-compliant MCP 2025-06-18 stdio transport.

This module replaces the hand-rolled JSON-RPC dispatcher in crate::serve. The legacy dispatcher treated the request method field as a tool name (e.g. "cortex_memory_note") and therefore failed Claude Code’s MCP client, which speaks the canonical initialize / tools/list / tools/call handshake. The handshake itself is now handled by rmcp; tool dispatch routes through the existing ToolRegistry so every crate::ToolHandler implementation — and every per-tool unit test — keeps working unchanged.

§Wire mapping

Every #[tool] method below accepts Parameters<serde_json::Value> and delegates to CortexServer::dispatch, which looks up the static tool name in the registry and returns either Json<Value> (success) or an McpError. The mapping from ToolError to McpError is:

ToolErrorMcpError constructor
InvalidParams(msg)invalid_params(msg, None)
PolicyRejected(msg)invalid_params(msg, None)
SizeLimitExceeded(msg)invalid_params(msg, None)
Internal(msg)internal_error(msg, None)

PolicyRejected maps to invalid_params because every policy rejection today is “the caller’s input was refused by an authority gate” — there is no separate rmcp variant for that case and the JSON-RPC -32602 semantics (“the parameters are invalid for this method as configured”) are correct.

§Why a registry passthrough instead of typed Params per tool

Cordance’s rmcp integration uses one JsonSchema-derived params struct per tool, which gives Claude Code’s UI a rich schema for argument prompting. Cortex’s 18 tools all currently validate their own raw serde_json::Value payload in ToolHandler::call. Re-deriving 18 typed params structs would duplicate that validation surface and risk drift between the rmcp schema and the runtime validator. The passthrough preserves the existing single source of truth at the cost of presenting “any JSON object” as the schema in tools/list. The handshake itself still works, which is the bug this module was written to fix.

Structs§

CortexServer
Cortex MCP server.

Functions§

serve_stdio
Drive the stdio MCP loop until the peer closes stdin (EOF) or an OS signal terminates the process.