简易 MCP 工具服务器
一个简单的 MCP 服务器,使用 SSE 传输公开网站获取工具。
要求
Python 3.10 或更高版本(在 Python 3.13 上测试)
Related MCP server: MCP Server Fetch TypeScript
安装
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
# Install the package and dependencies
pip install -r requirements.txtMCP Python SDK 文档
MCP Python SDK 文档已拆分为多个小文件,并整理到docs/目录中。这种结构方便 AI 代理浏览和理解 SDK。文档内容如下:
核心概念(服务器、资源、工具等)
以不同模式运行 MCP 服务器
示例和高级用法
还有更多!
用法
该软件包提供了一个命令行界面 (CLI),其中包含多个用于管理 MCP 服务器的命令:
启动服务器
在默认端口(7000)上启动服务器或指定自定义端口:
# Using default port (7000)
python -m mcp_simple_tool start
# Using custom port
python -m mcp_simple_tool start --port 8000管理服务器
# Check if server is running
python -m mcp_simple_tool check [--port PORT]
# Stop the server
python -m mcp_simple_tool stop [--port PORT]
# Restart the server (stop and start)
python -m mcp_simple_tool restart [--port PORT]重启命令将:
停止指定端口上的任何现有服务器
在后台启动新服务器
等待服务器响应
日志输出到server.log
CLI 快速参考
命令 | 目的 |
| 启动服务器 |
| 停止服务器 |
| 健康检查 |
| 停止和启动 |
服务器工具
该服务器公开以下工具:
fetch :远程HTTP 获取器 - 提供绝对 URL;返回页面文本。
url:要获取的网站的 URL(必需)
search_docs :跨 SDK 文档进行语义搜索;返回前 k 个摘录。
query:搜索短语或问题(必填)k:返回的最佳匹配数(可选,默认值 = 3)
get_content :获取
search_docs返回的任何匹配项的完整本地文件。file:相对于文档的路径(必需)
开发设置
为了进行开发,请安装其他工具:
pip install -e .
pip install -r requirements.txt使用 Makefile 执行常见任务:
# Format code
make fmt
# Run linters
make lint
# Run tests
make test测试套件为所有测试内置了 20 秒的超时时间,以防止挂起,尤其是在使用 SSE 端点时。对于单个测试,可以使用@pytest.mark.timeout(seconds)装饰器指定更严格的超时时间。
语义搜索索引
对于search_docs工具,您可以手动构建或重建向量索引:
# Build or rebuild the semantic search index
python scripts/build_doc_index.py如果索引不存在,则在第一次使用工具时自动建立索引。
项目架构
mcp_simple_tool/
__init__.py # Package initialization
__main__.py # Entry point when run as module
cli.py # Command-line interface
server/ # Server implementation
__init__.py # Server package initialization
app.py # ASGI application setup
config.py # Configuration settings
handlers.py # Tool implementations
http.py # HTTP utilities
semantic_search/ # Semantic search functionality
__init__.py # Package initialization
indexing.py # Build and persist vector store
search.py # Load index and query helpers与游标一起使用
此 MCP 服务器可与 Cursor 配合使用,作为客户端。设置方法如下:
在终端中运行服务器:
source venv/bin/activate
python -m mcp_simple_tool start
# or use the restart command
python -m mcp_simple_tool restart通过创建
.cursor/mcp.json文件来配置 Cursor:
{
"mcpServers": {
"website-fetcher-sse": {
"url": "http://localhost:7000/sse"
}
}
}使用 Cursor 时在提示中提及服务器
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.