abstract-backend-mcp
Reusable MCP server for Python backend development with FastAPI, MongoDB, and Stackraise support.
README
abstract-backend-mcp
Reusable MCP server for Python backend development with FastAPI, MongoDB and Stackraise support.
Features
- Health & diagnostics – ping, runtime config, project health checks
- Test runner – pytest via Poetry (all, by file, keyword, node-id)
- Quality tools – ruff check, ruff format, pyright, combined suite
- FastAPI introspection – list routes, find routes, OpenAPI summary
- MongoDB operations – readonly inspection + permission-controlled writes
- Stackraise context – module detection, domain models, auth scopes, workflows, context snapshots
- Bootstrap CLI – auto-generate config files for any Python backend
Requirements
- Python >= 3.12
- Poetry
Installation
# Clone and install
git clone <repo-url> abstract-backend-mcp
cd abstract-backend-mcp
poetry install
Quick Start
# Bootstrap MCP config in your project
cd /path/to/your-project
poetry run abstract-mcp init
# Start MCP server (stdio transport)
poetry run abstract-mcp serve
# With a YAML config override
poetry run abstract-mcp serve --config mcp.project.yaml
Usage: How to Connect the MCP to Your Project
There are three ways to use this MCP server, from lightest to most integrated:
Option A: Reference from your MCP client (recommended, zero coupling)
The MCP lives in its own repo. Your project only needs a client config file (e.g. opencode.jsonc, VS Code MCP settings, etc.) pointing to it:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"abstract-mcp": {
"type": "local",
"command": [
"poetry",
"-C",
"/path/to/coding-mcp",
"run",
"abstract-mcp",
"serve",
"--config",
"/path/to/your-project/mcp.project.yaml"
],
"enabled": true,
"environment": {
"PROJECT_NAME": "my-app",
"PROJECT_ROOT": "/path/to/your-project",
"FASTAPI_APP_PATH": "src.main:app"
}
}
}
}
Pros: no dependency added to your project, one MCP repo serves multiple projects. Cons: every dev needs the MCP repo cloned locally at a known path.
Option B: Install as a local dev dependency
From your project directory:
poetry add --group dev /path/to/coding-mcp
Then you can run the CLI directly inside your project:
poetry run abstract-mcp init # generate config files
poetry run abstract-mcp serve # start MCP server
And point your client config to the project itself:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"abstract-mcp": {
"type": "local",
"command": ["poetry", "run", "abstract-mcp", "serve"],
"enabled": true
}
}
}
Pros: self-contained, any dev can run poetry install and it works.
Cons: adds a dev dependency; linked to a local path (or needs a registry).
Option C: Publish to a private registry (teams)
cd /path/to/coding-mcp
poetry build
poetry publish --repository your-private-registry
Then in any project:
poetry add --group dev abstract-backend-mcp
Pros: versioned, no local path coupling. Cons: requires a package registry.
Multiple projects simultaneously
Each client session spawns its own MCP process (stdio transport = 1 process per connection). You can run multiple projects at the same time without conflicts — each has its own config and its own process.
Typical workflow
1. Clone coding-mcp once on your machine
2. In your target project:
a. Create a mcp.project.yaml with project-specific settings
b. Point your MCP client to the server (option A, B, or C)
3. Start your client (OpenCode, VS Code, Copilot CLI, etc.)
4. The MCP exposes all configured tools to the agent
Configuration
Settings are loaded from (in order of priority):
- Environment variables
.envfile- YAML config file (via
--configorCONFIG_FILEenv var) - Built-in defaults
Key settings
| Variable | Default | Description |
|---|---|---|
PROJECT_NAME |
my-project |
Project identifier |
ENVIRONMENT |
development |
Current environment |
FASTAPI_APP_PATH |
app.main:app |
Python import path of the FastAPI app |
MONGODB_URI |
mongodb://localhost:27017 |
MongoDB connection string |
MONGODB_SAMPLE_MAX_DOCUMENTS |
20 |
Maximum number of sampled documents returned by MongoDB tools |
MONGODB_SAMPLE_MAX_BYTES |
65536 |
Maximum total bytes returned by sample_documents |
MONGODB_SAMPLE_MAX_FIELD_CHARS |
2000 |
Max characters preserved per string field in sampled documents |
ENABLE_FASTAPI_TOOLS |
true |
Enable FastAPI tools |
ALLOW_FASTAPI_RUNTIME_IMPORTS |
false |
Allow importing FastAPI runtime app for route/OpenAPI inspection |
ENABLE_MONGODB_TOOLS |
true |
Enable MongoDB tools |
ENABLE_STACKRAISE_TOOLS |
false |
Enable Stackraise tools |
ENABLE_DEEP_STACKRAISE_CONTEXT |
true |
Enable deep module/symbol indexing |
ALLOW_WRITE_OPERATIONS |
false |
Allow MongoDB writes |
REQUIRE_WRITE_CONFIRMATION |
true |
Require explicit confirmed=True |
ALLOWED_WRITE_COLLECTIONS |
[] |
Collection allowlist (empty = all) |
STACKRAISE_CONTEXT_MODE |
hybrid |
Extraction mode: static, runtime, hybrid |
ALLOW_RUNTIME_CONTEXT_IMPORTS |
false |
Allow live runtime imports during context extraction |
STACKRAISE_MODULE_ROOTS |
[] |
Optional glob roots for Stackraise packages |
MAX_SOURCE_CHUNK_LINES |
200 |
Max lines returned by source-oriented tools |
MAX_TOTAL_SNAPSHOT_ITEMS |
500 |
Global cap for deep snapshot inventories |
MAX_OUTPUT_ITEMS |
50 |
Max items returned by paginated Stackraise tools |
STACKRAISE_SEARCH_MAX_PATTERN_LENGTH |
200 |
Max accepted length for search_stackraise_code pattern |
STACKRAISE_SEARCH_TIMEOUT_MS |
500 |
Search timeout budget in milliseconds |
STACKRAISE_SEARCH_MAX_SCANNED_LINES |
20000 |
Max total scanned lines for code search |
STACKRAISE_CONTEXT_CACHE_TTL_SECONDS |
30 |
Cache TTL for Stackraise context provider |
STACKRAISE_CONTEXT_CACHE_MAX_ENTRIES |
32 |
Max in-memory context cache entries |
STACKRAISE_CONTEXT_FINGERPRINT_TTL_SECONDS |
1 |
TTL for project fingerprint reuse before rescanning files |
REDACT_SENSITIVE_FIELDS |
true |
Redact secrets in all output |
PROJECT_INSTRUCTIONS_FILE |
PROJECT.md |
Path to project instructions file |
Cache profile recommendations
- High precision profile (always reflect file changes quickly):
STACKRAISE_CONTEXT_FINGERPRINT_TTL_SECONDS=0STACKRAISE_CONTEXT_CACHE_TTL_SECONDS=0
- Balanced profile (default, better performance):
STACKRAISE_CONTEXT_FINGERPRINT_TTL_SECONDS=1STACKRAISE_CONTEXT_CACHE_TTL_SECONDS=30
Use the high precision profile when actively editing many modules and you need the most up-to-date snapshot on every request.
Project Instructions (PROJECT.md)
Each project can define a PROJECT.md file that the MCP reads at startup and passes as context to the agent. This replaces the generic default instructions with project-specific goals, architecture notes, and conventions.
Format
The file uses YAML frontmatter (optional) + markdown body:
---
name: my-app
description: Document management API with electronic signatures
stack:
- FastAPI
- MongoDB
- Stackraise
conventions:
- Use Pydantic for all validation
- Tests required for every endpoint
- Spanish comments in domain code
---
## Objetivo
REST API for document management with workflow automation...
## Arquitectura
- backend/src/demo/ contains the main app
- Domain models in domain/
- Services in service/
## Notas para el agente
- Do not modify auth fixtures without confirmation
- Integration tests require MongoDB running locally
How it works
- On startup, the MCP reads
PROJECT.md(or the file configured inPROJECT_INSTRUCTIONS_FILE) from the project root - The frontmatter metadata (name, stack, conventions, description) is formatted and prepended
- The markdown body is included as the main instructions
- The combined text is passed to the MCP server as
instructions, which the agent receives as context
Behavior
| Scenario | Result |
|---|---|
PROJECT.md exists with frontmatter + body |
Full instructions with metadata |
PROJECT.md exists without frontmatter |
Entire file used as instructions |
PROJECT.md does not exist |
Generic default instructions |
| Invalid YAML frontmatter | Warning logged, body used as instructions |
Generation
Running abstract-mcp init generates a PROJECT.md template with detected stack info and placeholder sections.
Runtime access
The tool show_project_instructions lets the agent re-read the parsed PROJECT.md at any time during a session.
Tools
Health
ping– server alive checkshow_runtime_config– sanitized settingslist_enabled_tools– active tool groupscheck_project_health– project structure detection
Tests & Quality
run_tests_all,run_tests_file,run_tests_keyword,run_tests_nodeidrun_ruff_check,run_ruff_format_check,run_pyright,run_quality_suite
FastAPI
list_routes,find_route,show_openapi_summary
When ALLOW_FASTAPI_RUNTIME_IMPORTS=false, FastAPI introspection tools return a blocked error envelope.
MongoDB
- Readonly:
list_collections,sample_documents,count_documents,show_indexes - Writes:
insert_one_controlled,update_one_controlled,delete_one_controlled
MongoDB sample responses are bounded by MONGODB_SAMPLE_MAX_DOCUMENTS and respect
REDACT_SENSITIVE_FIELDS for textual/key-based redaction.
Additionally, payload size is bounded by MONGODB_SAMPLE_MAX_BYTES and large string
fields are truncated according to MONGODB_SAMPLE_MAX_FIELD_CHARS.
Stackraise
detect_stackraise,show_stackraise_modulesshow_stackraise_db_metadata,show_stackraise_auth_scopeslist_stackraise_crud_resources,list_stackraise_workflowslist_stackraise_module_tree,list_stackraise_modulesshow_stackraise_module_symbols,show_stackraise_symbol_sourceread_stackraise_module_chunk,search_stackraise_code(use_regex=falseby default)build_stackraise_context_snapshot– full context with schema:project,stackraise.modules,stackraise.domain,stackraise.apistackraise.auth,stackraise.workflows,stackraise.frontend_contractssecurity(redacted, warnings),extraction(mode, fallback, warnings)
Recommended Stackraise flow
Use navigation in this order to keep responses compact and deterministic:
build_stackraise_context_snapshot(mode="hybrid")list_stackraise_module_tree()show_stackraise_module_symbols(module="stackraise.some_module")show_stackraise_symbol_source(symbol_id="...")orread_stackraise_module_chunk(...)
For large codebases, prefer bounded tree navigation with
list_stackraise_module_tree(parent_module="stackraise", depth=0, limit=50).
By default, list_stackraise_module_tree uses depth=0 to avoid returning deep subtrees.
This workflow follows snapshot -> tree -> symbols -> source and avoids large payloads.
Write Operation Policy
All MongoDB writes are gated by:
ALLOW_WRITE_OPERATIONSmust betrueENVIRONMENTmust not beproduction/prod- Collection must be in
ALLOWED_WRITE_COLLECTIONS(if non-empty) confirmed=Truemust be passed explicitly (whenREQUIRE_WRITE_CONFIRMATION=true)
Context Extraction Modes
| Mode | Behavior |
|---|---|
static |
AST analysis of source files, no imports |
runtime |
Live introspection of imported modules (requires ALLOW_RUNTIME_CONTEXT_IMPORTS=true) |
hybrid |
Runtime with automatic fallback to static (runtime disabled by policy by default) |
Secret Redaction
When REDACT_SENSITIVE_FIELDS=true (default), context output is redacted in two layers:
- key-based redaction (
password,secret,token,api_key, etc.) - textual redaction for symbol/source content (docstrings, literals, bearer/query tokens)
Sensitive values are replaced with ***REDACTED***.
OpenCode Integration
After running abstract-mcp init, use the generated opencode.jsonc:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"abstract-mcp": {
"type": "local",
"command": ["poetry", "run", "abstract-mcp", "serve"],
"enabled": true
}
}
}
The generated opencode.jsonc also includes an agent block with predefined prompts:
- audit – review, quality and security assessment
- build – implementation from execution plan
- fix – remediation based on audit findings
- doc – documentation engineering (Markdown-only edits)
- plan – planning and decomposition before implementation
AGENTS.md remains a concise operational role reference and is generated alongside
opencode.jsonc.
Limitations (v1)
- No HTTP/SSE transport (stdio only)
- Dependency tracing is static and best-effort (import graph only)
- Stackraise introspection is best-effort and defensive
- No advanced RPA analysis beyond detection
- MongoDB adapter uses pymongo (no async motor)
Development
poetry install
poetry run pytest -v
poetry run ruff check .
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。