Skip to contents

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.

Usage

McpRouter$new()

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).


Method list_tools()

List all available tools across all connected clients.

Usage

McpRouter$list_tools()

Returns

A list of tool definitions.


Method call_tool()

Call a tool, routing to the appropriate client.

Usage

McpRouter$call_tool(name, arguments = list())

Arguments

name

Tool name.

arguments

Tool arguments.

Returns

The tool result.


Method as_sdk_tools()

Get all tools as SDK Tool objects for use with generate_text.

Usage

McpRouter$as_sdk_tools()

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.

Usage

McpRouter$status()

Returns

A list with status information.


Method close()

Close all client connections.

Usage

McpRouter$close()


Method print()

Print method for McpRouter.

Usage

McpRouter$print()


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.