Cover image
Try Now
2025-04-07

3 years

Works with Finder

1

Github Watches

0

Github Forks

3

Github Stars

MCP Server transport for Hono applications

Overview

This project provides a transport for Hono application that needs to connect to MCP Server. An official TypeScript SDK is designed to be used with express. If you try and follow their instructions but change express with hono, you will find that it's not going to work. Even if you set HttpBinding as an env (see an example from @hono/node-server), it still doesn't work as some headers are being added to a response after it's sent.

This implementation is inspired by the following pull request

You can use this transport until there is a proper support for Hono in the official SDK.

Getting started

Installation

pnpm add -D hono-mcp-server-sse-transport

Usage

import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import { streamSSE } from 'hono/streaming';
import { SSETransport } from 'hono-mcp-server-sse-transport';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

const mcpServer = new McpServer(
  {
    name: 'your-mcp-server-name',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
    },
  },
);

// here you add your tools
// ...

const app = new Hono();

// to support multiple simultaneous connections we have a lookup object from
// sessionId to transport
const transports: { [sessionId: string]: SSETransport } = {};

app.get('/sse', (c) => {
  return streamSSE(c, async (stream) => {
    const transport = new SSETransport('/messages', stream);

    transports[transport.sessionId] = transport;

    stream.onAbort(() => {
      delete transports[transport.sessionId];
    });

    await mcpServer.connect(transport);

    while (true) {
      // This will keep the connection alive
      // You can also await for a promise that never resolves
      await stream.sleep(60_000);
    }
  });
});

app.post('/messages', async (c) => {
  const sessionId = c.req.query('sessionId');
  const transport = transports[sessionId];

  if (transport == null) {
    return c.text('No transport found for sessionId', 400);
  }

  return transport.handlePostMessage(c);
});

serve(
  {
    fetch: app.fetch,
    port: 3000,
  },
);

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • 林乔安妮
  • A fashion stylist GPT offering outfit suggestions for various scenarios.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • GeyserMC
  • 与Minecraft客户端/服务器通信的库。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • awslabs
  • AWS MCP服务器 - 将AWS最佳实践直接带入您的开发工作流程的专门MCP服务器

  • modelcontextprotocol
  • 模型上下文协议服务器

    Reviews

    5 (1)
    Avatar
    user_lcnlOMKT
    2025-04-17

    As a dedicated user of Hono MCP applications, I am thoroughly impressed with the hono-mcp-server-sse-transport by NikaBuligini. The seamless integration and efficient server-sent events transport enhance the overall performance and reliability. It has truly transformed the way we handle real-time data communication. Highly recommend checking it out!