Skip to content

keelgate.adapters.claude_agent_sdk

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

Claude Agent SDK adapter: governed tools as an in-process MCP server, and locked-down options.

Needs keelgate[anthropic]. The SDK drives the Claude Code CLI, which has its own powerful built-in tools (shell, file edits, web). The point of this adapter is that an agent built with it can only act through governed tools:

  • the governed tools are served from an in-process MCP server, and every call goes through the gateway (grant, policy, approval, audit);
  • the CLI's built-in tools are switched off, strict_mcp_config stops it loading other MCP servers from the machine's settings, and setting_sources is emptied so project or user settings cannot add tools or hooks;
  • a can_use_tool callback refuses anything that is not one of the governed tools, as a final check even if one of the settings above is overridden.

can_use_tool requires the SDK's streaming input mode (pass prompt as an async iterable).

governed_claude_options

governed_claude_options(
    toolset: GovernedToolset,
    *,
    server_name: str = "keelgate",
    **overrides: Any,
) -> ClaudeAgentOptions

ClaudeAgentOptions that confine an agent to the governed tools.

Extra keyword arguments (model, system_prompt, max_turns, max_budget_usd...) are passed through. Overriding the security-relevant ones (tools, allowed_tools, mcp_servers, can_use_tool, strict_mcp_config) is refused, because that would defeat the adapter.

governed_sdk_mcp_server

governed_sdk_mcp_server(
    toolset: GovernedToolset,
    *,
    name: str = "keelgate",
    version: str = "1.0.0",
) -> McpSdkServerConfig

An in-process MCP server exposing the governed tools to the Claude Agent SDK.

governed_tool_names

governed_tool_names(
    toolset: GovernedToolset,
    *,
    server_name: str = "keelgate",
) -> list[str]

The SDK's fully qualified names for the governed tools: mcp__<server>__<tool>.