MCP Server for generating FastAPI CRUD modules with hexagonal architecture
Project description
fastapi-hexagon-mcp
An MCP (Model Context Protocol) server that lets Claude — and any other MCP-compatible client — scaffold production-ready FastAPI projects following hexagonal (ports & adapters) architecture.
It generates the full module: domain entities, ORM models, Pydantic schemas, repositories, use cases, and API routes — with the wiring between them, validation, search, filters, and relationships all handled for you.
Why
Hexagonal architecture is great for separation of concerns, but the boilerplate is painful: every new entity touches 6+ files across 4 layers. This MCP automates the mechanical parts (file generation, field propagation, repository mapping, dependency wiring) while leaving the parts that need real judgment (domain rules, custom validations) as TODOs you complete with the LLM.
The result: ask Claude for "a Product CRUD with name, price, and category" and get a working, well-structured FastAPI module in seconds.
Features
- Layered scaffolding — generates domain, application, infrastructure, and routes layers with a single command.
- Field propagation across layers — define a field once; it shows up correctly typed in entities, models, schemas, mappers, and search filters.
- Relationship support — one-to-many and many-to-one foreign keys with proper SQLAlchemy + Pydantic plumbing.
- Dependency injection wiring — auto-registers repositories and use cases.
- Built-in apps — bootstrap a complete project (auth, base infra, alembic) with
generate_builtin. - TODO-driven workflow — anything that requires understanding (custom validation, business rules) is left as a clearly-marked TODO instead of being guessed.
Installation
The server runs via uvx, so you don't need to install anything globally — just configure your MCP client to invoke it.
Claude Desktop / Claude Code
Add to your claude_desktop_config.json or ~/.claude.json:
{
"mcpServers": {
"hexagonal-generator": {
"type": "stdio",
"command": "uvx",
"args": [
"--from",
"fastapi-hexagon-mcp",
"hexagonal-mcp"
],
"env": {}
}
}
}
Pin a specific version with fastapi-hexagon-mcp==X.Y.Z if you need reproducibility.
Manual install
pip install fastapi-hexagon-mcp
hexagonal-mcp # runs the server over stdio
Usage
Once configured, prompt your LLM in natural language. Example:
Generate a CRUD module called Product using the hexagonal-generator MCP. Define its fields:
name(str, max 100, searchable),price(float, required),description(str, max 500, nullable), andcategory(str, max 50, searchable). Add a validation:namemust start with"PRODUCT: ". Then generate a module Store withname(str, max 100, searchable),address(str, required), andproducts(foreign key to Product). Wire the modules and complete all remaining TODOs.
The model will orchestrate the MCP tools below to produce a working project.
Tools
| Tool | What it does |
|---|---|
generate_builtin |
Bootstrap a project skeleton (auth, base infra, alembic). |
generate_crud |
Scaffold a new CRUD module's files across all layers. |
define_fields |
Add fields to a module and propagate them to entities, models, schemas, repositories, and filters. |
add_relationship |
Add a foreign-key relationship between two modules. |
wire_module |
Register a module's dependencies (repository + use cases) in the DI container and routes. |
list_todos |
List remaining TODOs in a module so the LLM can complete them. |
complete_todos |
Help complete TODOs that need judgment (custom validation, business rules). |
Typical workflow
generate_builtin— create the project skeleton.generate_crud— scaffold a module.define_fields— fill in the fields.add_relationship(optional) — connect modules.wire_module— plug it into the app.list_todos/complete_todos— finish the parts that need understanding.
Generated project layout
src/
└── <module>/
├── domain/
│ ├── entities.py # dataclasses
│ └── repositories.py # repository protocol
├── application/
│ ├── schemas.py # Pydantic request/response models
│ └── use_cases.py # business logic
├── infrastructure/
│ ├── models.py # SQLAlchemy ORM
│ └── database.py # repository implementation
└── routes.py # FastAPI router
Requirements
- Python ≥ 3.10
uvx(orpip+ a venv) to run the server- An MCP-compatible client (Claude Desktop, Claude Code, or any other)
Links
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_hexagon_mcp-0.1.3.tar.gz.
File metadata
- Download URL: fastapi_hexagon_mcp-0.1.3.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aba5ec9dab295c40656171433304d45cde27330b1a69aa84f0607f7c9ee173b
|
|
| MD5 |
1e3accd25fcfbb17af61e4e4d2cd57f0
|
|
| BLAKE2b-256 |
2735d79d2b9e37c8b6a09739a5b31187b3c5359181f8c7c140897d7913ffbad4
|
File details
Details for the file fastapi_hexagon_mcp-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_hexagon_mcp-0.1.3-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d90896ca1441f9bd95c69f5bb21265a26f857af58f085f189f79194165cadba0
|
|
| MD5 |
b5391a7274e5c65e728d8a585d547f2a
|
|
| BLAKE2b-256 |
ede376169403761afe287c6ceeb22a1ac4f16da7de360a471800214f30a3e501
|