pub fn make_mcp_router(options: MakeMcpRouterOptions) -> Result<FunctionTool>Expand description
Creates an mcp_router tool bound to an allowlist of servers.
Connections are per agent and persist across invocations. They close when the model calls
disconnect, when the tool is dropped, and soon after their agent is dropped.
use std::collections::BTreeMap;
use strands::mcp::McpServerConfig;
use strands::vended_tools::mcp_router::{MakeMcpRouterOptions, make_mcp_router};
let router = make_mcp_router(MakeMcpRouterOptions {
servers: BTreeMap::from([(
"my-api".to_owned(),
McpServerConfig::builder().url("https://mcp.example.com/mcp").build(),
)]),
..MakeMcpRouterOptions::default()
})?;
let agent = strands::Agent::builder().tools([router]).printer(false).build()?;
assert!(agent.tool_registry().get("mcp_router").is_some());§Errors
servers is empty, or max_connections is 0. The tool returns an error result with an
McpRouterToolError message when, among others, call_tool names a tool that the
connection’s list_tools does not return.