Skip to content

keelgate.adapters.mcp

Stability of each symbol (stable or provisional) is listed in the API contract. Narrative and semantics are in the integration contract.

Model Context Protocol adapter. MCP tool output is untrusted data.

Serve governed tools to MCP clients with :class:GovernedMCPServer, and admit external MCP tools into a registry, under an allowlist, with :class:GovernedMCPClient.

Discovery dataclass

What was found on the server, and what happened to each tool.

ExternalArgs

Bases: BaseModel

Passthrough arguments for an external tool; the remote JSON schema is enforced separately.

ExternalOutput

Bases: BaseModel

What a governed external MCP tool returns, wrapped so it stays labelled untrusted.

ExternalToolError

Bases: Exception

The external server reported an error, or returned something unusable.

ExternalToolMapping dataclass

How one external tool is admitted: the capability and side effect you assign.

GovernedMCPClient

Wraps an MCP client (anything with list_tools and call_tool).

register async

register(registry: ToolRegistry) -> Discovery

Discover, then register the vetted tools into registry.

GovernedMCPServer

Serve governed tools as an MCP server over stdio or streamable HTTP.

Every call goes through the gateway, handlers never raise, and output is labelled untrusted.

__init__

__init__(
    toolset: GovernedToolset,
    *,
    name: str = "keelgate",
    instructions: str | None = None,
    toolset_for_request: Callable[
        [CallToolRequestParams], GovernedToolset
    ]
    | None = None,
) -> None

toolset_for_request lets a deployment pick a per-caller toolset (and so a per-caller grant). Without it, every caller shares toolset's grant.

http_app

http_app(*, path: str = '/mcp', **kwargs: Any) -> Starlette

An ASGI app serving streamable HTTP. Read the confused-deputy note before using it.

serve_stdio async

serve_stdio() -> None

Serve one client over stdin/stdout until it disconnects.

schema_digest

schema_digest(tool: Tool) -> str

The pin for a remote tool: a hash over its name, description and input schema.