Skip to content

MCP Router

Lets your agent connect to Model Context Protocol servers at runtime, list the tools they expose, invoke one, and disconnect. The factory takes a developer-set allowlist of server configurations; the model can only initiate connections to servers on that list.

The tool exposes five commands: connect (opens a named connection to an allowlisted server using a connection_id), list_connections (returns all open connection IDs for the current agent), list_tools (returns the tools the server exposes), call_tool (invokes a tool by name), and disconnect (closes a connection).

Connections are scoped per agent and persist across invocations on the same agent instance. A connection is closed when the model calls disconnect explicitly, or when the agent is garbage collected. The connection remains open otherwise.

Supported in: Node.js (TypeScript); all platforms (Python).

Example:

import { Agent } from '@strands-agents/sdk'
import { makeMcpRouter } from '@strands-agents/sdk/vended-tools/mcp-router'
const mcpRouter = makeMcpRouter({
servers: {
files: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
},
'my-api': { url: 'https://mcp.example.com/mcp' },
},
maxConnections: 5,
})
const agent = new Agent({ tools: [mcpRouter] })
await agent.invoke(
"Connect to 'files', list its tools, " +
'call the read_file tool on /tmp/hello.txt, then disconnect.'
)