MCP cover image
See in Github
2025-03-09

使用SDIO + SSE的MCP服务器的示例。还使用兰链MCP

1

Github Watches

1

Github Forks

0

Github Stars

MCP Multi-Server Demo with SSE Transport

This project demonstrates how to use the Model Context Protocol (MCP) with multiple servers using different transport methods (stdio and Server-Sent Events).

It is based on examples from: https://github.com/langchain-ai/langchain-mcp-adapters

Overview

The project consists of:

  1. A math server that provides basic arithmetic operations (add, multiply)
  2. A weather server that provides simulated weather information for different locations
  3. A main application that connects to both servers using the MultiServerMCPClient
  4. Integration with LangChain and OpenAI to create an agent that can use tools from both servers

Requirements

  • Python 3.8+
  • OpenAI API key

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/mcp-sse.git
    cd mcp-sse
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Set up your OpenAI API key in a .env file:

    OPENAI_API_KEY=your-api-key-here
    

Project Structure

  • main.py: The main application that connects to both servers and runs the agent
  • math_server.py: A simple MCP server that provides math operations using stdio transport
  • weather_server.py: A simple MCP server that provides weather information using SSE transport
  • requirements.txt: List of Python dependencies
  • .env: Environment variables (contains your OpenAI API key)

How It Works

The application demonstrates how to use the MultiServerMCPClient to connect to multiple MCP servers with different transport methods:

  1. The math server uses stdio transport, which is a simple pipe-based communication method
  2. The weather server uses Server-Sent Events (SSE) transport, which is an HTTP-based protocol for server-to-client push notifications

The main application:

  1. Starts the weather server as a separate process
  2. Connects to both servers using the MultiServerMCPClient
  3. Creates a LangChain agent that can use tools from both servers
  4. Demonstrates using the agent to perform math calculations and get weather information

Usage

Run the main application:

python main.py

This will:

  1. Start the weather server on port 8000
  2. Connect to both the math and weather servers
  3. Run the agent with example queries for both math and weather

Example Queries

The demo includes two example queries:

  1. Math query: "what's (3 + 5) x 12?"
  2. Weather query: "what is the weather in nyc?"

Extending the Project

You can extend this project by:

  1. Adding more tools to the math or weather servers
  2. Creating additional MCP servers with different functionality
  3. Modifying the agent to handle more complex queries
  4. Connecting to real weather APIs instead of using simulated data

License

MIT

Acknowledgments

相关推荐

  • 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.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

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

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

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

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

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

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

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

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

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • modelcontextprotocol
  • 模型上下文协议服务器

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

    Reviews

    2 (1)
    Avatar
    user_EjBU9T3o
    2025-04-15

    The CLI Integradora for Arcee, TESS, and MCP by diegofornalha is a must-have tool for MCP enthusiasts. It seamlessly integrates Arcee and TESS with MCP, making server management efficient and user-friendly. With robust functionality and intuitive design, it greatly enhances productivity. A highly recommended product!