LangGraph Agent MCP Server

LangGraph Agent MCP Server

Provides a standardized interface to interact with LangGraph agents through ChatGPT Enterprise, enabling conversational AI workflows with tools for agent invocation, streaming responses, and thread management.

Category
访问服务器

README

MCP Server for LangGraph Agent

FastMCP-based Model Context Protocol server for ChatGPT Enterprise integration with LangGraph agent.

🎉 Quick Start

The fastest way to get started:

./start.sh

This will:

  1. Check if your LangGraph agent is running on port 2024
  2. Start the MCP server on port 8000
  3. Start the test UI on port 3005
  4. Open http://localhost:3005 in your browser

Overview

This MCP server provides a standardized interface to interact with a LangGraph agent deployed on port 2024, compliant with ChatGPT Enterprise integration requirements.

✨ Latest Updates

January 2025 - LangGraph CLI Integration

  • ✅ Refactored to use LangGraph CLI API architecture
  • ✅ Updated to /runs, /runs/stream, /ok endpoints
  • ✅ Changed message format to {"type": "human"}
  • ✅ Added 3 new tools: health check, agent status, thread listing
  • ✅ Fixed all async operations (no more blocking calls)
  • ✅ Updated web UI to match new API structure

See REFACTORING_SUMMARY.md for detailed changes.

Features

  • MCP Protocol 2025-06-18 compliant
  • ChatGPT Enterprise compatible (SSE transport)
  • OAuth 2.0 Authentication - Google OAuth and API key support
  • FastMCP 2.13.0+ framework for production-ready deployment
  • LangGraph CLI API integration
  • 6 Tools: invoke_agent, stream_agent, check_system_health, check_agent_status, get_thread_state, list_threads
  • 2 Resources: Agent health check and server info
  • Prompts: Formatted agent queries
  • Web Test UI: Interactive testing interface on port 3005
  • Secure by Default: Optional authentication for production deployments

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment (optional):
# Copy example configuration
cp .env.example .env

# Edit .env with your settings
# For development without auth:
OAUTH_ENABLED=false

# For production with auth:
OAUTH_ENABLED=true
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
API_KEYS=your-api-key-1,your-api-key-2
  1. Generate credentials (if using OAuth):
python generate_credentials.py

See OAUTH_SETUP.md for detailed authentication setup.

Usage

Option 1: Quick Start Script (Recommended)

./start.sh

Option 2: Manual Start

Start MCP Server:

python src/agent_mcp/mcp_server.py

Start Test UI (optional):

cd web_ui && python server.py

Option 3: Using FastMCP CLI

python -m agent_mcp.mcp_server

Or using FastMCP CLI:

fastmcp run src/agent_mcp/mcp_server.py

For local development (STDIO):

fastmcp dev src/agent_mcp/mcp_server.py

Custom transport:

from agent_mcp.mcp_server import mcp

# HTTP transport
mcp.run(transport="http", host="0.0.0.0", port=8000, path="/mcp")

# SSE transport (for ChatGPT Enterprise)
mcp.run(transport="sse", host="0.0.0.0", port=8000)

Available Tools

1. invoke_agent

Execute a single invocation of the LangGraph agent.

{
    "prompt": "What is the capital of France?",
    "thread_id": "optional-thread-id"
}

2. stream_agent

Stream responses from the LangGraph agent.

{
    "prompt": "Tell me a story",
    "thread_id": "optional-thread-id"
}

3. get_agent_state

Retrieve the current state of a conversation thread.

{
    "thread_id": "thread-id-to-query"
}

Authentication

The MCP server supports three authentication methods for production deployments:

1. OAuth 2.0 (Google or Okta)

Enable user-based authentication with your preferred identity provider:

Google OAuth:

# .env configuration
OAUTH_ENABLED=true
OAUTH_PROVIDER=google
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret

Okta OAuth:

# .env configuration
OAUTH_ENABLED=true
OAUTH_PROVIDER=okta
OKTA_DOMAIN=your-domain.okta.com
OKTA_CLIENT_ID=your-okta-client-id
OKTA_CLIENT_SECRET=your-okta-client-secret

