more functions out of the Big Tool registers

This commit is contained in:
lda
2026-05-13 16:09:28 +07:00 Verified
parent bead0aadfd
commit c1a25c7eb3
10 changed files with 490 additions and 130 deletions
+17 -61
View File
@@ -1,77 +1,54 @@
from __future__ import annotations
from dataclasses import asdict
from typing import Any
from mcp.server.fastmcp import FastMCP
from ..shared.errors import error_payload
from ..admin_surface import BrokerAdminHandlers
from .service import WfMcpService
def register_broker_tools(server: FastMCP, service: WfMcpService) -> None:
"""Register broker tool handlers on a FastMCP server."""
handlers = BrokerAdminHandlers(service)
# These MCP tool names are compatibility exports. Their capability metadata
# belongs to the wf.admin source; future admin-enabled servers can project
# dotted wf.admin.* names from that source.
@server.tool()
async def list_connections() -> list[dict[str, Any]]:
return [
asdict(connection)
for connection in sorted(
service.connections.list_all(),
key=lambda connection: connection.id,
)
]
return handlers.list_connections()
@server.tool()
async def get_connection_statuses() -> list[dict[str, Any]]:
return service.connection_statuses()
return handlers.get_connection_statuses()
@server.tool()
async def refresh_connection_catalog(connection_id: str) -> dict[str, Any]:
try:
await service.refresh_connection_catalog(connection_id)
except Exception as exc:
return {
"connection_id": connection_id,
"refreshed": False,
**error_payload(exc),
}
snapshot = service.get_connection_snapshot(connection_id)
if snapshot is None:
return {"connection_id": connection_id, "refreshed": False}
return {
"connection_id": connection_id,
"refreshed": True,
"node_count": len(snapshot.nodes),
"resource_count": len(snapshot.resources),
"prompt_count": len(snapshot.prompts),
}
return await handlers.refresh_connection_catalog(connection_id)
@server.tool()
async def get_catalog() -> dict[str, Any]:
return service.get_catalog().as_payload()
return handlers.get_catalog()
@server.tool()
async def get_planner_catalog() -> dict[str, Any]:
return service.get_planner_catalog().as_payload()
return handlers.get_planner_catalog()
@server.tool()
async def list_spec_sources() -> list[dict[str, Any]]:
return service.list_spec_sources()
return handlers.list_spec_sources()
@server.tool()
async def read_broker_resource(qualified_name: str) -> dict[str, Any]:
return await service.read_resource(qualified_name)
return await handlers.read_broker_resource(qualified_name)
@server.tool()
async def render_broker_prompt(
qualified_name: str,
arguments: dict[str, str] | None = None,
) -> dict[str, Any]:
return await service.render_prompt(qualified_name, arguments=arguments)
return await handlers.render_broker_prompt(qualified_name, arguments=arguments)
@server.tool()
async def invoke_broker_method(
@@ -79,15 +56,7 @@ def register_broker_tools(server: FastMCP, service: WfMcpService) -> None:
method: str,
params: dict[str, Any] | None = None,
) -> dict[str, Any]:
try:
return await service.invoke_method(connection_id, method, params=params)
except Exception as exc:
return {
"connection_id": connection_id,
"method": method,
"ok": False,
**error_payload(exc),
}
return await handlers.invoke_broker_method(connection_id, method, params=params)
@server.tool()
async def call_broker_tool(
@@ -95,25 +64,12 @@ def register_broker_tools(server: FastMCP, service: WfMcpService) -> None:
tool_name: str,
arguments: dict[str, Any] | None = None,
) -> dict[str, Any]:
try:
return {
"connection_id": connection_id,
"tool_name": tool_name,
"ok": True,
**await service.call_tool(
connection_id,
tool_name,
arguments=arguments,
),
}
except Exception as exc:
return {
"connection_id": connection_id,
"tool_name": tool_name,
"ok": False,
**error_payload(exc),
}
return await handlers.call_broker_tool(
connection_id,
tool_name,
arguments=arguments,
)
@server.tool()
async def get_broker_events() -> list[dict[str, Any]]:
return [asdict(event) for event in service.list_events()]
return handlers.get_broker_events()