MCP Server Demo
A WebSocket-based Model Control Protocol (MCP) server that processes model requests and provides responses. Supports chat and text completion actions with a standardized JSON protocol for AI model communication.
README
MCP Server
基于WebSocket的MCP(Model Control Protocol)服务器,用于处理模型请求并提供响应。
项目结构
MCPServerDemo/
├── src/ # 源代码目录
│ └── mcp/ # MCP实现
│ ├── handlers/ # 请求处理器
│ ├── models/ # 数据模型
│ ├── protocol/ # 协议定义
│ └── server/ # 服务器实现
├── client/ # 客户端示例
│ └── index.html # 测试用HTML客户端
├── .env # 环境变量配置(需要从.env.example创建)
├── .env.example # 环境变量示例
├── main.py # 应用程序入口点
└── README.md # 项目说明
安装
本项目使用uv进行依赖管理。
# 安装依赖
uv pip install fastapi uvicorn pydantic pydantic-settings
配置
- 复制环境变量示例文件并进行配置:
cp .env.example .env
- 编辑
.env文件,设置您的配置。
运行
# 启动服务器
python main.py
服务器将在http://localhost:8000上运行,WebSocket端点为ws://localhost:8000/ws。
测试客户端
打开client/index.html文件在浏览器中测试MCP服务器。
MCP协议
MCP协议是一个基于WebSocket的协议,用于控制和管理AI模型。
请求格式
{
"id": "请求ID",
"type": "request",
"action": "动作名称",
"messages": [
{
"role": "user",
"content": "消息内容"
}
],
"parameters": {
"参数名": "参数值"
}
}
响应格式
{
"id": "请求ID",
"type": "response",
"action": "动作名称",
"messages": [
{
"role": "assistant",
"content": "响应内容"
}
],
"metadata": {
"元数据名": "元数据值"
}
}
错误格式
{
"id": "请求ID",
"type": "error",
"action": "动作名称",
"error": "错误信息",
"details": {
"详情名": "详情值"
}
}
事件格式
{
"id": "事件ID",
"type": "event",
"event": "事件名称",
"data": {
"数据名": "数据值"
}
}
支持的动作
chat: 聊天请求completion: 文本完成请求
扩展
您可以通过以下方式扩展MCP服务器:
- 创建新的处理器在
src/mcp/handlers/目录 - 在
main.py中注册新的处理器 - 自定义协议实现在
src/mcp/protocol/目录
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.