使用说明
MCP GitHub演示
本项目演示了一个使用FastMCP和SSE传输的MCP(模型上下文协议)服务器。
设置
- 安装依赖项:
uv sync
# or
pip install -r requirements.txt
运行MCP服务器
重要:MCP服务器必须正在运行 之前 启动MCP检查器。
启动MCP服务器
在一个终端中,启动服务器:
python mcp_server.py
服务器将于启动 http://localhost:8001 SSE端点位于 http://localhost:8001/sse.
您应该看到:
Running MCP server...
MCP Server will be available at: http://localhost:8001/sse
Make sure this server is running before starting the MCP Inspector!
启动MCP检查器
在另一个终端中,启动检查器:
npx @modelcontextprotocol/inspector
检查员将:
- 在上启动代理服务器
localhost:6277 - 在以下位置打开web UI
http://localhost:6274
为什么选择代理服务器?
MCP检查员使用 代理服务器架构 因为:
-
浏览器限制:Inspector UI在浏览器中运行,但浏览器不能直接:
- 执行基于stdio的进程(大多数MCP服务器使用stdio传输)
- 绕过CORS(跨源资源共享)限制
- 访问本地文件系统或生成进程
-
运输转换:代理服务器充当桥梁:
- 使用各种传输方式(stdio、SSE、HTTP)连接到MCP服务器
- 将MCP协议消息转换为浏览器的HTTP/WebSocket
- 处理身份验证和会话管理
-
架构流程:
Browser UI (port 6274) ↕ HTTP/WebSocket Proxy Server (port 6277) ↕ MCP Protocol (stdio/SSE/HTTP) Your MCP Server (port 8001)
代理是必要的,以便对可能使用与浏览器不兼容的传输的MCP服务器进行基于浏览器的检查。
将检查器连接到服务器
需要配置MCP检查器以连接到您的SSE服务器。以下是步骤:
-
首先启动MCP服务器 (1号航站楼):
python mcp_server.py -
启动检查器 (在2号航站楼):
npx @modelcontextprotocol/inspector -
在检查器UI中:
- 查找“连接”或“添加服务器”按钮
- 输入服务器URL:
http://localhost:8001/sse - 或者使用检查器的连接对话框添加新的SSE服务器
备注:检查器代理在端口6277上运行,但您需要将其连接到在端口8001上运行的MCP服务器。
故障排除
错误:“连接到MCP检查器代理时出错”
此错误通常意味着:
- MCP服务器未运行:确保
python mcp_server.py正在另一个终端中运行 - 端口冲突:检查端口8001是否已在使用中
- CORS问题:服务器已配置CORS中间件,但如果问题仍然存在,请检查浏览器控制台日志
验证服务器是否正在运行
检查服务器是否可访问:
curl http://localhost:8001/sse
您应该得到一个响应(可能是SSE连接尝试)。
检查服务器日志
看看终端 mcp_server.py 正在运行以查找任何错误消息。
$ npx @modelcontextprotocol/inspector
Starting MCP inspector...
⚙️ Proxy server listening on localhost:6277
🔑 Session token: 8899f3c4d6be7e18b934fe7371d2e4cdd2dfe13170d6138db4a494d352c3a092
Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
🚀 MCP Inspector is up and running at:
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=8899f3c4d6be7e18b934fe7371d2e4cdd2dfe13170d6138db4a494d352c3a092
🌐 Opening browser...
New SSE connection request. NOTE: The SSE transport is deprecated and has been replaced by StreamableHttp
Query parameters: {"url":"http://localhost:8001/sse","proxyFullAddress":"http://localhost:6277","transportType":"sse"}
SSE transport: url=http://localhost:8001/sse, headers={"Accept":"text/event-stream"}
Created client transport
Created server transport
Received POST message for sessionId f7c7ff1f-781d-4646-974a-259f9da0b282
Received POST message for sessionId f7c7ff1f-781d-4646-974a-259f9da0b282
...
服务器功能
MCP服务器提供:
-
工具:
search_papers:搜索arXiv上的论文extract_info:按ID提取有关论文的信息
-
资源:
papers://folders:列出可用的主题文件夹papers://{topic}:获取特定主题的论文
-
提示词:
generate_search_prompt:生成搜索论文的提示
-
用于更新requirements.txt的命令
uv pip compile pyproject.toml > requirements.txt -
github命令
$ git remote add origin https://github.com/tien-le/mcp-arxiv-demo $ git remote -v
渲染部署
https://dashboard.render.com>监视器>日志
...
==> Deploying...
==> Running 'python mcp_server.py'
INFO: Started server process [56]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:10000 (Press CTRL+C to quit)
Running MCP server...
MCP Server will be available at: http://0.0.0.0:10000/sse
Make sure this server is running before starting the MCP Inspector!
INFO: 127.0.0.1:46312 - "HEAD / HTTP/1.1" 404 Not Found
==> Your service is live 🎉
==>
==> ///////////////////////////////////////////////////////////
==>
==> Available at your primary URL https://mcp-arxiv-demo.onrender.com
==>
==> ///////////////////////////////////////////////////////////