关于 Simple MCP Client
Simple MCP Client 是一个用于测试 MCP 服务的 Python 命令行客户端,适合开发者连接多个服务并与 LLM 交互。它结合交互式命令、直接调用工具和支持 ReAct 的聊天模式。
主要功能
- 01连接多个 SSE 或 stdio MCP 服务
- 02支持多种 LLM 提供方
- 03交互式命令行与自动补全
- 04直接执行工具并管理资源和提示词
- 05ReAct 聊天与流式响应
适用场景
- 01测试并检查多个 MCP 服务
- 02通过聊天模式调用服务工具
- 03从命令行获取资源或提示词
MCP 相关
客户端可连接多个 MCP 服务,并发现和调用工具、资源及提示词。它也支持在聊天中由 LLM 驱动工具执行。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Simple MCP Client
一个简单的命令行 MCP(Model Context Protocol)客户端,使用 Python 测试 MCP 服务。支持与各种大模型提供商聊天,并连接多个 MCP 服务。
功能
- 连接多个 MCP 服务(SSE 和 stdio 协议)
- 集成不同的大模型提供商(Ollama、DeepSeek、OpenAI、OpenRouter)
- 支持自动补全的交互式命令行界面
- 基于命令的工具执行
- 支持由大模型驱动工具执行的聊天模式
- 通过 JSON 配置文件进行配置
ReAct Agent 集成
此分支引入了 ReAct(Reasoning and Acting)Agent,增强了聊天功能:
- 智能工具推理:ReAct Agent 会通过推理来确定要使用哪些工具以及何时使用,从而实现更好的工具链式调用和多步骤问题解决
- LangChain MCP 集成:与 LangChain 的 MultiServerMCPClient 无缝集成,改进工具管理
- 增强的聊天体验:清晰展示 Agent 的推理过程和工具执行流程
- 可配置设置:可自定义 Agent 操作的超时时间和最大迭代次数
flowchart TD
START([START]) --> call_model[Call LLM Model]
call_model --> decision{Should End?}
decision -->|"tools"| tools[Execute Tools]
decision -->|"end"| END([END])
tools --> call_model
聊天命令
通过集成 ReAct Agent,chat 命令得到了显著改进:
chat
聊天命令的主要增强包括:
- 由 LangGraph 驱动的推理:使用 LangGraph 的 StateGraph 管理 Agent 的推理和工具执行流程
- 实时显示工具执行过程:实时展示工具调用和结果,并以格式化的形式输出
- 流式响应:Agent 响应会实时流式传输,提供即时反馈
- 改进的错误处理:更好地处理工具执行期间的超时和错误
- 上下文感知对话:保留对话上下文,使多轮交互更加连贯
- 自动发现工具:自动发现并提供所有已连接 MCP 服务中的工具
现在,聊天命令会显示一个标题,其中包含 Agent、已连接服务和可用工具的信息:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Enhanced MCP Chat with ReAct Agent ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ ReAct Agent: openai/gpt-4-turbo │
│ Connected Servers: k8s, weather │
│ Available Tools: 15 │
│ Timeout: 60s │
│ │
│ The agent will use ReAct (Reasoning and Acting) to intelligently select and use tools. │
│ Type exit to return to command mode. │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
聊天模式

执行模式

