LangChain Agent MCP Server

LangChain Agent MCP Server

Exposes LangChain agent capabilities through the Model Context Protocol, enabling multi-step reasoning tasks with ReAct pattern execution via a production-ready FastAPI service deployed on Google Cloud Run.

Category
访问服务器

README

LangChain Agent MCP Server

A production-ready MCP server exposing LangChain agent capabilities through the Model Context Protocol, deployed on Google Cloud Run.

GitHub Stars GitHub Forks License

🚀 Overview

This is a standalone backend service that wraps a LangChain agent as a single, high-level MCP Tool. The server is built with FastAPI and deployed on Google Cloud Run, providing a scalable, production-ready solution for exposing AI agent capabilities to any MCP-compliant client.

Live Service: https://langchain-agent-mcp-server-554655392699.us-central1.run.app

✨ Features

  • MCP Compliance - Full Model Context Protocol support
  • LangChain Agent - Multi-step reasoning with ReAct pattern
  • Google Cloud Run - Scalable, serverless deployment
  • Tool Support - Extensible framework for custom tools
  • Production Ready - Error handling, logging, and monitoring
  • Docker Support - Containerized for easy deployment

🏗️ Architecture

Component Technology Purpose
Backend Framework FastAPI High-performance, asynchronous web server
Agent Framework LangChain Multi-step reasoning and tool execution
Deployment Google Cloud Run Serverless, auto-scaling hosting
Containerization Docker Consistent deployment environment
Protocol Model Context Protocol (MCP) Standardized tool and context sharing

🛠️ Quick Start

Prerequisites

  • Python 3.11+
  • OpenAI API key
  • Google Cloud account (for Cloud Run deployment)
  • Docker (optional, for local testing)

Local Development

  1. Clone the repository:

    git clone https://github.com/mcpmessenger/LangchainMCP.git
    cd LangchainMCP
    
  2. Install dependencies:

    # Windows
    py -m pip install -r requirements.txt
    
    # Linux/Mac
    pip install -r requirements.txt
    
  3. Set up environment variables: Create a .env file:

    OPENAI_API_KEY=your-openai-api-key-here
    OPENAI_MODEL=gpt-4o-mini
    PORT=8000
    
  4. Run the server:

    # Windows
    py run_server.py
    
    # Linux/Mac
    python run_server.py
    
  5. Test the endpoints:

    • Health: http://localhost:8000/health
    • Manifest: http://localhost:8000/mcp/manifest
    • API Docs: http://localhost:8000/docs

☁️ Google Cloud Run Deployment

The server is designed for deployment on Google Cloud Run. See our comprehensive deployment guides:

Quick Deploy

# Windows PowerShell
.\deploy-cloud-run.ps1 -ProjectId "your-project-id" -Region "us-central1"

# Linux/Mac
./deploy-cloud-run.sh your-project-id us-central1

Current Deployment

  • Service URL: https://langchain-agent-mcp-server-554655392699.us-central1.run.app
  • Project: slashmcp
  • Region: us-central1
  • Status: ✅ Live and operational

📡 API Endpoints

MCP Endpoints

Get Manifest

GET /mcp/manifest

Returns the MCP manifest declaring available tools.

Response:

{
  "name": "langchain-agent-mcp-server",
  "version": "1.0.0",
  "tools": [
    {
      "name": "agent_executor",
      "description": "Execute a complex, multi-step reasoning task...",
      "inputSchema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "The user's query or task"
          }
        },
        "required": ["query"]
      }
    }
  ]
}

Invoke Tool

POST /mcp/invoke
Content-Type: application/json

{
  "tool": "agent_executor",
  "arguments": {
    "query": "What is the capital of France?"
  }
}

Response:

{
  "content": [
    {
      "type": "text",
      "text": "The capital of France is Paris."
    }
  ],
  "isError": false
}

Other Endpoints

  • GET / - Server information
  • GET /health - Health check
  • GET /docs - Interactive API documentation (Swagger UI)

🔧 Configuration

Environment Variables

Variable Description Default Required
OPENAI_API_KEY OpenAI API key - ✅ Yes
OPENAI_MODEL OpenAI model to use gpt-4o-mini No
PORT Server port 8000 No
API_KEY Optional API key for authentication - No
MAX_ITERATIONS Maximum agent iterations 10 No
VERBOSE Enable verbose logging false No

📚 Documentation

📖 Full Documentation Site - Complete documentation with examples (GitHub Pages)

Quick Links:

Build Docs Locally:

# Windows
.\build-docs.ps1 serve

# Linux/Mac
./build-docs.sh serve

Additional Guides:

🧪 Testing

# Test health endpoint
Invoke-WebRequest -Uri "https://langchain-agent-mcp-server-554655392699.us-central1.run.app/health"

# Test agent invocation
$body = @{
    tool = "agent_executor"
    arguments = @{
        query = "What is 2+2?"
    }
} | ConvertTo-Json

Invoke-WebRequest -Uri "https://langchain-agent-mcp-server-554655392699.us-central1.run.app/mcp/invoke" `
    -Method POST `
    -ContentType "application/json" `
    -Body $body

🏗️ Project Structure

.
├── src/
│   ├── main.py              # FastAPI application with MCP endpoints
│   ├── agent.py             # LangChain agent definition and tools
│   ├── mcp_manifest.json    # MCP manifest configuration
│   └── start.sh             # Cloud Run startup script
├── tests/
│   └── test_mcp_endpoints.py # Test suite
├── Dockerfile               # Container configuration
├── requirements.txt         # Python dependencies
├── deploy-cloud-run.ps1     # Windows deployment script
├── deploy-cloud-run.sh      # Linux/Mac deployment script
└── cloudbuild.yaml          # Cloud Build configuration

🚀 Deployment Options

Google Cloud Run (Recommended)

  • Scalable - Auto-scales based on traffic
  • Serverless - Pay only for what you use
  • Managed - No infrastructure to manage
  • Fast - Low latency with global CDN

See DEPLOY_CLOUD_RUN_WINDOWS.md for detailed instructions.

Docker (Local/Other Platforms)

docker build -t langchain-agent-mcp-server .
docker run -p 8000:8000 -e OPENAI_API_KEY=your-key langchain-agent-mcp-server

📊 Performance

  • P95 Latency: < 5 seconds for standard 3-step ReAct chains
  • Scalability: Horizontal scaling on Cloud Run
  • Uptime: 99.9% target (Cloud Run SLA)
  • Throughput: Handles concurrent requests efficiently

🔒 Security

  • API key authentication (optional)
  • Environment variable management
  • Secret Manager integration (Cloud Run)
  • HTTPS by default (Cloud Run)
  • CORS configuration

🤝 Contributing

We welcome contributions! Please see our contributing guidelines.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

📜 License

This project is licensed under the MIT License.

🔗 Links

  • GitHub Repository: https://github.com/mcpmessenger/LangchainMCP
  • Live Service: https://langchain-agent-mcp-server-554655392699.us-central1.run.app
  • API Documentation: https://langchain-agent-mcp-server-554655392699.us-central1.run.app/docs
  • Model Context Protocol: https://modelcontextprotocol.io/

🙏 Acknowledgments


Status: ✅ Production-ready and deployed on Google Cloud Run

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选