MCP Server — FastAPI
A FastAPI-based MCP server providing automation and AI-powered tools for performance testing, security scanning, browser automation, code review, code generation, knowledge retrieval, and design collaboration via both REST API and MCP protocol.
README
Model Context Protocol (MCP) Server — FastAPI
A FastAPI-based MCP Server that exposes automation and AI tools via both REST API and MCP protocol. Tools cover performance testing (JMeter), security scanning (OWASP ZAP), browser automation (Playwright, Selenium), code review (GitLab), AI code generation (unit tests, scenario tests, API specs), knowledge retrieval (RAG/Knowledge Base), and design collaboration (Miro).
Table of Contents
- Prerequisites
- Project Structure
- Environment Variables
- Start the Server
- API & MCP Access
- Architecture
- Available Tools (MCP)
- Development
1. Prerequisites
- Docker
- Docker Compose (included with Docker Desktop)
2. Project Structure
├── functions/
│ └── main.py # FastAPI entry point; registers all routers; configures MCP
├── routers/ # One file per domain (REST endpoints)
├── services/ # Core business logic
├── batch_jobs/
│ ├── base/
│ │ └── subprocess_job_runner.py # Spawns worker processes; tracks state
│ └── jobs/ # One job file per async tool
├── schemas/ # Pydantic request/response models
├── models/ # DynamoDB models, job registry, OWASP ZAP state
├── constants/
│ └── config.py # All env-var constants (source of truth)
├── jobs/
│ └── scheduler.py # APScheduler: background sync jobs
├── prompts/ # Jinja2 prompt templates (organized by feature)
├── skills/ # Markdown skill definitions for agent workflows
├── subagents/ # Agent role documentation for multi-step pipelines
├── ui_s3_manager/ # Sub-app mounted at /ui-s3-manager and /ui-s3
├── data/
│ └── DDL/ # DynamoDB table creation scripts
├── public/ # Static files (served at /public)
├── docker/ # Dockerfiles for fastapi (ZAP uses zaproxy/zap-stable in compose)
├── docker-compose.yml
├── requirements.txt
├── .env.example
└── ruff-guide.md
3. Environment Variables
Copy .env.example to .env and fill in the required values:
cp .env.example .env
| Variable | Required | Description |
|---|---|---|
AWS_REGION |
Yes | AWS region for S3, DynamoDB, Bedrock, etc. |
AWS_ACCESS_KEY_ID |
Yes | AWS credentials |
AWS_SECRET_ACCESS_KEY |
Yes | AWS credentials |
S3_BUCKET_NAME |
Yes | S3 bucket for uploads and report storage |
| GitLab host allowlist | Code | Edit constants/gitlab_hosts.py (not .env) |
GITLAB_TOKEN |
Removed | Replaced by per-request gitlab_token field in tool inputs |
REDIS_HOST |
Yes* | Redis host for Miro OAuth state and per-user token storage |
REDIS_PORT |
Yes* | Redis port (default 6379 in Docker Compose) |
AUTH_JWT_SECRET |
Yes | JWT secret for AuthMiddleware |
AWS_BEDROCK_LLM_MODEL |
Yes | Bedrock model ID (e.g. anthropic.claude-3-haiku-20240307-v1:0) |
SLACK_HOOK |
No | Slack incoming webhook URL for job notifications |
SLACK_CHANNEL |
No | Slack channel for notifications |
BACKLOG_DOMAIN |
No | Backlog domain for backlog sync jobs |
BACKLOG_API_KEY |
No | Backlog API key |
BACKLOG_PROJECT_KEYS |
No | Comma-separated Backlog project keys |
LLM_LOCAL_BASE_URL |
No | Base URL for local LLM (e.g. Ollama: http://localhost:11434) |
LLM_LOCAL_MODEL |
No | Local LLM model name (e.g. qwen2.5:3b) |
BEDROCK_AGENT_ID |
No | AWS Bedrock Agent ID |
BEDROCK_AGENT_ALIAS_ID |
No | AWS Bedrock Agent Alias ID |
RAG_INIT_S3_FOLDER |
No | S3 folder to seed the RAG knowledge base on startup |
Yes*= required only when using that specific tool group.
See .env.example for all RAG, Selenium, and Redis tuning options.
4. Start the Server
Use the OS-specific wrapper script instead of calling docker compose directly. Each script auto-detects the host architecture and sets the correct platform before delegating to Docker.
macOS (Intel or Apple Silicon)
One-time prerequisite for Apple Silicon (M1/M2/M3):
Docker Desktop → Settings → General → enable "Use Rosetta for x86_64/amd64 emulation on Apple Silicon" → Apply & Restart
Step 1 — Build and start:
# All services
./run.sh up --build
# Minimal setup (fastapi + redis only)
./run.sh up --build fastapi redis
# Run in background
./run.sh up -d fastapi redis
On Apple Silicon you will see:
[run.sh] Apple Silicon (arm64) detected — running linux/amd64 containers via Rosetta 2 emulation
Windows
# All services
.\run.ps1 up --build
# Minimal setup (fastapi + redis only)
.\run.ps1 up --build fastapi redis
# Run in background
.\run.ps1 up -d fastapi redis
Common commands (both OSes)
# Stop all containers
./run.sh down # macOS
.\run.ps1 down # Windows
# View logs
./run.sh logs -f fastapi
# Open a shell inside the container
docker exec -it fastapi_app bash
Step 2 — (One-time) Create DynamoDB tables:
docker exec -it fastapi_app python ./data/DDL/create_dynamodb_tables.py
Check container logs:
docker logs fastapi_app
5. API & MCP Access
| Interface | URL |
|---|---|
| REST API docs (Swagger) | http://localhost:8000/docs |
| MCP endpoint | http://localhost:8000/mcp |
| S3 File Manager UI | http://localhost:8000/ui-s3-manager |
Integrate into an LLM client (MCP config):
{
"mcpServers": {
"local-mcp": {
"url": "http://localhost:8000/mcp"
}
}
}
6. Architecture
Request Flow
Client → Router → Service → (optional) Batch Job → DynamoDB / Redis
↑
Client polls GET /api/history/{operation_id} ───────────┘
- Router (
routers/) — validates the request schema and calls the service. - Service (
services/) — core business logic. Short operations (reading rules, file uploads, Miro API calls) return a result immediately. Long-running operations (test execution, security scans, LLM generation) spawn a batch job and return anoperation_id. - Batch Job (
batch_jobs/jobs/) — runs in a subprocess viaSubprocessJobRunner; writes status to DynamoDB/Redis. Only used for async operations. - Client — polls
GET /api/history/{operation_id}(exposed as theget_resultMCP tool) until the job resolves. Only needed after async operations.
Infrastructure
| Service | Description | Exposed Port |
|---|---|---|
fastapi |
Main app (fastapi_app) |
8000 |
owaspzap_1–5 |
5 parallel OWASP ZAP instances | 8080 (internal) |
redis |
Job state / caching | 6379 |
LLM Integration
| Service | Description |
|---|---|
LLMService (services/llm_service.py) |
Direct AWS Bedrock invocations |
LLMLocalService (services/llm_local_service.py) |
Local LLM via LLM_LOCAL_BASE_URL / LLM_LOCAL_MODEL |
Model IDs are configured via AWS_BEDROCK_LLM_MODEL in constants/config.py.
MCP Exposure
Only operations listed in include_operations inside functions/main.py are exposed as MCP tools. Endpoints tagged "allure" are additionally exposed via include_tags.
When adding a new router endpoint intended for MCP, add its
operation_idtoinclude_operationsinfunctions/main.py.
Authentication
AuthMiddleware (services/auth_service.py) is applied globally to all routes. JWT secret is configured via AUTH_JWT_SECRET.
7. Available Tools (MCP)
| Domain | Operation IDs |
|---|---|
| JMeter | run_jmeter |
| OWASP ZAP | scan_owasp_zap, scan_owasp_zap_scenario, scan_owasp_zap_website |
| Playwright | get_playwright_scenario_rules, run_playwright_e2e, run_playwright_converse |
| GitLab | gitlab_review_merge_request |
| Miro | create_miro_board, get_all_boards, get_miro_mermaid_rules, draw_miro_board |
| Spec Generator | get_template_design, publish_file, publish_file_ui, publish_file_via_s3, extract_archive, ai_generate_spec |
| Unit Test Generator | ai_generate_unit_test |
| Scenario Test Generator | generate_scenario_test |
| Knowledge Base | knowledge_ask |
| Allure | all endpoints tagged allure |
| History | get_result, stop_operation |
8. Development
All linting and formatting commands run inside the container:
# Open a shell in the container
docker exec -it fastapi_app bash
# Lint
ruff check .
ruff check . --fix # auto-fix
ruff check path/to/file.py
# Format
ruff format .
ruff format path/to/file.py
ruff format . --check # dry run (no changes)
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。