2.9 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
spark-executor-mcp is a Python 3.12+ service that wraps Spark-related operations as a Model Context Protocol (MCP) server, exposed via HTTP through FastAPI. The MCP layer is built on top of fastapi-mcp, which auto-discovers FastAPI routes and exposes them as MCP tools.
Common Commands
The project uses uv for dependency management. Dependencies are pinned in pyproject.toml and uv.lock. A virtualenv already exists at .venv/. PyPI index is configured to the Tsinghua mirror in pyproject.toml.
# Install/sync dependencies
uv sync
# Run the server (binds 0.0.0.0:8000)
uv run main.py
# Or activate the venv and run directly
source .venv/bin/activate
python main.py
Once running, the MCP endpoint is mounted at http://localhost:8000/spark-executor-mcp. The spark_executor app's own routes (e.g. /health) remain available at the root.
There is currently no test suite, linter configuration, or CI config in the repository.
Architecture
The codebase is small and intentionally layered — the goal is to add new "tool" FastAPI sub-apps and have them be auto-exposed as MCP.
main.py # Root FastAPI app; lifespan wires in the MCP server
common/
factory.py # init_mcp_server(app) -> FastApiMCP wrapper
logging.py # loguru logger, level=DEBUG to stderr
spark_executor/
__init__.py # Re-exports `app`
server.py # Spark Executor FastAPI app (the MCP tool surface)
How a request flows:
main.pycreates the rootFastAPI(title="Main App")and registers anasynccontextmanagerlifespan.- At startup, the lifespan calls
init_mcp_server(spark_executor_app)(common/factory.py) which returns aFastApiMCPinstance bound to the spark executor's FastAPI app. - That
FastApiMCPis mounted onto the root app at/spark-executor-mcpviamount_http(...).fastapi-mcpinspects the spark executor's routes and registers each one as an MCP tool. - To add new MCP tools, define new routes on the
appinspark_executor/server.py(or create a new sub-package and mount it the same way inmain.py's lifespan) — they will be picked up automatically.
Key conventions:
- All modules include the file header
# coding=utf-8plus a@Time/@Authordocstring. Match this when adding new files. common/logging.pyconfigures a single process-widelogurulogger and removes the default handler. Importfrom common.logging import loggerrather than creating new loggers.spark_executor/__init__.pyre-exportsappso callers canfrom spark_executor import app— keep this re-export when adding to the package.- The
FastApiMCPinstance is created per-app in the lifespan; do not cache it at module import time.