Model Context Protocol (MCP) Server
使用 LangChain / Python 的 MCP 客户端
这个简单的模型上下文协议 (MCP)客户端演示了 LangChain ReAct Agent 对 MCP 服务器工具的使用。
它利用了langchain_mcp_tools中的实用函数convert_mcp_to_langchain_tools() 。
此函数处理指定的多个 MCP 服务器的并行初始化,并将它们可用的工具转换为与 LangChain 兼容的工具列表 ( List[BaseTool] )。
目前支持 Anthropic、OpenAI 和 Groq 的 LLM。
此 MCP 客户端的 TypeScript 版本可在此处获取
先决条件
Python 3.11+
Related MCP server: OpenAI and Claude MCP
设置
安装依赖项:
make install设置 API 密钥:
cp .env.template .env根据需要更新
.env。.gitignore配置为忽略.env以防止意外提交凭据。
根据需要配置 LLM 和 MCP 服务器设置
llm_mcp_config.json5。MCP 服务器的配置文件格式遵循与Claude for Desktop相同的结构,但有一点不同:键名
mcpServers已更改为mcp_servers,以遵循 JSON 配置文件中常用的 snake_case 约定。文件格式为JSON5 ,其中允许使用注释和尾随逗号。
该格式进一步扩展,用相应环境变量的值替换
${...}符号。将所有凭证和私人信息保存在
.env文件中,并根据需要使用${...}符号引用它们。
用法
运行应用程序:
make start第一次运行需要一段时间。
以详细模式运行:
make start-v查看命令行选项:
make start-h在提示符下,您只需按 Enter 即可使用执行 MCP 服务器工具调用的示例查询。
可以在llm_mcp_config.json5中配置示例查询
Available Tools
2 toolsget-alertsC
Get weather alerts for a US state
Inputs: state (required).
get-forecastB
Get weather forecast for a location in the US
Inputs: latitude (required), longitude (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The tools get-alerts and get-forecast have clearly distinct purposes: one provides weather alerts, the other gives forecasts. No overlap.
Both tool names follow the consistent pattern 'get-<resource>', using lowercase and hyphens, which is predictable.
With only 2 tools, the server feels too sparse for a weather domain. Typically, more operations like current conditions or radar would be expected.
The tool set only covers alerts and forecasts, missing common weather operations like current conditions, location search, or severe weather warnings, resulting in significant gaps.
Maintenance
Related MCP Connectors
AI routing, memory, guardrails, and governance. Routes across Claude, GPT, Gemini.
OpenAI-compatible BYOK LLM gateway: per-task routing, shadow evaluation, promotion gates.
Chat, image, video, and audio models from many vendors behind one remote MCP server and one key.
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceThis server provides an API to query Large Language Models using context from local files, supporting various models and file types for context-aware responses.1ISC
- AlicenseNot gradedqualityDmaintenanceA simple server that acts as a Master Control Program (MCP) for unified interaction with OpenAI and Anthropic (Claude) AI models through a single API endpoint.MIT
- AlicenseNot gradedqualityDmaintenanceA unified API server that enables interaction with multiple AI model providers like Anthropic and OpenAI through a consistent interface, supporting chat completions, tool calling, and context handling.ISC
- FlicenseAqualityDmaintenanceUnified MCP server for querying multiple LLM providers (Gemini, OpenAI, Anthropic, etc.) with advanced routing, cost optimization, and fallback resilience.2-