diff options
Diffstat (limited to 'src/ollama_web/mcp.py')
| -rw-r--r-- | src/ollama_web/mcp.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/ollama_web/mcp.py b/src/ollama_web/mcp.py index e52860b..835a160 100644 --- a/src/ollama_web/mcp.py +++ b/src/ollama_web/mcp.py @@ -104,18 +104,14 @@ def validate_mcp_server_name(name: Any) -> str: """Return a safe MCP server name or raise ``ValueError``.""" value = str(name) if not _is_safe_name(value): - raise ValueError( - "server name must match ^[A-Za-z0-9_-]{1,64}$ and must not contain '__'" - ) + raise ValueError("server name must match ^[A-Za-z0-9_-]{1,64}$ and must not contain '__'") return value def _validate_mcp_tool_name(name: Any) -> str: value = str(name) if not _is_safe_name(value): - raise ValueError( - "tool name must match ^[A-Za-z0-9_-]{1,64}$ and must not contain '__'" - ) + raise ValueError("tool name must match ^[A-Za-z0-9_-]{1,64}$ and must not contain '__'") return value @@ -249,7 +245,6 @@ def wrap_untrusted_tool_output(text: str) -> str: return f"{_UNTRUSTED_PREFIX}\n<tool-output>\n{body}\n</tool-output>" - def _to_ollama_tool(server_name: str, tool: Any) -> dict[str, Any]: """Convert an MCP ``Tool`` object into an ollama-compatible tool dict. @@ -437,7 +432,9 @@ async def collect_mcp_tools( results = await asyncio.gather(*tasks, return_exceptions=True) all_tools: list[dict[str, Any]] = [] for name, result in zip(servers.keys(), results, strict=True): - if isinstance(result, Exception): + # asyncio.gather(return_exceptions=True) can surface BaseException + # (e.g. CancelledError), so check BaseException here. + if isinstance(result, BaseException): logger.warning("failed to list tools from MCP server %s: %s", name, result) continue all_tools.extend(result) @@ -663,4 +660,4 @@ def make_mcp_executor( ) -> str: return call_mcp_tool_sync(config, full_name, arguments) - return executor + return executor
\ No newline at end of file |
