Skip to main content

Overview

The MCP SSE (Server-Sent Events) Transport module provides real-time communication between PraisonAI agents and MCP servers using Server-Sent Events. This transport layer enables agents to use tools from MCP servers that communicate via SSE instead of stdio.

Architecture

Components

Quick Start

1
Install praisonaiagents
2
Create MCP client with SSE transport
3
Use MCP tools with agents

Core Classes

SSEMCPClient

The main client class for connecting to SSE-based MCP servers.

Key Methods

connect()
discover_tools()
invoke_tool()

SSEMCPTool

Wrapper class that makes MCP tools compatible with PraisonAI agents.

Usage Examples

Basic SSE Connection

Authenticated Connection

Custom Event Handling

Streaming Responses

Event Flow

Connection Lifecycle

1
Initialize Connection
  • Client creates HTTP connection to SSE endpoint
  • Establishes persistent event stream
2
Discover Tools
  • Client sends discovery request
  • Server responds with available tools and schemas
3
Event Processing
  • Client listens for server-sent events
  • Events processed asynchronously in background
4
Tool Invocation
  • Agent calls tool through wrapper
  • Request sent via SSE connection
  • Response streamed back via events

Tool Invocation

Configuration

MCP Class with SSE

Environment Variables

Error Handling

Connection Errors

Tool Invocation Errors

Best Practices

Connection Management

  • Use connection pooling for multiple agents
  • Implement retry logic for transient failures
  • Set appropriate timeouts for your use case
  • Close connections gracefully when done

Event Processing

  • Process events asynchronously to avoid blocking
  • Implement proper error handling in event handlers
  • Use event filtering to reduce processing overhead
  • Log important events for debugging

Performance

  • Reuse MCP client instances across agents
  • Batch tool invocations when possible
  • Monitor memory usage with long-running connections
  • Implement circuit breakers for unreliable servers

Security

  • Always use HTTPS in production
  • Rotate API keys regularly
  • Validate server certificates
  • Implement request signing if required

Advanced Topics

Custom Transport Implementation

Event Stream Processing

Monitoring and Metrics

Troubleshooting

Common Issues:

Debug Mode

Enable debug logging to troubleshoot issues:

Summary

The SSE Transport module enables: Real-time Communication - Stream events and responses via SSE
Async Operations - Non-blocking tool invocations
Automatic Validation - Pydantic-based input validation
Event Handling - Process streaming data and progress updates
Easy Integration - Drop-in replacement for stdio transport
Perfect for:
  • Real-time streaming applications
  • Long-running tool operations
  • Progress tracking and updates
  • Distributed MCP server deployments