Files
mistral-vibe/tests/stubs/fake_mcp_registry.py
Mathias Gesbert e9a9217cc8 v2.7.4 (#579)
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-authored-by: Lucas Marandat <31749711+lucasmrdt@users.noreply.github.com>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Paul Cacheux <paul.cacheux@mistral.ai>
Co-authored-by: Peter Evers <pevers90@gmail.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Pierre Rossinès <pierre.rossines@protonmail.com>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Simon Van de Kerckhove <simon.vandekerckhove@mistral.ai>
Co-authored-by: Val <102326092+vdeva@users.noreply.github.com>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-04-09 18:40:46 +02:00

51 lines
1.8 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from vibe.core.tools.mcp import MCPRegistry
from vibe.core.tools.mcp.tools import (
RemoteTool,
create_mcp_http_proxy_tool_class,
create_mcp_stdio_proxy_tool_class,
)
if TYPE_CHECKING:
from vibe.core.config import MCPServer
from vibe.core.tools.base import BaseTool
_BROKEN_SERVER_NAME = "broken-server"
class FakeMCPRegistry(MCPRegistry):
def get_tools(self, servers: list[MCPServer]) -> dict[str, type[BaseTool]]:
result: dict[str, type[BaseTool]] = {}
for srv in servers:
key = self._server_key(srv)
if key not in self._cache:
remote = RemoteTool(
name="fake_tool", description=f"A fake tool for {srv.name}"
)
match srv.transport:
case "stdio":
proxy = create_mcp_stdio_proxy_tool_class(
command=["fake-cmd"], remote=remote, alias=srv.name
)
case "http" | "streamable-http":
proxy = create_mcp_http_proxy_tool_class(
url="http://fake-mcp-server", remote=remote, alias=srv.name
)
case _:
raise ValueError(
f"FakeMCPRegistry: unsupported transport {srv.transport!r}"
)
self._cache[key] = {proxy.get_name(): proxy}
result.update(self._cache[key])
return result
class FakeMCPRegistryWithBrokenServer(FakeMCPRegistry):
def get_tools(self, servers: list[MCPServer]) -> dict[str, type[BaseTool]]:
working = [s for s in servers if s.name != _BROKEN_SERVER_NAME]
return super().get_tools(working)