dragon.ai.agent.tools.mcp_tool.MCPServerClient

class MCPServerClient[source]

Bases: object

Client that owns one persistent connection to a single MCP server.

Each instance represents one server. Tools from that server are exposed to the LLM with names scoped as {alias}__{tool_name} (double-underscore separator) so that multiple servers can be connected simultaneously without name collisions.

Parameters

alias:

Short, unique label for this server (e.g. "jupyter", "filesystem"). Used as the routing prefix in tool names.

max_retries:

Number of connection attempts before raising ConnectionError.

retry_delay:

Seconds to wait between retry attempts.

timeout:

Per-attempt connection timeout in seconds.

Example

client = MCPServerClient(alias="jupyter")
await client.start("http://mcp-server/mcp", token)
result = await client.call_tool("jupyter__create_notebook", {"name": "demo"})
await client.close()
__init__(alias: str , max_retries: int = 3, retry_delay: float = 0.5, timeout: float = 5.0) None [source]

Methods

__init__(alias[, max_retries, retry_delay, ...])

call_tool(scoped_name, args)

Call a tool on this server by its scoped name.

close()

Close the MCP session and release all resources.

start(url, token)

Connect to the MCP server and cache its tool schemas.

Attributes

scoped_names

Set of scoped tool names ({alias}__{tool_name}) for this server.

tools_schemas

vLLM-compatible tool schema list for this server's tools.

__init__(alias: str , max_retries: int = 3, retry_delay: float = 0.5, timeout: float = 5.0) None [source]
async start(url: str , token: str ) None [source]

Connect to the MCP server and cache its tool schemas.

Parameters:
  • url – URL of the MCP server.

  • token – Authentication token.

Raises:

ConnectionError – If all retry attempts fail.

async close() None [source]

Close the MCP session and release all resources.

async call_tool(scoped_name: str , args: dict ) Any [source]

Call a tool on this server by its scoped name.

Parameters:
  • scoped_name – Tool name in {alias}__{tool_name} format.

  • args – Arguments to pass to the tool.

Returns:

structured_content from the MCP response if available, otherwise the plain-text content joined into a single string.

Raises:
property tools_schemas: list [dict [str , Any ]]

vLLM-compatible tool schema list for this server’s tools.

property scoped_names: set [str ]

Set of scoped tool names ({alias}__{tool_name}) for this server.