Skip to main content

McpBridge

What it is

McpBridge is the SDK’s client for a Model Context Protocol (MCP) server. It spawns the server as a child process, performs the MCP handshake, discovers the tools it advertises, and lets you invoke them by name. The normal path for agents is agent.register_mcp() — it wraps McpBridge and turns every MCP tool into an A2A capability automatically. You import McpBridge yourself only when you want to use MCP tools without publishing them.

When to use it

Reach for McpBridge directly when:
  • You’re writing a script or utility that needs to call a single MCP tool once.
  • You want to inspect an MCP server’s tool list without registering it with Svantic.
  • You’re building custom glue (e.g. forwarding MCP results to somewhere other than an agent capability).
For the mainline case — “make these MCP tools callable as agent capabilities” — use agent.register_mcp().

Functional usage

See the MCP integration guide for the normal agent-side pattern.

Types

McpServerSpawnConfig

What to execute. For stdio-based MCP servers that ship on npm, the usual shape is:

McpToolDescriptor

Returned by list_tools(). input_schema is the raw JSON Schema the MCP server advertised.

Constructor

server_name is a logical label (e.g. 'chrome-devtools'). Used for error messages and telemetry.

Methods

connect(config)

Spawn the MCP server and perform the MCP handshake. Idempotent — calling connect() on an already-connected bridge is a no-op.

list_tools()

Return the set of tools the MCP server advertised. Throws when not connected.

call_tool(tool_name, args)

Invoke a tool by name. Throws when not connected, when the tool rejects, or when the MCP server returns an error result.

close()

Shut down the child process and release resources. Idempotent.

Properties

Example