"""Entry point for ``python -m excel_mcp`` and ``excel-analytics-mcp`` CLI."""
from __future__ import annotations
import json
import os
import platform
import sys
from pathlib import Path
def _find_claude_config() -> Path:
"""Return the Claude Desktop config file path."""
if platform.system() == "Darwin":
return Path.home() / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json"
elif platform.system() == "Windows":
return Path(os.environ.get("APPDATA", "")) / "Claude" / "claude_desktop_config.json"
else:
return Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "Claude" / "claude_desktop_config.json"
def _setup() -> None:
"""Configure Claude Desktop to use this MCP server, then exit."""
from . import config
config.ensure_dirs()
config_path = _find_claude_config()
config_path.parent.mkdir(parents=True, exist_ok=True)
# Load existing config
existing: dict = {}
if config_path.exists():
try:
existing = json.loads(config_path.read_text())
except (json.JSONDecodeError, OSError):
pass
# Find our executable
# For uvx/pip installs, the entry point script is the cleanest way
import shutil
exe = shutil.which("excel-analytics-mcp")
if exe:
# Installed via pip/uvx — use the entry point directly
mcp_entry = {
"command": exe,
"args": [],
}
else:
# Fallback: python -m excel_mcp
mcp_entry = {
"command": sys.executable,
"args": ["-m", "excel_mcp"],
}
existing.setdefault("mcpServers", {})
existing["mcpServers"]["excel-analytics"] = mcp_entry
config_path.write_text(json.dumps(existing, indent=2))
# Write user config
if not config.CONFIG_PATH.exists():
config.CONFIG_PATH.write_text(json.dumps({
"port": config.DEFAULT_PORT,
"auto_scan": False,
}, indent=2))
print()
print(" ✅ Excel Analytics MCP — Setup Complete!")
print()
print(f" Claude Desktop config: {config_path}")
print(f" Your data: {config.BASE_DIR}")
print(f" Dashboard: http://localhost:{config.PORT}")
print()
print(" Next steps:")
print(" 1. Restart Claude Desktop (quit and reopen)")
print(" 2. Ask Claude: \"What datasets do I have?\"")
print(" 3. Upload Excel files via the dashboard")
print()
def main() -> None:
if "--setup" in sys.argv:
_setup()
else:
from .server import main as run_server
run_server()
if __name__ == "__main__":
main()