使用说明
MCP一切
注: 该项目摘自https://github.com/modelcontextprotocol/servers/tree/main/src/everything创建一个独立的实现。
此MCP服务器项目演示了模型上下文协议(MCP)的各种功能。它包括TypeScript和Python中的服务器实现,作为MCP客户端构建器的测试服务器。这两种实现都旨在实现功能对等,展示提示、工具、资源、采样、日志记录等功能。
公共特性
工具
-
echo- 回显输入消息的简单工具
- 输入:
message(string):要回显的消息
- 返回:带有回显消息的文本内容
-
add- 将两个数字相加
- 输入:
a(number):第一个数字b(number):第二个数字
- 返回:加法的文本结果
-
longRunningOperation- 演示长时间操作的进度通知
- 输入:
duration(数字,默认值:10):持续时间(秒)steps(数字,默认值:5):进度步骤数
- 返回:带有持续时间和步骤的完成消息
- 在执行过程中发送进度通知
-
sampleLLM- 使用MCP采样功能演示LLM采样能力
- 输入:
prompt(string):发送给LLM的提示maxTokens(数字,默认值:100):要生成的最大令牌数
- 返回:生成的LLM响应
-
getTinyImage- 返回一个小测试图像
- 无需输入
- 返回:Base64编码的PNG图像数据
-
printEnv- 打印所有环境变量
- 可用于调试MCP服务器配置
- 无需输入
- 返回:所有环境变量的JSON字符串
-
annotatedMessage- 演示如何使用注释提供有关内容的元数据
- 输入:
messageType(枚举:“error”|“success”|“debug”):用于演示不同注释模式的消息类型includeImage(boolean,默认值:false):是否包含示例图像
- 返回:带有不同注释的内容
资源
服务器以两种格式提供100个测试资源:
-
偶数资源:
- 纯文本格式
- URI模式:
test://static/resource/{even_number} - 内容:简单的文字描述
-
奇数资源:
- 二进制blob格式
- URI模式:
test://static/resource/{odd_number} - 内容:Base64编码二进制数据
资源特征:
- 支持分页(每页10个项目)
- 允许订阅资源更新
- 演示资源模板
- 每5秒自动更新订阅的资源
提示
-
simple_prompt- 无参数的基本提示
- 返回:单消息交换
-
complex_prompt- 高级提示演示论证处理
- 必需参数:
temperature(数字):温度设置
- 可选参数:
style(string):输出样式首选项
- 返回:带图像的多回合对话
日志记录
服务器每15秒发送一次随机分级日志消息,以展示MCP的日志记录能力。
TypeScript实现
地点: typescript/
安装
地方发展
# Clone the repository (if not already done)
# git clone https://github.com/modelcontextprotocol/mcp-everything.git
# cd mcp-everything
# Navigate to the TypeScript directory from the repository root
cd typescript
# Install dependencies
npm install
# Build the project
npm run build
# Start the server
npm start
全球安装
# Navigate to the TypeScript directory:
# cd path/to/mcp-everything/typescript
# Then install globally from the local package:
npm install -g .
# Run the server
# (The command name will depend on the 'bin' field in typescript/package.json,
# e.g., 'mcp-everything-ts' or 'mcp-everything' if modified)
# Example:
# mcp-everything-ts
注意:全局安装功能和确切命令取决于 bin 内部配置 typescript/package.json.
码头工人
# Build the Docker image from the repository root
# (Assumes Dockerfile is updated to handle APP_DIR build argument or typescript context)
docker build -t mcp-everything-ts -f Dockerfile . --build-arg APP_DIR=typescript
# Run the container
docker run -it mcp-everything-ts
使用MCP客户端(例如Claude Desktop)
添加到客户端的MCP服务器配置中。路径可能需要调整。
如果使用 npx 使用已发布的包(例如。, mcp-everything-ts):
{
"mcpServers": {
"everything-ts-npx": {
"command": "npx",
"args": [
"-y",
"mcp-everything-ts"
// Replace 'mcp-everything-ts' with the actual package name if different
]
}
}
}
如果从本地版本运行(确保 cwd 是 typescript 目录):
{
"mcpServers": {
"everything-ts-local": {
"command": "npm",
"args": [
"start"
],
// Ensure 'cwd' points to the 'typescript' directory of this project.
"cwd": "path/to/mcp-everything/typescript"
}
}
}
替换 "path/to/mcp-everything/typescript" 正确的路径。
Python实现
地点: python/
安装和设置
- 从存储库根目录导航到Python目录:
cd python - (推荐)创建并激活虚拟环境:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate - 安装依赖项:
pip install -r requirements.txt
运行服务器
从内部 python 目录(如果使用,则激活虚拟环境):
python mcp_server.py
服务器通过stdio监听MCP消息。
使用MCP客户端(例如Claude Desktop)
配置示例:
{
"mcpServers": {
"everything-py": {
"command": "python", // Or "path/to/python/venv/bin/python"
"args": ["mcp_server.py"],
"cwd": "path/to/mcp-everything/python" // Ensure this is the correct path
}
}
}
替换 "path/to/mcp-everything/python" 正确的路径。
通过GitHub操作测试服务器
注: 执行工作正在进行中。服务器尚未完全运行。
- 测试1
- 测试2