You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/examples/mcp_example/README.md

1.1 KiB

MCP Integration Documentation

Overview

This implementation connects an agent with a Math Server using the Model Context Protocol (MCP). The system consists of:

  1. Math Server (math_server.py) - Handles mathematical calculations
  2. Test Integration (test_integration.py) - Client that connects to the math server

Key Components

Math Agent Setup

math_server = MCPServerSseParams(
    url="http://0.0.0.0:6274",
    headers={"Content-Type": "application/json"},
)

math_agent = Agent(
    agent_name="Math-Agent",
    system_prompt="You are a math assistant. Process mathematical operations.",
    max_loops=1,
    mcp_servers=[math_server]
)

Task Flow

  1. User inputs a math operation
  2. Math agent processes the request
  3. Request is sent to math server via MCP
  4. Result is returned through the agent

Testing

Run the integration test:

python examples/mcp_example/math_server.py  # Start server
python examples/mcp_example/test_integration.py  # Run client

Implementation Notes

  • Server runs on port 6274
  • Uses SSE (Server-Sent Events) for transport
  • Handles basic math operations (add, subtract, multiply, divide)