Cover image
Try Now
2025-03-24

使用FastApi的模型上下文协议服务器实现

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

Model Context Protocol Server

A FastAPI-based implementation of a Model Context Protocol (MCP) server that handles model context management, session handling, and protocol operations.

Features

  • FastAPI-based REST API server
  • Model context management
  • Session handling and persistence
  • WebSocket support for real-time updates
  • Authentication and authorization
  • Request validation and error handling
  • Swagger/OpenAPI documentation
  • Docker support

Project Structure

mcp-protocol-server/
├── app/
│   ├── __init__.py
│   ├── main.py
│   ├── config.py
│   ├── core/
│   │   ├── __init__.py
│   │   ├── context.py
│   │   ├── session.py
│   │   └── protocol.py
│   ├── api/
│   │   ├── __init__.py
│   │   ├── endpoints/
│   │   │   ├── __init__.py
│   │   │   ├── context.py
│   │   │   └── session.py
│   │   └── dependencies.py
│   ├── models/
│   │   ├── __init__.py
│   │   ├── context.py
│   │   └── session.py
│   └── utils/
│       ├── __init__.py
│       └── security.py
├── tests/
│   ├── __init__.py
│   ├── conftest.py
│   ├── test_context.py
│   └── test_session.py
├── docker/
│   ├── Dockerfile
│   └── docker-compose.yml
├── requirements.txt
├── .env.example
└── README.md

Installation

  1. Clone the repository:
git clone https://github.com/tian1ll1/mcp-protocol-server.git
cd mcp-protocol-server
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Copy the example environment file and configure your settings:
cp .env.example .env

Running the Server

Development Mode

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

Production Mode

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

Using Docker

docker-compose up -d

API Documentation

Once the server is running, you can access the API documentation at:

Testing

Run the test suite:

pytest

Configuration

The server can be configured using environment variables or a .env file. See .env.example for available options.

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Lists Tailwind CSS classes in monospaced font

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

    Reviews

    5 (1)
    Avatar
    user_KOB321o0
    2025-04-15

    As a devoted user of MCP applications, I find the MCP Google Contacts Server by RayanZaki to be incredibly efficient and user-friendly. It seamlessly synchronizes and manages my contacts, significantly boosting my productivity. For anyone looking to simplify their contact management, I highly recommend checking it out!