Skip to content

langchain-samples/agent-builder-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LangGraph Agent Builder with MCP

A LangGraph-based project that deploys AI agents as both a streaming API and MCP (Model Context Protocol) tools.

Overview

This project contains two LangGraph agents:

  • Summarizer: Takes text input and returns a concise summary
  • Search: Web search agent that answers questions using Tavily API

Agents are exposed via:

  1. LangGraph streaming API (/assistants, /threads, /runs)
  2. MCP JSON-RPC protocol (/mcp/)

Prerequisites

  • Python 3.9+
  • OpenAI API key
  • Tavily API key (for search agent)

Setup

  1. Clone the repository and navigate to the project directory

  2. Create and activate virtual environment:

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create .env file with your API keys:
OPENAI_API_KEY=your_openai_key
TAVILY_API_KEY=your_tavily_key

Running the Server

Start the LangGraph development server:

langgraph dev --no-browser

The server runs on http://127.0.0.1:2024 by default.

To run in the background:

langgraph dev --no-browser &

Testing

Ensure the server is up and running in the background first.

Test Agents via Streaming API

Test both agents with their streaming API endpoints:

python client/test_agents.py --test-all

Individual tests:

python client/test_agents.py --test-summarizer
python client/test_agents.py --test-search
python client/test_agents.py --list  # List available assistants

Test MCP Protocol

Test agents exposed as MCP tools:

python client/test_mcp.py --all

Individual test suites:

python client/test_mcp.py --json-rpc     # Test MCP JSON-RPC methods
python client/test_mcp.py --openapi      # Fetch OpenAPI spec
python client/test_mcp.py --endpoints    # Test endpoint patterns
python client/test_mcp.py --assistants   # Test assistants API

Configuration

Environment Variables

  • LANGGRAPH_BASE_URL: API endpoint (default: http://127.0.0.1:2024)
  • LANGSMITH_API_KEY: API key for authentication (optional for local dev)
  • OPENAI_API_KEY: OpenAI API key (required)
  • TAVILY_API_KEY: Tavily API key (required for search agent)

Command Line Options

Both test scripts support custom base URLs:

python client/test_agents.py --base-url https://your-deployment-url
python client/test_mcp.py --base-url https://your-deployment-url

Project Structure

.
├── agents/
│   ├── search.py          # Web search agent
│   └── summarize.py       # Text summarization agent
├── client/
│   ├── test_agents.py     # Test streaming API
│   └── test_mcp.py        # Test MCP protocol
├── langgraph.json         # LangGraph configuration
├── requirements.txt       # Python dependencies
└── .env                   # Environment variables (create this)

API Endpoints

Streaming API

  • POST /assistants/search - List available assistants
  • POST /threads - Create a new thread
  • POST /threads/{thread_id}/runs/stream - Stream agent execution

MCP Protocol

  • POST /mcp/ - JSON-RPC 2.0 endpoint
    • initialize - Initialize MCP session
    • tools/list - List available tools
    • tools/call - Invoke a tool
    • resources/list - List resources
    • prompts/list - List prompts

About

No description or website provided.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages