MCP服务器与LangChain集成示例

两个小型Python示例项目,展示了一个最小的MCP服务器模式以及使用OpenRouter(兼容OpenAI API)的LangChain集成。

  • by pradhyu
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 pradhyu/mcp-server-samples

使用说明

两个小型Python示例项目演示了最小的“MCP”服务器模式和OpenRouter(与OpenAI兼容的API基础)的LangChain使用。

前提条件

  • Python 3.10+
  • 有效的OpenRouter API密钥(或任何与OpenAI兼容的密钥)。我们假设您使用OpenRouter并在下面设置与OpenAI兼容的环境变量。

环境变量(在运行示例之前设置这些变量):

# OpenRouter-compatible (make sure your key is from OpenRouter)
export OPENAI_API_KEY="<your-openrouter-key>"
export OPENAI_API_BASE="https://api.openrouter.ai/v1"

项目

  • simple_mcp_fastapi/ -最小的基于FastAPI的MCP端点,将消息转发到LangChain的ChatOpenAI(配置为使用OPENAI_API_BASE)。
  • langchain_example/ --直接调用LangChain ChatOpenAI并打印响应的小脚本。

有关运行说明,请参阅每个项目的README。#mcp服务器示例