Skip to content

Commit dede78e

Browse files
author
LittleCoinCoin
committed
fix(mcp): add Claude Desktop transport validation
Prevent Claude Desktop from accepting remote server configurations (--url) that will fail at runtime. Add CLI-level validation to reject --url for Claude Desktop and Claude Code hosts. Fixes: Issue 2 - Claude Desktop accepts --url but fails at runtime
1 parent 4268d4e commit dede78e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

hatch/cli_hatch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,12 @@ def handle_mcp_configure(host: str, server_name: str, command: str, args: list,
637637
print(f"Error: Invalid host '{host}'. Supported hosts: {[h.value for h in MCPHostType]}")
638638
return 1
639639

640+
# Validate Claude Desktop/Code transport restrictions (Issue 2)
641+
if host_type in (MCPHostType.CLAUDE_DESKTOP, MCPHostType.CLAUDE_CODE):
642+
if url is not None:
643+
print(f"Error: {host} does not support remote servers (--url). Only local servers with --command are supported.")
644+
return 1
645+
640646
# Validate argument dependencies
641647
if command and headers:
642648
print("Error: --headers can only be used with --url (remote servers), not with --command (local servers)")

tests/test_mcp_cli_host_config_integration.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,56 @@ def test_reporting_functions_available(self):
626626
self.assertIsNotNone(report)
627627
self.assertEqual(report.operation, 'create')
628628

629+
@regression_test
630+
def test_claude_desktop_rejects_url_configuration(self):
631+
"""Test Claude Desktop rejects remote server (--url) configurations (Issue 2)."""
632+
with patch('hatch.cli_hatch.print') as mock_print:
633+
result = handle_mcp_configure(
634+
host='claude-desktop',
635+
server_name='remote-server',
636+
command=None,
637+
args=None,
638+
env=None,
639+
url='http://localhost:8080', # Should be rejected
640+
headers=None,
641+
no_backup=True,
642+
dry_run=False,
643+
auto_approve=True
644+
)
645+
646+
# Validate: Should return error code 1
647+
self.assertEqual(result, 1)
648+
649+
# Validate: Error message displayed
650+
error_calls = [call for call in mock_print.call_args_list
651+
if 'Error' in str(call) or 'error' in str(call)]
652+
self.assertTrue(len(error_calls) > 0, "Expected error message to be printed")
653+
654+
@regression_test
655+
def test_claude_code_rejects_url_configuration(self):
656+
"""Test Claude Code (same family) also rejects remote servers (Issue 2)."""
657+
with patch('hatch.cli_hatch.print') as mock_print:
658+
result = handle_mcp_configure(
659+
host='claude-code',
660+
server_name='remote-server',
661+
command=None,
662+
args=None,
663+
env=None,
664+
url='http://localhost:8080',
665+
headers=None,
666+
no_backup=True,
667+
dry_run=False,
668+
auto_approve=True
669+
)
670+
671+
# Validate: Should return error code 1
672+
self.assertEqual(result, 1)
673+
674+
# Validate: Error message displayed
675+
error_calls = [call for call in mock_print.call_args_list
676+
if 'Error' in str(call) or 'error' in str(call)]
677+
self.assertTrue(len(error_calls) > 0, "Expected error message to be printed")
678+
629679
@regression_test
630680
def test_cli_handler_signature_compatible(self):
631681
"""Test that handle_mcp_configure signature is compatible with integration."""

0 commit comments

Comments
 (0)