Pure validation and normalization for the pinned MCP protocol contract.
PtcRunner.Kernel.MCPSource owns transport, deadlines, capability
construction, and provider-error translation. This module owns the
transport-independent JSON-RPC envelopes and responses, catalog-page
reduction, selected-tool interpretation, HTTP parameter-header projection,
and tool-result normalization.
Catalog reduction validates only the identity and pagination fields needed
to find installed mappings. Contract fields on unselected tools are retained
without interpretation. One paginated list operation must retain the same
cacheScope across every page, although page TTLs may differ. Once a mapped
tool is selected, its description, schemas, and transport annotations are
validated. Unknown tool fields remain ignored for forward compatibility. The
removed 2025-11-25
execution.taskSupport field has no semantics in the pinned modern core.
Structured results require a frozen object-output validator and explicit
content containing only exact text or embedded text-resource blocks; those
companion blocks are validated and discarded. Standard content-block
annotations and _meta fields are validated, accepted, and ignored; other
extra block fields are rejected. Tools without output schemas
return a map containing ordered "text" values and, when present, ordered
embedded text "resources". Binary resources and all other content types
remain unsupported. Inbound documents are rejected before decoding when
their raw JSON nesting exceeds the fixed document-depth ceiling.
Multi-round-trip input_required results are legal only for tools/call,
prompts/get, and resources/read. A schema-valid state-only result,
including an empty load-shedding inputRequests map accompanied by
requestState, is refused by policy. A schema-valid, non-empty request map is
a capability-negotiation error because the client advertises no elicitation,
sampling, or roots capability. Input requests are validated against those
three method schemas only to distinguish malformed protocol data; they are
never interpreted or fulfilled. Malformed results and results on other
methods are protocol errors. This module never retries either form. Functions
normally return closed MCP reason atoms; the explicitly installed
:bounded error-feedback policy is the sole exception and returns a bounded
validated remote text value for later provider-error construction.
Summary
Types
Functions
@spec catalog_page(map(), map(), pos_integer(), pos_integer()) :: catalog_result()
@spec decode_message(binary()) :: {:ok, inbound_message()} | {:error, :mcp_protocol_error}
@spec decode_response(binary(), pos_integer()) :: {:ok, map()} | {:error, :mcp_protocol_error}
@spec request(pos_integer(), binary(), map(), map()) :: map()