dev.py•3.37 kB
#!/usr/bin/env python3
"""
Development runner script for the CSV MCP server.
"""
import subprocess
import sys
import argparse
from pathlib import Path
def run_server(log_level="INFO"):
"""Run the CSV MCP server with stdio transport."""
cmd = [
sys.executable, "-m", "csv_mcp_server.server",
"--log-level", log_level
]
print(f"Starting CSV MCP Server...")
print(f"Transport: stdio (JSON-RPC 2.0)")
print(f"Log Level: {log_level}")
print("-" * 50)
try:
subprocess.run(cmd, check=True)
except KeyboardInterrupt:
print("\nServer stopped by user")
except subprocess.CalledProcessError as e:
print(f"Server error: {e}")
sys.exit(1)
def run_tests():
"""Run the test suite."""
cmd = [sys.executable, "-m", "pytest", "tests/", "-v"]
print("Running tests...")
print("-" * 50)
try:
result = subprocess.run(cmd, check=False)
sys.exit(result.returncode)
except Exception as e:
print(f"Test error: {e}")
sys.exit(1)
def run_demo():
"""Run the demo client."""
cmd = [sys.executable, "examples/demo_client.py"]
print("Running demo client...")
print("-" * 50)
try:
subprocess.run(cmd, check=True)
except Exception as e:
print(f"Demo error: {e}")
sys.exit(1)
def main():
"""Main entry point for development runner."""
parser = argparse.ArgumentParser(description="CSV MCP Server Development Runner")
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Server command
server_parser = subparsers.add_parser("server", help="Run the MCP server")
server_parser.add_argument("--log-level", choices=["DEBUG", "INFO", "WARNING", "ERROR"],
default="INFO", help="Logging level")
# Test command
test_parser = subparsers.add_parser("test", help="Run tests")
# Demo command
demo_parser = subparsers.add_parser("demo", help="Run demo client")
# Install command
install_parser = subparsers.add_parser("install", help="Install for Claude Desktop")
install_parser.add_argument("--name", default="CSV MCP Server", help="Server name")
args = parser.parse_args()
if not args.command:
parser.print_help()
return
if args.command == "server":
run_server(args.log_level)
elif args.command == "test":
run_tests()
elif args.command == "demo":
run_demo()
elif args.command == "install":
install_for_claude(args.name)
def install_for_claude(name="CSV MCP Server"):
"""Install the server for Claude Desktop."""
cmd = [
"uv", "run", "mcp", "install", "csv_mcp_server/server.py",
"--name", name
]
print(f"Installing '{name}' for Claude Desktop...")
print("-" * 50)
try:
subprocess.run(cmd, check=True)
print(f"Successfully installed '{name}' for Claude Desktop!")
except subprocess.CalledProcessError as e:
print(f"Installation failed: {e}")
sys.exit(1)
except FileNotFoundError:
print("Error: 'uv' command not found. Please install uv first.")
print("Visit: https://docs.astral.sh/uv/getting-started/installation/")
sys.exit(1)
if __name__ == "__main__":
main()