FastAPI backend application for MCP (Model Context Protocol) integration with external services.
- FastAPI REST API with comprehensive documentation
- JWT-based authentication with token blacklist
- Support for multiple external services (GitHub, Vercel, Linear, Notion, Slack, Discord, Google Workspace)
- PostgreSQL database integration with SQLAlchemy ORM
- Redis for caching and session management
- Comprehensive error handling and logging
- Health check endpoints
- Credential encryption/decryption
- GitHub: Repository and issue management
- Vercel: Deployment management
- Linear: Project management and issue tracking
- Notion: Workspace and database integration
- Slack: Messaging and channel management
- Discord: Bot and server management
- Google Workspace: File and document management
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Create a .env file with the following variables:
# Database
DATABASE_URL=postgresql://user:password@localhost/mcp_db
# Redis
REDIS_URL=redis://localhost:6379
# Security
ENCRYPTION_KEY=your-32-byte-encryption-key-here
# JWT (for production)
JWT_SECRET_KEY=your-jwt-secret-key
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=30uvicorn src.main:app --reload --host 0.0.0.0 --port 8000uvicorn src.main:app --host 0.0.0.0 --port 8000 --workers 4Once the application is running, you can access:
- Interactive API docs: http://localhost:8000/docs
- ReDoc documentation: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
GET /health- Health checkGET /api/mcp/status- MCP service statusGET /api/mcp/services- List available services
POST /api/mcp/execute- Execute MCP request for a service
All MCP endpoints require Bearer token authentication:
Authorization: Bearer <jwt_token>
{
"service_name": "github",
"payload": {
"action": "create_issue",
"repository": "my-org/my-repo",
"title": "Bug fix needed",
"body": "There's a bug in the login functionality",
"labels": ["bug", "high-priority"]
}
}{
"status": "success",
"action": "github_issue_created",
"data": {
"issue_id": "123",
"url": "https://github.com/my-org/my-repo/issues/123",
"number": 42
},
"message": "GitHub issue created successfully",
"service": "github",
"user_id": 12345,
"timestamp": "2025-11-01T14:15:22Z"
}{
"error": "VALIDATION_ERROR",
"detail": "Invalid service name provided",
"timestamp": "2025-11-01T14:15:22Z"
}src/
├── main.py # FastAPI application and middleware
├── schemas.py # Pydantic models
├── core/
│ ├── __init__.py
│ ├── router.py # API routes
│ └── services.py # Service delegation logic
└── __init__.py
Run tests with pytest:
pytest- JWT token authentication
- Token blacklist for revoked tokens
- Request validation with Pydantic
- CORS configuration
- Trusted host middleware
- Credential encryption
- Input sanitization
The application includes comprehensive logging:
- Request/response logging
- Authentication events
- Service delegation tracking
- Error monitoring
- Performance metrics
The application uses the following main tables:
user_credentials- Encrypted service credentialstoken_blacklist- Revoked JWT tokensservice_logs- Operation audit trail
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.