Service MCP
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Service MCP — Generic FastMCP + SQLAlchemy CRUD Template
A production-ready, generic FastMCP server template with
SQLAlchemy async CRUD. Distilled into a reusable skeleton for MCP data-management services;
the example domain (Product / ProductPrice) shares the same business contract as the sibling
backend and frontend templates in this family.
Stack: Python 3.12+ · FastMCP 3.x · SQLAlchemy 2.x (async) · Pydantic v2 · Typer CLI · uv
Features
Registry-driven CRUD tools — add/update/delete (single + batch) are generated from a one-line entity registry; no per-entity boilerplate.
FK code auto-resolution — business codes (
code) are resolved to internal IDs by the handler layer; callers never see primary keys.Auto-placeholder creation — child records referencing a missing parent create a
abnormal=Placeholderstub parent automatically (e.g. price records for an unknown product).Orphan marking — deleting a parent marks dependent child rows
abnormal=Orphanedinstead of cascade-deleting; areview_abnormal_itemstool aggregates all pending-review rows.Composite-key delete — child records can be located by their natural compound key (
code + price_date).Dynamic Filter/Search —
Filter/SearchByKeyword/SearchByFieldsclasses are generated at import time from ORM introspection;.pyistubs are regenerated by a script for IDE support.Conflict versioning — same-day price conflicts bump a
versioncolumn and mark the row for human review.Multi-transport CLI —
stdio/sse/streamable-http/ui(FastMCP Apps dashboard).Layered config — env vars → TOML → code defaults (
MCP_prefix,MCP_ENVselects the TOML).Auth-ready — JWT middleware +
mcp_permdecorators with permission discovery; async-faithful wrappers and admin-mode fail-closed rejection. Three-tier data scoping (scope_visibility_where: platform / team / personal + publish-review gate), a parent-visibility registry (PARENT_ENTITY_MAP) for child rows without own ownership columns (orphans stay visible), and soft-deleted rows hidden from list/search by default.Typed tool UX —
ToolAnnotationspresets (read-only / idempotent / mutating / destructive) on every tool; predictable business failures raiseToolErrorand are converted toUtilResponsebusiness errors (never 500); batch mutations capped atMAX_BATCH_SIZE.Docker deployment — compose stack (PostgreSQL 18 + Redis 8, optional pgAdmin) with lifecycle scripts (
ctl.sh/ctl.ps1).Extras — mock data generator, idempotent migration example, SQLite/MySQL/PostgreSQL/InfluxDB support, FastMCP Apps config UI.
Generic infrastructure — async per-key rate limiter with jitter (
utils/rate_limiter.py), large-result spill-to-file with startup sweep (utils/spill.py), cron expression parsing (utils/cron.py), background task manager + cron scheduler (task/), and a BOM-safe CSV export helper with demo toolexport_products_csv(utils/export.py+tools/export_tools.py).
Related MCP server: Skeleton MCP Server
Quick start
uv venv && uv sync --dev
# Run the server (pick one transport)
uv run service-mcp stdio
uv run service-mcp streamable-http --host 0.0.0.0 --port 8001
uv run service-mcp sse --host 0.0.0.0 --port 8001
uv run service-mcp ui --dev-port 8080 --mcp-port 8001On first start the server auto-creates configs/config.{MCP_ENV}.toml with a default in-memory
SQLite database + Redis cache config — zero configuration to get going.
Example entities
The template ships one minimal domain — Product + ProductPrice — implemented end-to-end to
demonstrate every pattern you need to replicate for your own entities. Field names match the
sibling backend/frontend demo product contract (code / name / category / price /
stock / is_active / remark).
Entity | Demonstrates |
| unique business code, soft-delete flag, auto-placeholder creation (orphan parent) |
| FK code resolution ( |
Follow the chain: add_product → AddHandler → CodeResolveMixin._resolve_fk_codes →
ProductPrice rows auto-resolve code → product_id; delete_product marks all its
prices abnormal=Orphaned; add_product_price with a conflicting same-day value
bumps version and flags abnormal=PriceConflict.
Project structure
service_mcp/
├── server.py # FastMCP app + Typer CLI (stdio/sse/streamable-http/ui)
├── config.py # MCPSettings layered config (env → TOML → code)
├── apps/ # FastMCP Apps UI (config_app: DB/cache management dashboard)
├── auth/ # JWT middleware, mcp_perm decorator, permission/entity discovery
├── db/ # DBManager (async SQLAlchemy CRUD/paginate) + InfluxDBManager
├── handlers/ # CodeResolveMixin + Add/Update/Delete/Query handlers
├── models/
│ ├── orm/ # SQLAlchemy models (base.py audit columns, product.py example)
│ ├── pydantic/ # dynamic Filter/Search generators + per-entity request/response models
│ └── schemas.py # DB/cache config schemas + pagination
├── tools/ # crud_factory (registry-driven), query_tools, basic_tools, dict_tools
├── task/ # generic background task manager + cron scheduler (TaskManager/TaskScheduler)
└── utils/ # enums, logging, path helpers, rate_limiter, spill, cron, export (CSV)
configs/ # config.example.toml skeleton (per-env TOMLs are git-ignored)
docker/ # compose files, entrypoint, ctl.sh/ctl.ps1
mock/ # mock_product_data.py
scripts/ # rename_project.py, refresh_project_stub.py, migrate_example.py, _migration_common.py
tests/ # pytest suite (in-memory SQLite)Add a new entity
ORM: create
service_mcp/models/orm/<entity>.pysubclassingBase(audit columns are inherited); add a unique business code column with acomment(used by friendly duplicate messages) and anabnormal: AbnormalType | Nonecolumn for orphan marking. Export it inmodels/orm/__init__.py(importbasefirst).Pydantic: create
<Entity>Base/Create/Update/Delete(extendsBaseDeleteModel, requires at least one lookup field) /Responseinmodels/pydantic/<entity>.py; reuse the validator helpers inproduct_validators.pyas a template.Filter/Search: add
create_filter_class(...)/create_search_class(...)calls inmodels/pydantic/filter.py/search.py. If you override the generated class with an explicitclass, re-register it withregister_pyi_class(..., explicit=True).Regenerate stubs:
uv run python scripts/refresh_project_stub.py(run twice; the second run must produce no diff).Handlers: add registry rows —
_CODE_RESOLVE_MAP(FK codes),_NAME_RESOLVE_MAP(name fallback),_OWN_CODE_FIELDS(own unique codes),_AUTO_CREATE_MODELS(placeholder auto-creation),_DELETE_NAME_LOOKUP,_COMPOUND_TARGET_REGISTRY(compound delete keys),_ORPHAN_REGISTRY(children to mark on delete),FIELD_MAPPING_CONFIG(FK display fields for query results).Tools: add a row to
crud_factory._ENTITIES(gives you add/update/delete single+batch tools) and list/search tools inquery_tools.py.Enums: add
EntityType/AuthResourceentries and any domain enums inutils/enums.py.Mock/tests: add a TABLE_META row in
mock/mock_product_data.pyand seeded fixtures intests/conftest.py.
Rename the project (one command)
The template uses placeholder naming (service_mcp / service-mcp / "Service MCP"). To create a
new project from this template:
uv run python scripts/rename_project.py my_company \
--project my-company-mcp --display "My Company MCP" --db my_company_data
uv run python scripts/rename_project.py my_company --write # apply after preview
uv sync # regenerate uv.lock / reinstall
uv run pytest # confirm greenThe script previews by default; pass --write to rewrite file contents and rename the package
directory. uv.lock and the script itself are intentionally skipped — regenerate the lock with
uv sync.
Docker deployment
cp docker/.env.example docker/.env # edit passwords/DB names
./docker/ctl.sh deploy -e prod # or: ctl.ps1 on WindowsInfra only (app runs locally):
cd docker && docker compose up -dServices: PostgreSQL 18 (5432), Redis 8 (6379), optional pgAdmin (5050).
Configuration reference
Env var | Meaning | Default |
| environment name; selects |
|
|
|
|
| default transport |
|
| HTTP transport bindings |
|
| enable Redis cache |
|
|
|
|
| per-database config (nested | — |
| logging config (console/file/JSON rotation) | — |
Testing & quality
pytest # all tests (in-memory SQLite, no external services)
ruff check . # lint
ruff format . # format
mypy service_mcp # type checkLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP server for AI-driven data ops. Create apps, manage schemas, and CRUD structured data.
MCP server for Boson Protocol — on-chain agentic commerce for physical & digital goods.
The official MCP Server from Mia-Platform to interact with Mia-Platform Console
MCP server for Modern Treasury — payment orders, transactions, counterparties and ledgers.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA production-ready foundation template for building Model Context Protocol (MCP) servers with FastAPI, featuring modular tools, comprehensive testing, and OpenShift deployment configurations. Includes automated transformation scripts to create custom domain-specific MCP servers.71Apache 2.0
- AlicenseAqualityDmaintenanceA template project for building Model Context Protocol servers with FastMCP framework, Docker support, and example CRUD API implementation to help developers quickly bootstrap their own MCP servers.6MIT
- FlicenseNot gradedqualityDmaintenanceA minimal, production-ready FastMCP server template with auto-discovery, YAML configuration, authentication, and a knowledgebase, enabling quick scaffolding of new MCP servers.-
- AlicenseNot gradedqualityDmaintenanceA production-ready FastMCP server template supporting local development with stdio and secure web deployment with HTTPS and OAuth.4MIT