m

mcp-server

@Pritrj/mcp-server
0 Stars 160 次浏览 Pritrj 更新于 2026-08-23

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "redis": {
      "url": "http://localhost:6379/mcp"
    }
  }
}

服务介绍

MCP Server

production-ready Model Context Protocol (MCP) server FastAPI framework

(Features)

  • FastAPI Framework: High-performance async API server
  • Security: JWT authentication secure coding practices
  • Database: PostgreSQL asyncpg
  • Caching: Redis integration
  • Docker Ready: Production-ready containerization
  • Health Checks: Built-in health monitoring
  • Development Ready: Comprehensive testing development tools

(Requirements)

  • Python 3.11+
  • PostgreSQL 13+
  • Redis 6+
  • Docker (optional)

(Installation)

1. Repository Clone

git clone <repository-url>
cd mcp-server

2. Virtual Environment

python -m venv venv
source venv/bin/activate  # Linux/Mac
# 
venv\\Scripts\\activate  # Windows

3. Dependencies Install

pip install -r requirements.txt

4. Environment Variables

.env file :

# Database
DATABASE_URL=postgresql://username:password@localhost:5432/mcp_db

# Redis
REDIS_URL=redis://localhost:6379/0

# Security
SECRET_KEY=your-secret-key-here
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=30

# Server
HOST=0.0.0.0
PORT=8000
DEBUG=false

Usage

Development Mode

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Production Mode

uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4

Docker

# Build 
docker build -t mcp-server .

# Run 
docker run -p 8000:8000 --env-file .env mcp-server

API Documentation

Base URL

http://localhost:8000

Interactive Documentation

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Main Endpoints

Health Check

GET /health

Server health status check

API Endpoints

GET /api/v1/status
POST /api/v1/connect
GET /api/v1/tools
POST /api/v1/tools/{tool_name}/call

Development

Code Quality

# Format code
black .

# Sort imports
isort .

# Lint code
flake8 .

# Type checking
mypy .

Testing

#  tests run 
pytest

# Coverage  
pytest --cov=src tests/

# Specific test file
pytest tests/test_main.py

Project Structure

mcp-server/
 src/                    # Source code
    main.py            # FastAPI application
    models/            # Pydantic models
    routes/            # API routes
    services/          # Business logic
    database/          # Database configuration
    utils/             # Utility functions
 tests/                 # Test files
 requirements.txt       # Python dependencies
 Dockerfile            # Docker configuration
 docker-compose.yml    # Docker Compose (optional)
 .env.example          # Environment variables template
 .gitignore           # Git ignore patterns
 .dockerignore        # Docker ignore patterns
 README.md            # This file

Configuration

Environment Variables

Variable Description Default
DATABASE_URL PostgreSQL connection URL Required
REDIS_URL Redis connection URL redis://localhost:6379/0
SECRET_KEY JWT secret key Required
JWT_ALGORITHM JWT algorithm HS256
JWT_EXPIRE_MINUTES JWT expiration time 30
HOST Server host 0.0.0.0
PORT Server port 8000
DEBUG Debug mode false

Database Setup

-- PostgreSQL database 
CREATE DATABASE mcp_db;

-- User  (optional)
CREATE USER mcp_user WITH PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE mcp_db TO mcp_user;

Redis Setup

# Redis start 
redis-server

#  Docker  
docker run -d -p 6379:6379 redis:alpine

Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • CORS protection
  • Rate limiting
  • Input validation
  • SQL injection protection
  • XSS protection

Monitoring

Health Checks

# Server health check
curl http://localhost:8000/health

# Database connection check
curl http://localhost:8000/health/db

# Redis connection check
curl http://localhost:8000/health/redis

Logging

Logs /logs/ directory store Production proper logging configuration set

Deployment

Docker Deployment

# Production image build 
docker build -t mcp-server:latest .

# Docker Compose  
docker-compose up -d

Manual Deployment

# Gunicorn  
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker

Contributing

  1. Fork
  2. Feature branch (git checkout -b feature/amazing-feature)
  3. Commit (git commit -m 'Add amazing feature')
  4. Push (git push origin feature/amazing-feature)
  5. Pull Request open

License

project MIT license under

Support

GitHub Issues create documentation

Changelog

v1.0.0

  • Initial release
  • FastAPI integration
  • JWT authentication
  • Redis caching
  • Docker support
  • Comprehensive documentation

相关 MCP 服务