#!/usr/bin/env python3
"""
Debug script to help troubleshoot MCP server issues in Cursor
"""
import sys
import json
import subprocess
from pathlib import Path
print("π MCP Server Debug Tool for Cursor")
print("=" * 50)
# 1. Check if the server can be imported
print("\n1οΈβ£ Checking if server can be imported...")
sys.path.insert(0, str(Path(__file__).parent / "src"))
try:
from osm_edit_mcp.server import mcp
print("β
Server imported successfully")
print(f" Name: {mcp.name}")
# FastMCP doesn't expose tools directly, but we know they exist
print(" Tools are registered with FastMCP")
except Exception as e:
print(f"β Failed to import server: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
# 2. Check if uv is available
print("\n2οΈβ£ Checking if uv is available...")
try:
result = subprocess.run(["uv", "--version"], capture_output=True, text=True)
if result.returncode == 0:
print(f"β
uv is installed: {result.stdout.strip()}")
else:
print("β uv command failed")
except FileNotFoundError:
print("β uv is not installed or not in PATH")
print(" Install with: curl -LsSf https://astral.sh/uv/install.sh | sh")
# 3. Check Python path
print("\n3οΈβ£ Checking Python environment...")
try:
result = subprocess.run(["uv", "run", "python", "--version"],
capture_output=True, text=True,
cwd=Path(__file__).parent)
if result.returncode == 0:
print(f"β
Python via uv: {result.stdout.strip()}")
else:
print(f"β Failed to run Python via uv: {result.stderr}")
except Exception as e:
print(f"β Error checking Python: {e}")
# 4. Test MCP server initialization
print("\n4οΈβ£ Testing MCP server initialization...")
test_script = '''
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from osm_edit_mcp.server import mcp
print(f"Server: {mcp.name}")
print("Tools registered")
'''
try:
result = subprocess.run(
["uv", "run", "python", "-c", test_script],
capture_output=True, text=True,
cwd=Path(__file__).parent
)
if result.returncode == 0:
print("β
Server initializes correctly via uv")
print(f" {result.stdout.strip()}")
else:
print("β Server initialization failed")
print(f" Error: {result.stderr}")
except Exception as e:
print(f"β Failed to test initialization: {e}")
# 5. Generate correct Cursor configuration
print("\n5οΈβ£ Correct Cursor Configuration:")
cursor_config = {
"osm-edit": {
"command": "uv",
"args": ["run", "python", str(Path(__file__).parent / "main.py")],
"cwd": str(Path(__file__).parent),
"env": {
"PYTHONPATH": str(Path(__file__).parent / "src")
}
}
}
print("```json")
print(json.dumps(cursor_config, indent=2))
print("```")
# 6. Alternative configurations
print("\n6οΈβ£ Alternative Configurations to Try:")
# Without uv
print("\nOption A - Direct Python:")
alt_config1 = {
"osm-edit": {
"command": sys.executable,
"args": [str(Path(__file__).parent / "main.py")],
"cwd": str(Path(__file__).parent),
"env": {
"PYTHONPATH": str(Path(__file__).parent / "src")
}
}
}
print("```json")
print(json.dumps(alt_config1, indent=2))
print("```")
# With absolute path to uv
print("\nOption B - Absolute uv path:")
uv_path = subprocess.run(["which", "uv"], capture_output=True, text=True).stdout.strip()
if uv_path:
alt_config2 = {
"osm-edit": {
"command": uv_path,
"args": ["run", "python", "main.py"],
"cwd": str(Path(__file__).parent)
}
}
print("```json")
print(json.dumps(alt_config2, indent=2))
print("```")
print("\n7οΈβ£ Troubleshooting Steps:")
print("1. Restart Cursor after changing configuration")
print("2. Check Cursor logs: View β Output β MCP")
print("3. Try the alternative configurations above")
print("4. Make sure all dependencies are installed: uv sync")
print("5. Check if .env file exists with proper configuration")
print("\n8οΈβ£ Testing MCP Protocol:")
print("Run this to simulate MCP communication:")
print(f"echo '{{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"id\":1}}' | uv run python {Path(__file__).parent / 'main.py'}")