Cover image
Try Now
2025-04-01

Langchain -Agent mit MCP -Servern: Verwenden von Langchain -MCP -Adaptern zur Integration von Tools.

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

LangChain Agent with MCP Servers

A LangChain agent using MCP Adapters for tool integration with Model Context Protocol (MCP) servers.

Overview

This project demonstrates how to build a LangChain agent that uses the Model Context Protocol (MCP) to interact with various services:

  • Tavily Search: Web search and news search capabilities
  • Weather: Mock weather information retrieval
  • Math: Mathematical expression evaluation

The agent uses LangGraph's ReAct agent pattern to dynamically select and use these tools based on user queries.

Features

  • Graceful Shutdown: All MCP servers implement proper signal handling for clean termination
  • Subprocess Management: The main agent tracks and manages all MCP server subprocesses
  • Error Handling: Robust error handling throughout the application
  • Modular Design: Easy to extend with additional MCP servers

Graceful Shutdown Mechanism

This project implements a comprehensive graceful shutdown system:

  1. Signal Handling: Captures SIGINT and SIGTERM signals to initiate graceful shutdown
  2. Process Tracking: The main agent maintains a registry of all child processes
  3. Cleanup Process: Ensures all subprocesses are properly terminated on exit
  4. Shutdown Flags: Each MCP server has a shutdown flag to prevent new operations when shutdown is initiated
  5. Async Cooperation: Uses asyncio to allow operations in progress to complete when possible

Installation

# Clone the repository
git clone https://github.com/yourusername/langchain-mcp.git
cd langchain-mcp

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .

Configuration

Create a .env file in the project root with the following variables:

OPENAI_API_KEY=your_openai_api_key
TAVILY_API_KEY=your_tavily_api_key

Usage

Run the agent from the command line:

python src/agent.py

The agent will prompt for your query and then process it using the appropriate tools.

Development

To add a new MCP server:

  1. Create a new file in src/mcpserver/
  2. Implement the server with proper signal handling
  3. Update src/mcpserver/__init__.py to expose the new server
  4. Add the server configuration to src/agent.py

License

MIT

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • apappascs
  • Entdecken Sie die umfassendste und aktuellste Sammlung von MCP-Servern auf dem Markt. Dieses Repository dient als zentraler Hub und bietet einen umfangreichen Katalog von Open-Source- und Proprietary MCP-Servern mit Funktionen, Dokumentationslinks und Mitwirkenden.

  • jae-jae
  • MCP -Server für den Fetch -Webseiteninhalt mit dem Headless -Browser von Dramatikern.

  • HiveNexus
  • Ein KI-Chat-Bot für kleine und mittelgroße Teams, die Modelle wie Deepseek, Open AI, Claude und Gemini unterstützt. 专为中小团队设计的 ai 聊天应用 , 支持 Deepseek 、 Open ai 、 claude 、 Gemini 等模型。

  • ravitemer
  • Ein leistungsstarkes Neovim -Plugin für die Verwaltung von MCP -Servern (Modellkontextprotokoll)

  • patruff
  • Brücke zwischen Ollama und MCP -Servern und ermöglicht es lokalen LLMs, Modellkontextprotokoll -Tools zu verwenden

    Reviews

    4 (1)
    Avatar
    user_4EuXQgMW
    2025-04-16

    As an avid user, I must say MCP_Server_Spotify by Hashim9184 is phenomenal. The integration with Spotify is seamless, making music streaming delightful. The server's performance and reliability are top-notch, ensuring an uninterrupted musical experience. Highly recommend checking it out: https://mcp.so/server/MCP_Server_Spotify/Hashim9184.