Skip to content

Commit df000fc

Browse files
authored
Merge pull request #140 from onmete/skip-mcp-servers
Skip MCP servers registration if there are no servers
2 parents e1c179c + 7eb7185 commit df000fc

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/utils/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ async def register_mcp_servers_async(
3232
logger: Logger, configuration: Configuration
3333
) -> None:
3434
"""Register Model Context Protocol (MCP) servers with the LlamaStack client (async)."""
35+
# Skip MCP registration if no MCP servers are configured
36+
if not configuration.mcp_servers:
37+
logger.debug("No MCP servers configured, skipping registration")
38+
return
39+
3540
if configuration.llama_stack.use_as_library_client:
3641
# Library client - use async interface
3742
# config.py validation ensures library_client_config_path is not None

tests/unit/utils/test_common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ async def test_register_mcp_servers_empty_list(mocker):
3030
# Mock the logger
3131
mock_logger = Mock(spec=Logger)
3232

33-
# Mock the LlamaStack client
34-
mock_client = Mock()
35-
mock_client.tools.list.return_value = []
36-
mocker.patch("utils.common.get_llama_stack_client", return_value=mock_client)
33+
# Mock the LlamaStack client (shouldn't be called since no MCP servers)
34+
mock_get_client = mocker.patch("utils.common.get_llama_stack_client")
3735

3836
# Create configuration with empty MCP servers
3937
config = Configuration(
@@ -48,10 +46,12 @@ async def test_register_mcp_servers_empty_list(mocker):
4846
# Call the function
4947
await register_mcp_servers_async(mock_logger, config)
5048

51-
# Verify client.tools.list was called
52-
mock_client.tools.list.assert_called_once()
53-
# Verify client.toolgroups.register was not called since no MCP servers
54-
assert not mock_client.toolgroups.register.called
49+
# Verify get_llama_stack_client was NOT called since no MCP servers
50+
mock_get_client.assert_not_called()
51+
# Verify debug message was logged
52+
mock_logger.debug.assert_called_with(
53+
"No MCP servers configured, skipping registration"
54+
)
5555

5656

5757
@pytest.mark.asyncio

0 commit comments

Comments
 (0)