Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-kiwis-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"toolsets": minor
---

feat:fix: rename deferred tools to comply with MCP naming standard
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ t.launch(mcp_server=True)

When tools are added with `defer_loading=True`:
- Tools are not exposed in the base tools list
- Two special MCP tools are added: "Search Deferred Tools" and "Call Deferred Tool"
- Two special MCP tools are added: `search_deferred_tools` and `call_deferred_tool`
- A search interface is available in the Gradio UI for finding deferred tools
- Tools can be discovered using semantic search based on natural language queries

Expand Down
16 changes: 8 additions & 8 deletions toolsets/gradio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def make_click_handler(schema):
},
}
h_search = gr.HTML(
f"<p><code>Search Deferred Tools</code></p><p>{search_tool_data['description']}</p>",
f"<p><code>search_deferred_tools</code></p><p>{search_tool_data['description']}</p>",
container=True,
elem_classes="tool-item",
)
Expand All @@ -130,7 +130,7 @@ def make_click_handler(schema):
},
}
h_call = gr.HTML(
f"<p><code>Call Deferred Tool</code></p><p>{call_tool_data['description']}</p>",
f"<p><code>call_deferred_tool</code></p><p>{call_tool_data['description']}</p>",
container=True,
elem_classes="tool-item",
)
Expand Down Expand Up @@ -242,7 +242,7 @@ def _get_complete_schema(toolset: "Toolset", request: Request) -> JSONResponse:
has_deferred = bool(toolset._deferred_elements)
if has_deferred:
search_tool_info = {
"name": "Search Deferred Tools",
"name": "search_deferred_tools",
"description": "Search for deferred tools using semantic and keyword matching. Returns top matching tools with their names, descriptions, and input schemas.",
"inputSchema": {
"type": "object",
Expand All @@ -262,14 +262,14 @@ def _get_complete_schema(toolset: "Toolset", request: Request) -> JSONResponse:
"meta": {
"file_data_present": False,
"mcp_type": "tool",
"endpoint_name": "Search Deferred Tools",
"endpoint_name": "search_deferred_tools",
},
}
if selected_tools is None or "Search Deferred Tools" in selected_tools:
if selected_tools is None or "search_deferred_tools" in selected_tools:
schemas.append(search_tool_info)

call_tool_info = {
"name": "Call Deferred Tool",
"name": "call_deferred_tool",
"description": "Call a deferred tool by name with the provided parameters.",
"inputSchema": {
"type": "object",
Expand All @@ -288,10 +288,10 @@ def _get_complete_schema(toolset: "Toolset", request: Request) -> JSONResponse:
"meta": {
"file_data_present": False,
"mcp_type": "tool",
"endpoint_name": "Call Deferred Tool",
"endpoint_name": "call_deferred_tool",
},
}
if selected_tools is None or "Call Deferred Tool" in selected_tools:
if selected_tools is None or "call_deferred_tool" in selected_tools:
schemas.append(call_tool_info)

return JSONResponse(schemas)
Expand Down
10 changes: 5 additions & 5 deletions toolsets/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def list_tools() -> list[types.Tool]:
if has_deferred:
tools.append(
types.Tool(
name="Search Deferred Tools",
name="search_deferred_tools",
description="Search for deferred tools using semantic and keyword matching. Returns top matching tools with their names, descriptions, and input schemas.",
inputSchema={
"type": "object",
Expand All @@ -94,7 +94,7 @@ async def list_tools() -> list[types.Tool]:
)
tools.append(
types.Tool(
name="Call Deferred Tool",
name="call_deferred_tool",
description="Call a deferred tool by name with the provided parameters.",
inputSchema={
"type": "object",
Expand All @@ -119,7 +119,7 @@ async def list_tools() -> list[types.Tool]:
async def call_tool(name: str, arguments: dict[str, Any]) -> types.CallToolResult:
headers = _get_forwarded_headers(server)

if name == "Search Deferred Tools":
if name == "search_deferred_tools":
query = arguments.get("query", "")
top_k = arguments.get("top_k", 2)
results = await run_sync(
Expand All @@ -132,7 +132,7 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> types.CallToolResul
]
return types.CallToolResult(content=content)

if name == "Call Deferred Tool":
if name == "call_deferred_tool":
tool_name = arguments.get("tool_name")
parameters = arguments.get("parameters", {})
if not tool_name:
Expand All @@ -154,7 +154,7 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> types.CallToolResul

if name in toolset._deferred_tool_to_element:
raise ValueError(
f"Tool '{name}' is deferred. Use 'Call Deferred Tool' to execute it."
f"Tool '{name}' is deferred. Use 'call_deferred_tool' to execute it."
)

if name not in toolset._tool_to_element:
Expand Down
2 changes: 1 addition & 1 deletion toolsets/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add(
Args:
element: The toolset element to add (typically a Server instance).
defer_loading: If True, tools from this element are not immediately loaded.
Instead, they can be discovered via semantic search using the "Search Deferred Tools"
Instead, they can be discovered via semantic search using the "search_deferred_tools"
tool. This is useful when dealing with large numbers of tools to save context length.
Defaults to False.
notes: Optional notes about when these tools should be used. This text is appended
Expand Down