安装
有多种安装客户端的方式:
使用 pip
pip install simple-mcp-client
使用 UV(推荐)
安装 UV
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate
python -m build
使用 requirements.txt 通过 pip 安装
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .
直接使用 pip 安装
pip install -e .
使用 pyproject.toml 通过 pip 安装
pip install .
配置
客户端使用配置文件定义大模型提供商和 MCP 服务。配置文件存储在特定平台的位置:
- Windows:
%APPDATA%\simple_mcp_client\config.json - Linux/macOS:
~/.config/simple_mcp_client/config.json
如果用户目录中不存在配置文件,客户端会从软件包的 default_config.json 文件复制默认配置,并将其保存到相应位置。
配置示例:
{
"llm": {
"provider": "openai",
"model": "claude-3-7-sonnet-20250219",
"api_url": "https://api.gptoai.top/v1",
"api_key": "",
"other_params": {
"temperature": 0.7,
"max_tokens": 4096
}
},
"mcpServers": {
"k8s": {
"type": "sse",
"url": "http://192.168.182.128:8000/sse",
"command": null,
"args": [],
"env": {}
}
},
"default_server": "k8s"
}
使用
启动客户端:
simple-mcp-client
或者直接运行:
python -m simple_mcp_client.main
可用命令
help:显示帮助信息connect <server_name>:连接到 MCP 服务disconnect <server_name>:断开与 MCP 服务的连接servers:列出可用的 MCP 服务tools [server_name]:列出可用工具,也可指定某个服务resources [server_name]:列出可用资源,也可指定某个服务prompts [server_name]:列出可用提示词,也可指定某个服务formats [server_name]:列出可用提示词格式,也可指定某个服务execute <server_name> <tool_name> [arg1=val1 ...]:使用参数执行指定工具get-resource [server_name] <resource_uri>:从 MCP 服务获取资源get-prompt [server_name] <prompt_name> [format=<format_name>] [arg1=val1 ...]:从 MCP 服务获取提示词chat:使用已配置的大模型和已启用的 MCP 工具启动聊天会话config show:显示当前配置config llm <provider> [model=<model>] [api_url=<url>] [api_key=<key>] [param=value ...]:配置大模型提供商reload:从文件重新加载配置exit:退出程序
命令示例
Execute 命令
execute 命令使用提供的参数运行 MCP 服务中的指定工具。ReAct Agent 集成通过在聊天模式下提供智能工具选择和推理,增强了此功能。
执行特定服务中的工具:
execute k8s get_pod namespace=default name=my-pod
使用多个参数执行工具:
execute weather get_forecast city="San Francisco" days=5
使用 JSON 参数执行工具:
execute github create_issue owner=octocat repo=hello-world title="Found a bug" body="I'm having a problem with this." labels=["bug","help wanted"]
使用 help 参数获取特定工具的帮助信息:
execute tavily tavily-extract help
帮助信息输出示例:
╭─────────────────────────────────────────────────────────────────────────────── Tool Help ───────────────────────────────────────────────────────────────────────────────╮
│ Server │ tavily │
│ Tool │ tavily-extract │
│ Description │ A powerful web content extraction tool that retrieves and processes raw content from specified URLs, ideal for data collection, content analysis, │
│ │ and research tasks. │
│ │ ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────… │
│ Parameters │ │
│ │ Parameter Type Required Description │
│ │ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │
│ │ urls array Yes List of URLs to extract content from │
│ │ extract_depth string No Depth of extraction - 'basic' or 'advanced', if usrls are linkedin use 'advanced' or if explicitly told to use │
│ │ advanced │
│ │ include_images boolean No Include a list of images extracted from the urls in the response │
│ │ ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────… │
│ Example Usage │ │
│ │ execute tavily tavily-extract urls=item1 extract_depth=basic include_images=true │
│ │ ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────… │
│ Note │ │
│ │ For string parameters with spaces, enclose the value in quotes: │
│ │ param="value with spaces" │
│ │ │
│ │ Example: query="latest news about AI" │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
输出将以格式化的方式显示工具名称、参数和结果。
Resources 命令
resources 命令会列出已连接的 MCP 服务中可用的资源和资源模板。
列出所有已连接服务中的全部资源:
resources
列出特定服务中的资源:
resources k8s
输出示例:
Resources from k8s - Direct Resources
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ URI ┃ Name ┃ MIME Type ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ k8s://namespaces │ Kubernetes Namespaces │ application/json │
│ k8s://resources │ Kubernetes Resources │ application/json │
└──────────────────┴───────────────────────┴──────────────────┘
Resources from k8s - Resource Templates
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ URI Template ┃ Name ┃ MIME Type ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ k8s:///{namespace} │ Namespace Overview │ Not specified │
│ k8s:///{resource_type} │ Cluster-Scoped Resources │ Not specified │
│ k8s:///{resource_type}/{name} │ Cluster-Scoped Resource │ Not specified │
│ k8s://{namespace}/{resource_type} │ Resources by Type in Namespace │ Not specified │
│ k8s://{namespace}/{resource_type}/{name} │ Namespaced Resource │ Not specified │
└──────────────────────────────────────────┴────────────────────────────────┴───────────────┘
Prompts 命令
prompts 命令会列出已连接的 MCP 服务中可用的提示词。
列出所有已连接服务中的全部提示词:
prompts
列出特定服务中的提示词:
prompts k8s
输出示例:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ All Available Prompts ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Name │ Description │
│ k8s-describe │ Describe Kubernetes resources │
│ k8s-troubleshoot │ Troubleshoot Kubernetes issues │
└────────────────────┴─────────────────────────────────┘
Get-Resource 命令
get-resource 命令会从 MCP 服务获取资源。
从任何包含该资源的服务获取资源:
get-resource k8s://pods/default
从特定服务获取资源:
get-resource k8s k8s://pods/default
Get-Prompt 命令
get-prompt 命令会从 MCP 服务获取提示词,并支持可选的格式和参数。
从任何包含该提示词的服务获取提示词:
get-prompt k8s-describe
从特定服务获取提示词:
get-prompt k8s k8s-describe
获取指定格式的提示词:
get-prompt k8s-describe format=markdown
获取带参数的提示词:
get-prompt k8s k8s-describe namespace=default resource=pod name=my-pod
环境变量
MCP_LOG_LEVEL:设置日志级别(默认值:INFO)OPENAI_API_KEY:OpenAI API 密钥(用于 OpenAI 提供商,或搭配 OpenAI 模型使用 LiteLLM)DEEPSEEK_API_KEY:DeepSeek API 密钥(用于 DeepSeek 提供商)OPENROUTER_API_KEY:OpenRouter API 密钥(用于 OpenRouter 提供商)ANTHROPIC_API_KEY:Anthropic API 密钥(用于搭配 Anthropic 模型使用 LiteLLM)GOOGLE_API_KEY:Google API 密钥(用于搭配 Google 模型使用 LiteLLM)MISTRAL_API_KEY:Mistral API 密钥(用于搭配 Mistral 模型使用 LiteLLM)COHERE_API_KEY:Cohere API 密钥(用于搭配 Cohere 模型使用 LiteLLM)AZURE_API_KEY:Azure API 密钥(用于搭配 Azure 模型使用 LiteLLM)
推荐模型
我们建议使用支持 MCP 调用的大模型,例如 Qwen3、Grok3 或 Grok4。
LLM 提供商
客户端支持以下 LLM 提供商:
- Ollama:用于在本地运行开源模型的本地 LLM 提供商
- OpenAI:基于 API 的 LLM 提供商,用于访问 OpenAI 的模型
- DeepSeek:基于 API 的 LLM 提供商,用于访问 DeepSeek 的模型
- OpenRouter:基于 API 的 LLM 提供商,可将请求路由到多个 LLM 后端,通过统一 API 提供对不同提供商的大量模型的访问
- LiteLLM:用于接入各种 LLM 提供商(OpenAI、Anthropic、Google、Azure 等)的统一 API,支持备用模型、负载均衡等功能
提供商专属配置
DeepSeek
DeepSeek 需要 API 密钥,可在配置文件中提供,也可通过环境变量(DEEPSEEK_API_KEY)提供。默认 API URL 为 https://api.deepseek.com/v1。
OpenRouter
OpenRouter 需要 API 密钥,可在配置文件中提供,也可通过环境变量(OPENROUTER_API_KEY)提供。默认 API URL 为 https://openrouter.ai/api/v1。
OpenRouter 支持以下附加参数:
http_referer:发起请求时使用的 HTTP 引荐来源(默认值:"https://github.com/simple_mcp_client")app_name:发起请求时使用的应用名称(默认值:"Simple MCP Client")
LiteLLM
LiteLLM 为许多不同的 LLM 提供商提供统一接口。它支持 OpenAI、Anthropic、Google、Azure、Mistral、Cohere 等提供商的模型。模型名称应采用提供商指定的格式,也可以选择添加提供商前缀。
配置示例:
{
"llm": {
"provider": "litellm",
"model": "anthropic/claude-3-opus-20240229",
"api_key": "YOUR_ANTHROPIC_API_KEY",
"other_params": {
"temperature": 0.7,
"max_tokens": 4096,
"request_timeout": 60.0
}
}
}
对于 OpenAI 模型:
{
"llm": {
"provider": "litellm",
"model": "gpt-4-turbo",
"api_key": "YOUR_OPENAI_API_KEY",
"other_params": {
"temperature": 0.7
}
}
}
LiteLLM 会根据模型名称中指定的提供商,自动从环境变量中查找相应的 API 密钥:
OPENAI_API_KEY:用于 OpenAI 模型ANTHROPIC_API_KEY:用于 Anthropic 模型GOOGLE_API_KEY:用于 Google 模型MISTRAL_API_KEY:用于 Mistral 模型COHERE_API_KEY:用于 Cohere 模型AZURE_API_KEY:用于 Azure 模型
你也可以直接在配置中提供 API 密钥。
LiteLLM 支持以下附加参数:
request_timeout:API 请求超时时间,单位为秒fallbacks:主模型失败时尝试使用的备用模型列表cache:启用响应缓存
许可证
MIT
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。