Skip to content

Commit d13f3a4

Browse files
committed
fix: Resolve MCP server stdout pollution causing Claude Desktop connection failure
When Claude Desktop launches the MCP server via `python -m mcp_arangodb_async`, the __main__.py module was printing diagnostic messages to stdout (lines 45, 49, 52), violating the MCP protocol's requirement for JSON-only stdout communication. This caused "Unexpected token" JSON parsing errors in Claude Desktop. Changes: - Add server mode detection in __main__.py (defaults to server when no args) - Delegate to entry.py:main() for MCP server operation (no stdout output) - Preserve CLI diagnostic functionality via explicit 'health' command - Add 'server' command and '--server' flag for explicit server mode The fix ensures __main__.py only prints to stdout in CLI diagnostic mode, while MCP server mode uses entry.py's proper stderr-only logging configuration. Fixes: MCP server connection error "Unexpected token 'C', "Connected "..."
1 parent 9b071b2 commit d13f3a4

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ Thumbs.db
5757
# Exclude all PDFs from the repository
5858
**/*.pdf
5959
gitignore/
60+
graph_backups/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Add this server entry to your Claude MCP config:
146146
"mcpServers": {
147147
"arangodb": {
148148
"command": "python",
149-
"args": ["-m", "mcp_arangodb_async"],
149+
"args": ["-m", "mcp_arangodb_async", "server"],
150150
"env": {
151151
"ARANGO_URL": "http://localhost:8529",
152152
"ARANGO_DB": "mcp_arangodb_test",
@@ -171,6 +171,7 @@ Add this server entry to your Claude MCP config:
171171
"mcpServers": {
172172
"arangodb": {
173173
"command": "mcp-arangodb-async",
174+
"args": ["server"],
174175
"env": {
175176
"ARANGO_URL": "http://localhost:8529",
176177
"ARANGO_DB": "mcp_arangodb_test",

mcp_arangodb_async/__main__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,32 @@
2020

2121
def main() -> int:
2222
parser = argparse.ArgumentParser(prog="mcp_arangodb_async", description="ArangoDB MCP diagnostics")
23-
parser.add_argument("command", nargs="?", choices=["health"], help="Command to run (default: info)")
23+
parser.add_argument("command", nargs="?", choices=["health", "server"], help="Command to run (default: server)")
2424
parser.add_argument("--health", dest="health_flag", action="store_true", help="Run health check and output JSON")
25+
parser.add_argument("--server", dest="server_flag", action="store_true", help="Run MCP server (default when no args)")
2526
args = parser.parse_args()
2627

27-
cfg = load_config()
28-
29-
# Determine mode
28+
# Determine mode: if no command and no flags, default to MCP server
3029
run_health = args.command == "health" or args.health_flag
30+
run_server = args.command == "server" or args.server_flag or (args.command is None and not args.health_flag)
31+
32+
# Delegate to MCP server entry point
33+
if run_server:
34+
try:
35+
from .entry import main as entry_main
36+
entry_main() # This never returns (runs async event loop)
37+
return 0
38+
except ImportError as e:
39+
print(f"Error: Could not import MCP server entry point: {e}", file=sys.stderr)
40+
print("Please ensure the package is properly installed.", file=sys.stderr)
41+
return 1
42+
except Exception as e:
43+
print(f"Error starting MCP server: {e}", file=sys.stderr)
44+
return 1
45+
46+
cfg = load_config()
3147

48+
# CLI diagnostic mode (health check or info)
3249
try:
3350
client, db = get_client_and_db(cfg)
3451
if run_health:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "mcp-arangodb-async"
7-
version = "0.2.0"
7+
version = "0.2.1"
88
description = "A Model Context Protocol server for ArangoDB"
99
readme = "README.md"
1010
license = "Apache-2.0"
@@ -13,7 +13,7 @@ authors = [
1313
]
1414
keywords = ["mcp", "mcp-server", "model-context-protocol", "async", "arangodb", "database", "aql", "graph"]
1515
classifiers = [
16-
"Development Status :: 4 - Beta",
16+
"Development Status :: 5 - Beta",
1717
"Intended Audience :: Developers",
1818
"License :: OSI Approved :: Apache Software License",
1919
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)