MCP Server Project Generator
Trigger
- •Use when given MCP folders or file lists containing
mcp_init.mdand asked to scaffold runnable MCP servers/connectors from those specs.
Inputs
- •One or more MCP units; each must include
mcp_init.md. - •Parse each spec for: MCP type (connector|server), name (external_api_name|domain_name), tools (name, purpose, request/response fields, data_source upstream|db|mixed, error cases), external integration (API base/auth/headers/query/body, DB intent), model requirements (DAO/DTO/service/repository/connection).
- •If data is missing, do not ask questions: choose reasonable defaults and mark “Assumption:” in README + TODO comments.
Outputs
- •For every MCP, emit full project tree and full code per file (path + content). Project must be runnable (scaffold level). Unimplemented logic stays as TODO with interfaces shaped.
- •Absolutely no pytest/테스트 files.
Global Conventions
- •FastMCP boilerplate (must keep order/shape):
from fastmcp import FastMCP
mcp = FastMCP("<mcp_name>")
@mcp.tool(or@mcp.toolsonly if spec forces; note it in README)
tool def/async def …
if __name__ == "__main__": mcp.run() - •Env vars (NAME = upper snake of external_api_name/domain_name):
LOG_LEVEL(default INFO);DB_DSN(server only);MCP_<NAME>_BASE_URL;MCP_<NAME>_API_KEY;MCP_<NAME>_TIMEOUT_SEC(default 20);MCP_<NAME>_RETRY(default 2). - •Types mapping: string→str, integer/int→int, float/double/number→float, boolean→bool, datetime→datetime.datetime (ISO8601 parse), date→datetime.date, decimal→decimal.Decimal, object/dict→dict[str, Any], array/list→list[T or Any]. Optional/nullable/? → Optional[T]=None. Enums → Literal[...] or Enum (Literal preferred). Unknown → Any with “Assumption:” notes.
Required Structure (unless spec overrides)
code
<root>/
mcp/
common/
settings.py # Pydantic Settings loading .env
logging.py # std logging with request_id helper
errors.py # ValidationError/UpstreamError/DatabaseError/InternalError + payload mapper
http_client.py # httpx client factory with timeout/retry
db.py # SQLAlchemy engine + SessionLocal (tool-scope)
types.py # Meta, ErrorPayload, EnvelopeResponse
connectors/<external_api_name>/
mcp_connector_<external_api_name>.py
tools/__init__.py, <tool_group>.py
connection/__init__.py, client.py, schemas.py
models/__init__.py, dto.py
servers/<domain_name>/
mcp_server_<domain_name>.py
tools/__init__.py, <tool_group>.py
service/__init__.py, interface.py (interface only, TODO impl)
repository/__init__.py, repo.py (SQLAlchemy)
models/__init__.py, dao.py (ORM), dto.py (Pydantic)
README.md
pyproject.toml or requirements.txt
Behavior Rules
- •Connector: No service/repository. tools → connection.client. All upstream→internal DTO transforms live only in
connection/client.py; tools never touch raw upstream. Entry file namedmcp_connector_<external_api_name>.py. - •Server: tools → service (interface only) → repository → db. Entry file
mcp_server_<domain_name>.py. DAO uses declarative base. Repository gets session injected. DB session scope is per tool:
with SessionLocal() as session: repo = ...; ... - •Tool design: exactly one Request DTO and one Response DTO. Docstring must include purpose, input fields, output fields, error codes, brief example. meta.source = upstream (connector), db (server DB-only), mixed (server API+DB).
- •Envelope response (never raise to caller):
code
{"data": <ResponseDTO|dict>, "meta": {"request_id": "...", "source": "upstream|db|mixed", "generated_at": "ISO8601", "version": "v1"}, "error": null | {"code": "VALIDATION_ERROR|UPSTREAM_ERROR|DATABASE_ERROR|INTERNAL_ERROR", "message": "...", "detail": {...}}}
Workflow
- •Discover all
mcp_init.mdfrom provided folders/files. If a referenced path is missing, note as TODO and proceed with available ones. - •For each spec, extract fields (type/name/tools/etc). Infer missing data with defaults; log “Assumption:” in README + code TODO.
- •Decide MCP type → choose connector/server layout and env var NAME.
- •Generate common layer once per project.
- •Per MCP, create entrypoint, tools, DTOs, connection/client (connector) or service/repository/models (server). Keep interfaces complete, logic TODO where spec is silent.
- •Ensure every tool returns Envelope and handles Validation/Upstream/Database/Internal errors into payload.
- •Write README.md covering MCP overview, tools, env vars, run instructions, Assumptions, TODOs.
- •Output: list every created file with path + full content. No pytest files.
Notes
- •Keep instructions concise in outputs; avoid extra assets unless required.
- •Respect any spec-enforced import paths/decorators, but preserve FastMCP boilerplate shape.
- •Never prompt the user for clarifications. Use explicit TODO + Assumption markers instead.