A virtual MCP server that aggregates tools from multiple downstream
MCP servers into a unified interface. Supports hot-swapping and
skill negotiation.
Public fields
clients
List of connected MCP clients.
tool_map
Mapping of tool names to their source clients.
capabilities
Aggregated capabilities from all clients.
Methods
Method new()
Create a new MCP Router.
Returns
A new McpRouter object.
Method add_client()
Add an MCP client to the router.
Usage
McpRouter$add_client(name, client)
Arguments
name
Unique name for this client.
client
An McpClient object.
Returns
Self (invisibly).
Method connect()
Connect to an MCP server and add it to the router.
Usage
McpRouter$connect(name, command, args = character(), env = NULL)
Arguments
name
Unique name for this connection.
command
Command to run the MCP server.
args
Command arguments.
env
Environment variables.
Returns
Self (invisibly).
Method remove_client()
Remove an MCP client from the router (hot-swap out).
Usage
McpRouter$remove_client(name)
Arguments
name
Name of the client to remove.
Returns
Self (invisibly).
List all available tools across all connected clients.
Returns
A list of tool definitions.
Call a tool, routing to the appropriate client.
Usage
McpRouter$call_tool(name, arguments = list())
Arguments
name
Tool name.
arguments
Tool arguments.
Get all tools as SDK Tool objects for use with generate_text.
Returns
A list of Tool objects.
Method negotiate()
Negotiate capabilities with a specific client.
Usage
McpRouter$negotiate(client_name)
Arguments
client_name
Name of the client.
Returns
A list of negotiated capabilities.
Method status()
Get router status.
Returns
A list with status information.
Close all client connections.
Print method for McpRouter.
Method clone()
The objects of this class are cloneable with this method.
Usage
McpRouter$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.