Skip to content

Commit 8a15c22

Browse files
committed
refactor(server): migrate MCP server to use fetch_tools
Update MCP server handlers to use dynamic tool fetching: list_tools(): - Replace get_tools() with fetch_tools() call_tool(): - Extract account_id from arguments before fetching - Use fetch_tools() with actions filter to get specific tool - Pass account_id to fetch_tools() when provided This completes the migration from OAS-based tool loading to MCP-backed dynamic tool fetching in the server component.
1 parent 0fb3aff commit 8a15c22

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stackone_ai/server.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def list_tools() -> list[Tool]:
7070

7171
try:
7272
mcp_tools: list[Tool] = []
73-
tools = toolset.get_tools()
73+
tools = toolset.fetch_tools()
7474
# Convert to a list if it's not already iterable in the expected way
7575
tool_list = list(tools.tools) if hasattr(tools, "tools") else []
7676

@@ -129,7 +129,16 @@ async def call_tool(
129129
)
130130

131131
try:
132-
tool = toolset.get_tool(name)
132+
# Get account_id from arguments if provided
133+
account_id = arguments.pop("account_id", None)
134+
135+
# Fetch tools with the specific action filter to get the right tool
136+
tools = toolset.fetch_tools(
137+
account_ids=[account_id] if account_id else None,
138+
actions=[name],
139+
)
140+
tool = tools.get_tool(name)
141+
133142
if not tool:
134143
logger.warning(f"Tool not found: {name}")
135144
raise McpError(
@@ -139,9 +148,6 @@ async def call_tool(
139148
)
140149
)
141150

142-
if "account_id" in arguments:
143-
tool.set_account_id(arguments.pop("account_id"))
144-
145151
if tool_needs_account_id(name) and tool.get_account_id() is None:
146152
logger.warning(f"Tool {name} needs account_id but none provided")
147153
raise McpError(

0 commit comments

Comments
 (0)