Skip to content
Draft
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
8 changes: 2 additions & 6 deletions src/utils/mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
from langchain.tools import BaseTool
from langchain_mcp_adapters.client import MultiServerMCPClient
from pydantic import BaseModel, Field, create_model
from pydantic.v1 import BaseModel, Field

logger = logging.getLogger(__name__)


async def setup_mcp_client_and_tools(mcp_server_config: Dict[str, Any]) -> Optional[MultiServerMCPClient]:
"""
Initializes the MultiServerMCPClient, connects to servers, fetches tools,
filters them, and returns a flat list of usable tools and the client instance.
Initializes the MultiServerMCPClient, connects to servers, and returns the client instance.

Returns:
A tuple containing:
- list[BaseTool]: The filtered list of usable LangChain tools.
- MultiServerMCPClient | None: The initialized and started client instance, or None on failure.
MultiServerMCPClient | None: The initialized and started client instance, or None on failure.
"""

logger.info("Initializing MultiServerMCPClient...")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ async def test_mcp_client():
}
}

mcp_tools, mcp_client = await setup_mcp_client_and_tools(test_server_config)
mcp_client = await setup_mcp_client_and_tools(test_server_config)

for tool in mcp_tools:
if mcp_client:
for server_name in mcp_client.server_name_to_tools:
for tool in mcp_client.server_name_to_tools[server_name]:
tool_param_model = create_tool_param_model(tool)
print(tool.name)
print(tool.description)
Expand Down