Skip to main content

Module mcp

Module mcp 

Source
Expand description

Model Context Protocol dialect: JSON-RPC tools/call requests in, isError tool results out.

MCP is the common tool bus emerging across agent hosts (Claude, IDEs, OpenAI-compatible runtimes). Guarding it guards every server behind it — including tools you don’t control. The typesec mcp-gate CLI subcommand builds a full stdio proxy on this codec.

Constants§

DIALECT
Dialect name used in error messages and the Python bindings.

Functions§

denial
Render a denied/undecided call as a complete JSON-RPC response carrying an MCP tool result with isError: true, so the client receives the refusal as tool output. A call_id that parses as an integer is restored to a numeric id; use denial_with_id to echo the original id exactly. Returns None for allowed calls.
denial_with_id
Like denial, but echoing the JSON-RPC id verbatim — the form a proxy that still holds the original request should use.
filter_tools
Filter a tools/list result ({"tools": [...]} or a bare array) down to the definitions keep accepts, returning the same shape it was given.
is_tools_call
true if this JSON-RPC message is a tools/call request.
parse_tool_calls
Parse tools/call invocations from a single JSON-RPC request object or a bare array of requests. Requests with other methods (initialize, tools/list, notifications) yield no calls — they are not errors.