hono-mcp-server-sse-transport
by NikaBuligini
This project provides a transport for Hono applications that need to connect to MCP Server using Server-Sent Events (SSE). It offers a workaround for using the official TypeScript SDK with Hono until proper Hono support is available.
Last updated: N/A
What is hono-mcp-server-sse-transport?
This is a transport layer that enables Hono applications to communicate with an MCP (Model Context Protocol) Server using Server-Sent Events (SSE). It bridges the gap between the official MCP Server TypeScript SDK (designed for Express) and the Hono web framework.
How to use hono-mcp-server-sse-transport?
- Install the package using
pnpm add -D hono-mcp-server-sse-transport
. 2. Import theSSETransport
class. 3. Create a Hono app and define an SSE endpoint (/sse
). 4. InstantiateSSETransport
within the SSE stream. 5. Connect to the MCP Server usingmcpServer.connect(transport)
. 6. Implement a/messages
endpoint to handle POST requests from the MCP Server.
Key features of hono-mcp-server-sse-transport
SSE transport for Hono applications
Compatibility with MCP Server
Workaround for official SDK limitations
Handles multiple simultaneous connections
Keeps connection alive with a periodic sleep
Use cases of hono-mcp-server-sse-transport
Connecting Hono-based applications to MCP Servers
Implementing real-time communication between Hono and MCP Server
Building applications that leverage the Model Context Protocol with Hono
Providing a temporary solution until official Hono support is added to the MCP Server SDK
FAQ from hono-mcp-server-sse-transport
Why do I need this transport?
Why do I need this transport?
The official MCP Server TypeScript SDK is designed for Express, and it doesn't work directly with Hono due to header handling issues.
How does this transport work?
How does this transport work?
It uses Server-Sent Events (SSE) to establish a persistent connection between the Hono application and the MCP Server.
What is the role of the /messages
endpoint?
What is the role of the /messages
endpoint?
It handles POST requests sent from the MCP Server to the Hono application through the SSE transport.
How do I handle multiple simultaneous connections?
How do I handle multiple simultaneous connections?
The example code uses a lookup object (transports
) to store and retrieve SSETransport
instances based on a session ID.
How do I keep the SSE connection alive?
How do I keep the SSE connection alive?
The example code includes a stream.sleep(60_000)
call within the SSE stream to prevent the connection from closing due to inactivity.