构建和使用自定义的 MCP( 模式上下文协议) 服务器
概览
一个演示如何构建和使用MCP(模式上下文协议)服务器的简单项目. 3.-起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起起 该MCP服务器已部署并可供测试,地点: --:https://my-mcp.fastmcp.app/mcp --:生产就绪 配置 Windsurf 以使用已部署的终点 : - 在 MCP 支持下询问任何 LLM : “ 显示 gn1264 的寄存器” - 部署的服务器将使用 GitHub 数据响应 。 - 不需要本地 Python 环境 - 总是可用和可靠的 - 管理基础设施 - 与本地版本相同的功能 两个服务器都是独立的,并显示不同的使用例: -:演示GitHub MCP服务器如何在市场上运行 - :普通用户的公共GitHub API访问 - :GitHub API操作(获得再投放,承诺,搜索等) -:商业GitHub MCP集成
概述(AI 翻译)
一个演示如何构建和使用MCP(模式上下文协议)服务器的简单项目.
□ 快开始
-
** 建立附属关系:**
-
** 在Windsurf/Claude桌面配置MCP服务器:**
-
** 与LLM有关的使用:**
- 启动Windsurf/Claude桌面
- 问: “给我看看奥克托猫的仓库”
- LLM 将自动调用 MCP 服务器工具
□ 现场部署
这个MCP服务器已经部署,可在下列地点测试:
- ** URL**:
https://my-mcp.fastmcp.app/mcp - 现状:已就绪
使用已部署的服务器
配置 Windsurf 以使用已部署的终点 :
** 测试已部署的服务器:**
- 在MCP支持下询问任何LLM:“给我看gn1264的寄存器”
- 部署的服务器将使用 GitHub 数据响应
部署服务器的好处
- 不需要本地Python环境
- 总是可用和可靠的
- 管理基础设施
- 与本地版本相同的功能
□ 测试( 可选)
用于开发和测试:
□ 项目结构
□ MCP 服务器
两个服务器都是独立的,并显示不同的使用例:
GitHub 服务器 ([[T1])
- 目的:示范GitHub MCP服务器如何在市场上运作
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MCP Server Project
A simple project demonstrating how to build and use MCP (Model Context Protocol) servers.
Quick Start
- Install dependencies:
pip install -r requirements.txt
- Configure MCP server in Windsurf/Claude Desktop:
{
"mcpServers": {
"github": {
"command": "python",
"args": ["/path/to/server/github.py"],
"env": {
"GITHUB_TOKEN": "your_github_token_here (see .env.example)"
}
},
"database": {
"command": "python",
"args": ["/path/to/server/database.py"]
}
}
}
- Use with LLM:
- Start Windsurf/Claude Desktop
- Ask: “Show me octocat’s repositories”
- LLM will automatically call the MCP server tools
🚀 Live Deployment
This MCP server is deployed and available for testing at:
- URL:
https://my-mcp.fastmcp.app/mcp - Status: Production ready
Using the Deployed Server
Configure Windsurf to use the deployed endpoint:
{
"mcpServers": {
"github-mcp-deployed": {
"url": "https://my-mcp.fastmcp.app/mcp",
"disabled": false
}
}
}
Test the deployed server:
- Ask any LLM with MCP support: “Show me repositories for gn1264”
- The deployed server will respond with GitHub data
Benefits of Deployed Server
- ✅ No local Python environment required
- ✅ Always available and reliable
- ✅ Managed infrastructure
- ✅ Same functionality as local version
Testing (Optional)
For development and testing:
# Test GitHub server
python testing/test_github_server.py get-repos octocat
# Test Database server
python testing/test_database_server.py query "SELECT * FROM users"
Project Structure
mcp/
├── server/ # MCP servers
│ ├── github.py # GitHub API server
│ └── database.py # Database server
├── client/ # Real LLM client
│ └── mcp_client.py # LLM integration example
├── testing/ # Server testing utilities
│ ├── test_github_server.py # Test GitHub server
│ └── test_database_server.py # Test Database server
├── simple.db # Sample database file
├── requirements.txt # Dependencies
├── README.md # This file
└── learn.md # Learning guide
MCP Servers
Both servers are independent and demonstrate different use cases:
GitHub Server (server/github.py)
- Purpose: Demonstrates how GitHub MCP servers work in the market
- Use Case: Public GitHub API access for general users
- Tools: GitHub API operations (get repos, commits, search, etc.)
- Similar to: Commercial GitHub MCP integrations
Database Server (server/database.py)
- Purpose: Shows enterprise database integration patterns
- Use Case: Internal database access in enterprise environments
- Tools: SQL query execution
- Similar to: Custom internal MCP servers for company data
Testing vs Real Usage
Testing Utilities (testing/)
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"github": {
"command": "python",
"args": ["/path/to/server/github.py"],
"env": {
"GITHUB_TOKEN": "your_github_token_here (see .env.example)"
}
},
"database": {
"command": "python",
"args": ["/path/to/server/database.py"]
}
}
}