-
Notifications
You must be signed in to change notification settings - Fork 346
feat: Add Multi-Instance Support via Custom Channel Builders #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add Multi-Instance Support via Custom Channel Builders #186
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
currently working on tweaks to the tests |
## Overview This PR adds support for running multiple SSE server instances with shared state. It introduces a flexible, technology-agnostic approach using channel builders that allow for distributed message delivery across server instances. ## Key Features - **Custom Event Queue Builders**: Allow customizing how server-sent events are distributed across instances - **Custom Notification Channel Builders**: Support distributed notification delivery - **Redis Implementation**: Provides a ready-to-use implementation using Redis pub/sub - **No Core Dependencies**: Maintains zero external dependencies in the core library - **Comprehensive Tests**: Includes tests using a mock broker to verify functionality ## Technical Approach Rather than tightly coupling the library to a specific technology (like Redis), this PR introduces builder functions that can create custom communication channels: ```go // Create a multi-instance SSE server using Redis sseServer := server.NewSSEServer( mcpServer, server.WithBaseURL("https://api.example.com"), server.NewRedisEventQueueBuilder(redisClient), server.NewRedisNotificationChannelBuilder(redisClient), ) ``` This approach has several advantages: - Users can implement different message broker solutions (Redis, RabbitMQ, SQS, etc.) - The core library remains focused and dependency-free - Testing is simplified using mock implementations ## Implementation Notes - Channel builders are executed once per SSE session - The Redis implementation uses pub/sub for real-time message delivery - Communication channels are bidirectional for both producing and consuming messages - Tests use a mock broker to verify multi-instance behavior without external dependencies ## Example Usage ```go import ( "github.com/go-redis/redis/v8" "github.com/mark3labs/mcp-go/server" ) func createMultiInstanceServer() *server.SSEServer { // Connect to Redis redisClient := redis.NewClient(&redis.Options{ Addr: "redis:6379", }) // Create MCP server mcpServer := server.NewMCPServer( "my-app", "1.0.0", server.WithToolCapabilities(true), ) // Create SSE server with Redis-backed channels return server.NewSSEServer( mcpServer, server.WithBaseURL("https://api.example.com"), server.NewRedisEventQueueBuilder(redisClient), server.NewRedisNotificationChannelBuilder(redisClient), ) } ``` This solution enables horizontally scaling SSE servers while maintaining session consistency across instances.
2faa151
to
aa44ce7
Compare
Overview
This PR adds support for running multiple SSE server instances with shared state. It introduces a flexible, technology-agnostic approach using channel builders that allow for distributed message delivery across server instances.
Key Features
Technical Approach
Rather than tightly coupling the library to a specific technology (like Redis), this PR introduces builder functions that can create custom communication channels:
This approach has several advantages:
Implementation Notes
Example Usage
This solution enables horizontally scaling SSE servers while maintaining session consistency across instances.