OAuth Endpoints:

  • GET /auth/login - Initiate OAuth flow
  • GET /auth/callback - OAuth callback handler
  • GET /auth/logout - Logout
  • GET /auth/status - Check authentication status

Quick Start Guides:

2. API Key Authentication

Use API keys for service-to-service authentication:

# Generate API keys
python generate_credentials.py

# Add to .env
API_KEYS=key1,key2,key3

Using API Keys:

# cURL
curl -H "X-API-Key: your-api-key" http://localhost:8000/sse

# Python
headers = {"X-API-Key": "your-api-key"}

Testing Authentication

# Test OAuth setup
python test_oauth.py

# Or test manually
curl http://localhost:8000/health  # Public endpoint
curl -H "X-API-Key: your-key" http://localhost:8000/sse  # Protected

For detailed setup instructions, see OAUTH_SETUP.md

Resources

  • agent://health - Agent health check
  • agent://info - Agent capabilities and metadata

Prompts

  • agent_query_prompt - Format queries for the agent

ChatGPT Enterprise Integration

This server is designed for ChatGPT Enterprise integration with:

  1. SSE Transport: Default transport for real-time streaming
  2. MCP Protocol 2025-06-18: Latest stable protocol version
  3. Proper Tool Schemas: Auto-generated from Python type hints
  4. Context Support: Logging and progress reporting
  5. Error Handling: Comprehensive error responses

ChatGPT Configuration

Add to your ChatGPT Enterprise MCP configuration:

{
  "mcpServers": {
    "langgraph-agent": {
      "url": "http://your-server:8000/sse",
      "transport": "sse"
    }
  }
}

Testing

Web UI Test Tool

We provide a beautiful web-based UI to test your MCP server and LangGraph agent:

# Start the test UI server
cd web_ui
python server.py

Then open http://localhost:3005 in your browser to:

  • Test MCP server connectivity
  • Test LangGraph agent connectivity
  • Invoke agent with custom prompts
  • Stream responses in real-time
  • View activity logs

See web_ui/README.md for details.

Unit Tests

Run tests:

pytest tests/test_mcp_server.py -v

Run all tests:

pytest

Development

Project Structure

agent-mcp-py/
├── src/
│   └── agent_mcp/
│       ├── __init__.py
│       └── mcp_server.py      # FastMCP server implementation
├── tests/
│   ├── test_mcp_server.py     # MCP server tests
│   └── test_*.py              # Other tests
├── requirements.txt           # Production dependencies
├── requirements-dev.txt       # Development dependencies
└── README.md

Adding New Tools

from fastmcp import Context

@mcp.tool()
async def my_tool(param: str, ctx: Context = None) -> dict:
    """Tool description for ChatGPT."""
    if ctx:
        await ctx.info(f"Processing: {param}")

    # Your logic here
    return {"result": "success"}

Adding Resources

@mcp.resource("custom://resource")
async def my_resource() -> str:
    """Resource description."""
    return "Resource content"

Architecture

┌─────────────────┐
│  ChatGPT        │
│  Enterprise     │
└────────┬────────┘
         │ MCP/SSE
         │
┌────────▼────────┐
│  FastMCP        │
│  Server         │
│  (Port 8000)    │
└────────┬────────┘
         │ HTTP
         │
┌────────▼────────┐
│  LangGraph      │
│  Agent          │
│  (Port 2024)    │
└─────────────────┘

Production Deployment

With Authentication

from fastmcp.server.auth.providers.google import GoogleProvider

auth = GoogleProvider(
    client_id="your-client-id",
    client_secret="your-client-secret",
    base_url="https://your-domain.com"
)

mcp = FastMCP(
    "LangGraph Agent Server",
    auth=auth
)

Docker Deployment

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY src/ ./src/
CMD ["python", "-m", "agent_mcp.mcp_server"]

License

MIT

References

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选