-
Notifications
You must be signed in to change notification settings - Fork 26
feat(transport): Add new transport modes (Streamable HTTP & SSE) #33
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
Conversation
- Added support for HTTP transport in the MCP server, allowing communication via HTTP requests. - Introduced a new `HttpTransport` class that handles incoming requests and manages sessions. - Updated CLI options to include transport type selection, defaulting to stdio. - Enhanced environment schema to configure HTTP host and port. - Refactored the main server logic to utilize the selected transport type, improving flexibility in deployment. - Added a base transport class to standardize transport implementations.
- Introduced a `TransportManager` class to manage multiple transport types (HTTP, SSE, STDIO) for the MCP server. - Updated CLI options to allow selection of multiple transport types, improving flexibility in deployment. - Refactored the `HttpTransport` and added a new `SseTransport` class for handling Server-Sent Events. - Enhanced environment variable loading and error handling in the CLI. - Removed the obsolete `BaseTransport` class and factory pattern, simplifying transport management. - Updated package dependencies to include `@fastify/swagger` and `@fastify/swagger-ui` for API documentation. - Improved logging configuration to default to debug level for better traceability.
…ection management - Updated the HttpServer class to include a custom logger instance for improved logging capabilities. - Configured the server to force close ongoing connections, enhancing resource management during shutdowns. - Refactored the server initialization to accommodate the new logging setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the MCP Server by introducing support for multiple transport modes (HTTP, SSE, and STDIO), along with corresponding CLI, environment, and logging improvements. Key changes include:
- Addition of new transport types and implementations for HTTP (streamable), SSE, and STDIO.
- Introduction of a TransportManager to dynamically initialize and manage these transports.
- Updates to CLI options, environment schemas, and logging configuration.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/mcp/transports/types.ts | Introduces transport types and shared interfaces for the transports. |
src/mcp/transports/stdio.ts | Implements the STDIO transport. |
src/mcp/transports/sse.ts | Implements the SSE transport endpoints and session management. |
src/mcp/transports/http.ts | Implements the streamable HTTP transport with session handling. |
src/mcp/transports/server.ts | Sets up an HTTP server with Swagger documentation. |
src/mcp/transports/manager.ts | Provides lifecycle management for starting/stopping transports. |
src/cli.ts | Updates CLI parsing to accept comma-separated transport types. |
src/env-schema.ts | Adds HTTP transport configuration to the environment schema. |
src/logger.ts | Changes default logging level from info to debug. |
src/index.ts | Initializes the TransportManager and updates tool handler invocations. |
package.json | Adds npm scripts for starting the server with different transport modes. |
Object.values(this.sessions).forEach((transport) => { | ||
const sessionId = transport.sessionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'this.sessions' variable is a Map, so using Object.values() may not iterate over the stored transports as expected. Consider using 'this.sessions.forEach((transport, sessionId) => { ... })' or iterating over 'this.sessions.values()' for correct behavior.
Object.values(this.sessions).forEach((transport) => { | |
const sessionId = transport.sessionId; | |
this.sessions.forEach((transport, sessionId) => { |
Copilot uses AI. Check for mistakes.
src/confluent/helpers.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifications of this file were necessary to help remove typing errors now that we've introduced a number type to our env-schema.
Prevents issues when accessing env.*
when our client args would expect a string
type and not a string | number
// Useful for when ongoing http/sse connections are present | ||
forceCloseConnections: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not sure if this is better or if it's better for us to modify keep alive time
…orts before disconnecting clients
This pull request introduces enhancements to the CLI, transport system, and overall server architecture, enabling support for multiple transport protocols (HTTP, SSE, and Stdio) and improving configurability and error handling. The changes also include updates to the logging level, environment schema, and tool handler interfaces.
CLI and Environment Configuration Enhancements:
--transport
) with validation and parsing logic for multiple transport protocols (src/cli.ts
).HTTP_PORT
andHTTP_HOST
) with default values.Transport System Overhaul:
TransportManager
to manage multiple transport protocols (HTTP, SSE, Stdio) with start/stop lifecycle management (src/mcp/transports/manager.ts
).HttpTransport
to handle HTTP-based MCP sessions, including POST, GET, and DELETE endpoints for session management (src/mcp/transports/http.ts
).index.ts
to initialize and manage transports dynamically based on CLI options and environment variables.Tool Handler Improvements:
sessionId
parameter for session-specific operations, improving flexibility for tools like Kafka message consumption.Logging and Debugging:
info
todebug
to provide more detailed runtime information.Dependency and Build Updates:
@fastify/swagger
,@fastify/swagger-ui
, andfastify
dependencies to support HTTP transport and API documentation (package.json
).start:http
,start:sse
,start:all
,help
) to facilitate transport-specific server startups.Testing
Tested using https://github.com/modelcontextprotocol/inspector (for streamable http & sse) and goose cli (sse). Not all clients support streamable http mode yet.