Skip to content

Commit a02a4af

Browse files
Add tests and core implementation for MCP server functionality
Introduces MCP server implementation with stdio transport and test suite for basic/advanced Click command functionality. Includes tool scanning, command invocation, and error handling tests.
1 parent 9442fdf commit a02a4af

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

click_mcp/scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def scan_click_command(command: click.Group, parent_path: str = "") -> List[type
4141
# Determine command path
4242
custom_name = metadata.get("name", name)
4343
# Ensure paths use underscore separator instead of dot
44-
cmd_path = f"{parent_path}{custom_name}" if parent_path else custom_name
44+
cmd_path = _sanitize_tool_name(f"{parent_path}{custom_name}" if parent_path else custom_name)
4545

4646
if "commands" in cmd_info:
4747
# Handle subgroup

click_mcp/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def _find_command(self, group: click.Group, path: List[str]) -> click.Command:
119119
if path[0] == group.name:
120120
return self._find_command(group, path[1:])
121121

122-
current, *remaining = path
122+
# Convert underscore-separated path back to dot notation for lookups
123+
current = path[0].replace('_', '.')
124+
remaining = path[1:]
123125

124126
# Try to find the command by name
125127
if current in group.commands:

tests/test_mcp_server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def test_basic_server_tools(basic_mcp_session):
7878
# Find the users.list command
7979
users_list_tool = None
8080
for tool in tools:
81-
if "users.list" in tool.name.lower():
81+
if "users_list" in tool.name.lower():
8282
users_list_tool = tool
8383
break
8484

@@ -141,10 +141,10 @@ async def test_invoke_users_list_command(basic_mcp_session):
141141
result = await basic_mcp_session.list_tools()
142142
tools = result.tools
143143

144-
# Find the users.list command
144+
# Find the users_list command
145145
users_list_tool = None
146146
for tool in tools:
147-
if "users.list" in tool.name.lower():
147+
if "users_list" in tool.name.lower():
148148
users_list_tool = tool
149149
break
150150

@@ -244,7 +244,7 @@ async def test_advanced_server_tools(advanced_mcp_session):
244244
tools = result.tools
245245
assert len(tools) > 0
246246

247-
# Find the config.set command
247+
# Find the config_set command
248248
config_set_tool = None
249249
for tool in tools:
250250
if "config.set" in tool.name.lower():
@@ -324,7 +324,7 @@ async def test_invoke_advanced_commands(advanced_mcp_session):
324324
result = await advanced_mcp_session.list_tools()
325325
tools = result.tools
326326

327-
# Find the config.set command
327+
# Find the config_set command
328328
config_set_tool = None
329329
for tool in tools:
330330
if "config.set" in tool.name.lower():

0 commit comments

Comments
 (0)