Skip to content

Siddendra/mcp-client-langgraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Client with LangGraph

A minimal Model Context Protocol (MCP) client built using LangGraph in Python.

This repository shows how to:

  • Build a conversational agent with LangGraph.
  • Connect that agent to external tools and data sources via MCP clients.
  • Experiment with synchronous, asynchronous, and MCP-driven chatbot flows.

MCP (Model Context Protocol) is an open standard for connecting AI applications to external tools and data sources, so LLMs can call tools, query systems, and act on real-world context. :contentReference[oaicite:0]{index=0}


📁 Repository Structure

mcp-client-langgraph/
├── chatbot.py          # Basic LangGraph chatbot example
├── chatbot_async.py    # Asynchronous LangGraph chatbot example
├── chatbot_mcp.py      # LangGraph chatbot wired to an MCP client
  • chatbot.py – simplest entry point to understand how a LangGraph-based chatbot is structured.
  • chatbot_async.py – demonstrates async usage (useful when integrating with external APIs/tools).
  • chatbot_mcp.py – the main example showing how to use LangGraph as an MCP client, connecting to MCP servers and invoking tools via the protocol.

🚀 Getting Started

1. Prerequisites

  • Python 3.10+

  • git

  • (Optional but recommended) A virtual environment tool:

    • venv / virtualenv / conda
  • One or more MCP servers running locally or remotely (for the MCP example).

You can explore public MCP servers and ecosystem docs via the official MCP resources and registries. ([Anthropic][1])


2. Clone the Repository

git clone https://github.com/campusx-official/mcp-client-langgraph.git
cd mcp-client-langgraph

3. Set Up a Virtual Environment (Optional but Recommended)

python -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows (PowerShell)
# .venv\Scripts\Activate.ps1

4. Install Dependencies

If a requirements.txt exists:

pip install -r requirements.txt

If not, you can install the core libraries typically needed for LangGraph + MCP work:

pip install langgraph openai mcp

⚠️ Adjust the dependencies based on what’s imported inside chatbot.py, chatbot_async.py, and chatbot_mcp.py.


💬 Usage

1. Run the Basic Chatbot

python chatbot.py

This example is usually the simplest place to start. It will:

  • Initialize a LangGraph graph.
  • Run a basic chat loop in the terminal.
  • Show how messages flow through the graph.

2. Run the Asynchronous Chatbot

python chatbot_async.py

Use this to:

  • Understand async patterns with LangGraph.
  • Integrate with non-blocking I/O (e.g., external HTTP tools, databases, etc.).

3. Run the MCP-Enabled Chatbot

python chatbot_mcp.py

This script demonstrates:

  • How to configure a LangGraph agent as an MCP client.
  • How to connect to MCP servers (tools, data sources, or workflows exposed via MCP).
  • How to call MCP tools from within a conversational flow.

Before running this, ensure that:

  • Your MCP server(s) are running and reachable.
  • Any required environment variables / config (e.g., server address, API keys) are set inside chatbot_mcp.py or via your shell.

⚙️ Configuration

Typical configuration options (check inside the Python files and tailor as needed):

  • Model configuration

    • OpenAI / Anthropic / other LLM provider keys via environment variables
    • Model name, temperature, max tokens, etc.
  • MCP connection details

    • MCP server URL / transport (e.g., stdio, http, etc.)
    • Tool names and resource IDs to be used by the agent

Common environment variables you may need:

export OPENAI_API_KEY="your-api-key"
export MCP_SERVER_URL="http://localhost:PORT"   # Example if using HTTP transport

Replace with the actual variables used in the code.


🧠 What is MCP (Model Context Protocol)?

MCP is an open standard that allows AI assistants to connect to external systems (files, databases, tools, APIs) through a common protocol. Think of it as a “USB-C for AI tools”—your LangGraph agent becomes an MCP client, and any MCP server you point it to becomes a pluggable capability. ([Model Context Protocol][2])

This repo’s chatbot_mcp.py file is a simple, practical example of that pattern.


🧪 Extending the Project

Here are some ideas to extend this repo:

  • Add custom MCP servers for:

    • Internal APIs
    • Databases
    • File systems / knowledge bases
  • Build a LangGraph workflow that:

    • Searches documents via MCP
    • Summarizes them
    • Performs actions (e.g., write back results, send notifications)
  • Integrate with UI frontends:

    • Stream responses to a web UI or CLI with streaming support.
  • Add tracing / logging:

    • Track MCP tool calls and LangGraph node execution.

About

mcp-client-langgraph

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages