ToolRunner
mcpygen.tool_exec.client.ToolRunner
ToolRunner(
server_name: str,
server_params: dict[str, Any],
host: str = "localhost",
port: int = 8900,
)
Client for executing MCP tools on a ToolServer.
Example
runner = ToolRunner(
server_name="fetch",
server_params={"command": "uvx", "args": ["mcp-server-fetch"]},
)
result = await runner.run("fetch", {"url": "https://example.com"})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_name
|
str
|
Name of the MCP server. |
required |
server_params
|
dict[str, Any]
|
MCP server parameters. |
required |
host
|
str
|
Hostname of the |
'localhost'
|
port
|
int
|
Port number of the |
8900
|
reset
async
reset()
Reset the ToolServer, stopping all started MCP servers.
run
async
Execute a tool on the configured MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to execute. |
required |
tool_args
|
dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | str | None
|
The tool execution result. |
Raises:
| Type | Description |
|---|---|
ApprovalRejectedError
|
If the tool call is rejected by the approval workflow. |
ApprovalTimeoutError
|
If the approval request times out. |
ToolRunnerError
|
If tool execution fails. |
run_sync
Synchronous version of run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to execute. |
required |
tool_args
|
dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | str | None
|
The tool execution result. |
Raises:
| Type | Description |
|---|---|
ApprovalRejectedError
|
If the tool call is rejected by the approval workflow. |
ApprovalTimeoutError
|
If the approval request times out. |
ToolRunnerError
|
If tool execution fails. |