Skip to content

sunse-kwon/langchain-mcp-adapters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Crash Course

A tutorial project demonstrating how to integrate MCP (Model Context Protocol) servers with LangChain and LangGraph.

Overview

This project connects multiple MCP servers and uses LangChain's ReAct agent to automatically select and use the appropriate tools based on user questions.

Features

  • Math Server: Mathematical operation tools (addition, multiplication)
  • Weather Server: Weather information lookup tool
  • Multi-Server Client: Connect and manage multiple MCP servers simultaneously
  • ReAct Agent: Automatically select appropriate tools based on questions

Installation

  1. Python 3.11 or higher is required.

  2. Install dependencies:

uv sync

Or if using pip:

pip install -r requirements.txt

Setup

  1. Create a .env file and set your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
  1. Check the paths in main.py. Make sure the absolute path to math_server.py is correct.

Usage

1. Start the Weather Server

Run the weather server as a separate process in a terminal:

uv run python servers/weather_server.py

Or:

python servers/weather_server.py

This server will run on http://localhost:8000/sse.

2. Run the Main Program

In another terminal:

uv run python main.py

Or:

python main.py

Examples

  • Weather question: "what is the weather in nyc?"
  • Math question: "what is 5 + 3?" or "what is 10 * 7?"

You can modify the question in the last line of the main.py file.

Project Structure

mcp-crash-course/
├── main.py                 # Main execution file
├── langchain_client.py     # LangChain client setup (similar to main.py)
├── servers/
│   ├── math_server.py      # Math MCP server (stdio transport)
│   └── weather_server.py   # Weather MCP server (sse transport)
├── pyproject.toml          # Project dependencies
└── README.md               # This file

Tech Stack

Notes

  • The Math server uses stdio transport (process communication)
  • The Weather server uses SSE (Server-Sent Events) transport (HTTP-based)
  • The ReAct agent analyzes questions and automatically selects appropriate tools

About

tutorial multiple clients using multiple mcp server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages