MCP cover image
See in Github
2025-04-14

Un exemple de serveur Hono MCP utilisant HTTP Streamable

7

Github Watches

0

Github Forks

7

Github Stars

Stateless Hono MCP Server

An example Hono MCP server using Streamable HTTP, based off the official Express example, using fetch-to-node to convert, deployable to Cloudflare Workers (and anywhere else Hono runs).

The only real changes to the Express example are:

- import express, { Request, Response } from 'express';
+ import { Hono } from 'hono';
+ import { toFetchResponse, toReqRes } from 'fetch-to-node';

// ...

- const app = express();
- app.use(express.json());
+ const app = new Hono();

- app.post('/mcp', async (req: Request, res: Response) => {
+ app.post('/mcp', async (c) => {
+   const { req, res } = toReqRes(c.req.raw);

    const server = getServer();
    try {
      const transport: StreamableHTTPServerTransport = new StreamableHTTPServerTransport({
        sessionIdGenerator: undefined,
      });
      await server.connect(transport);
-     await transport.handleRequest(req, res, req.body);
+     await transport.handleRequest(req, res, await c.req.json());
      res.on('close', () => {
        console.log('Request closed');
        transport.close();
        server.close();
      });
+     return toFetchResponse(res);
    } catch (error) {

Testing with an example MCP client

In one terminal:

npm start

In another:

node node_modules/@modelcontextprotocol/sdk/dist/esm/examples/client/simpleStreamableHttp.js

This will try to connect to the MCP server running on port 3000. You can use connect <url>/mcp to connect to a different host or port.

Then you can run commands like list-prompts or list-tools to verify your MCP server is working.

Deploying

npm run deploy

Here's an example session against a Hono MCP server deployed on Cloudflare Workers:

> connect https://mcp-hono-stateless.michael.workers.dev/mcp
Connecting to https://mcp-hono-stateless.michael.workers.dev/mcp...
Transport created with session ID: undefined
Connected to MCP server

> list-tools
Available tools:
  - start-notification-stream: Starts sending periodic notifications for testing resumability

> list-prompts
Available prompts:
  - greeting-template: A simple greeting prompt template

> call-tool start-notification-stream
Calling tool 'start-notification-stream' with args: {}

Notification #1: info - Periodic notification #1 at 2025-04-22T16:20:50.178Z
>
Notification #2: info - Periodic notification #2 at 2025-04-22T16:20:50.278Z
>
Notification #3: info - Periodic notification #3 at 2025-04-22T16:20:50.378Z
>
Notification #4: info - Periodic notification #4 at 2025-04-22T16:20:50.478Z
>
Notification #5: info - Periodic notification #5 at 2025-04-22T16:20:50.578Z
>
Notification #6: info - Periodic notification #6 at 2025-04-22T16:20:50.678Z
>
Notification #7: info - Periodic notification #7 at 2025-04-22T16:20:50.778Z
>
Notification #8: info - Periodic notification #8 at 2025-04-22T16:20:50.878Z
>
Notification #9: info - Periodic notification #9 at 2025-04-22T16:20:50.978Z
>
Notification #10: info - Periodic notification #10 at 2025-04-22T16:20:51.078Z
> Tool result:
  Started sending periodic notifications every 100ms

相关推荐

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • Aurity Ltd
  • Create and Publish Business Websites in seconds. AI will gather all the details about your website and generate link to your website.

  • Convincible Ltd
  • You're in a stone cell – can you get out? A classic choose-your-adventure interactive fiction game, based on a meticulously-crafted playbook. With a medieval fantasy setting, infinite choices and outcomes, and dice!

  • John Rafferty
  • Text your favorite pet, after answering 10 questions about their everyday lives!

  • Ian O'Connell
  • Provide players' names or enter Quickstart to start the game!

  • analogchat.com
  • Efficient Spotify assistant for personalized music data.

  • seabiscuit.ai
  • Discover A More Robust Business: Craft tailored value proposition statements, develop a comprehensive business model canvas, conduct detailed PESTLE analysis, and gain strategic insights on enhancing business model elements like scalability, cost structure, and market competition strategies. (v1.18)

  • n8n-io
  • Plateforme d'automatisation de workflow à code équitable avec des capacités d'IA natives. Combinez le bâtiment visuel avec du code personnalisé, de l'auto-hôte ou du cloud, 400+ intégrations.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.

  • av
  • Exécutez sans effort LLM Backends, API, Frontends et Services avec une seule commande.

  • langgenius
  • Azure
  • Ce référentiel est pour le développement du serveur MCP Azure, apportant la puissance d'Azure à vos agents.

  • alibaba
  • 1Panel-dev
  • 🔥 1Panel fournit une interface Web intuitive et un serveur MCP pour gérer des sites Web, des fichiers, des conteneurs, des bases de données et des LLM sur un serveur Linux.

  • superiorlu
  • 🤖 Recueillir des référentiels, des outils, des sites Web, des articles et des tutoriels pratiques sur l'IA. 实用的 ai 百宝箱 💎

  • Byaidu
  • PDF Traduction de papier scientifique avec formats conservés - 基于 AI 完整保留排版的 PDF 文档全文双语翻译 , 支持 Google / Deepl / Olllama / Openai 等服务 , 提供 CLI / GUI / MCP / DOCKER / ZOTERO

  • caio-moliveira
  • Ce projet a été créé pour démontrer comment nous pouvons nous connecter avec différents protocoles de contexte de modèle (MCP).

  • rulego
  • ⛓️RULEGO est un cadre de moteur de règle d'orchestration des composants de nouvelle génération légère, intégrée, intégrée et de nouvelle génération pour GO.

  • Onelevenvy
  • Flock est une plate-forme à faible code de workflow pour construire rapidement des chatbots, un chiffon et coordonner des équipes multi-agents, alimentée par Langgraph, Langchain, Fastapi et NextJs. (Flock 是一个基于 Workflow 工作流的低代码平台 , 用于快速构建聊天机器人、 Rag 、 Agent 和 和 , 采用 采用 采用 采用 Langgraph 、 Langchain 、 Fastapi 和 ,))

    Reviews

    2.4 (8)
    Avatar
    user_XTswRNpC
    2025-04-23

    As a dedicated user of mcp applications, I must say that mcp-hono-stateless by mhart has exceeded my expectations. Its stateless nature makes it incredibly efficient and versatile for numerous applications. Easy to implement and integrate, highly recommend this for anyone looking for a reliable solution!

    Avatar
    user_vNDktz9n
    2025-04-23

    As an avid user of the mcp-hono-stateless application by mhart, I have to say it truly excels in performance and stability. It's incredibly efficient for managing stateless applications, making my work smoother and faster. The user-friendly interface and robust functionality have exceeded my expectations. A must-have for developers looking to optimize their workflow! Highly recommended!

    Avatar
    user_q36eE4vZ
    2025-04-23

    As a dedicated user of MCP applications, I find mcp-hono-stateless to be an outstanding tool. Created by mhart, it seamlessly integrates into my workflow, providing reliable and efficient stateless operations. This product has significantly enhanced my productivity, and I highly recommend it to anyone in need of robust and versatile solutions.

    Avatar
    user_PLCbuDL0
    2025-04-23

    I'm a big fan of the mcp-hono-stateless application. It is an incredible tool by mhart that has greatly simplified my workflow. The seamless and stateless design ensures consistent performance without the need for session handling. If you're looking for a reliable and efficient solution, I highly recommend giving this a try!

    Avatar
    user_Wy5C6kMg
    2025-04-23

    The mcp-hono-stateless by mhart is an outstanding tool for developers who need a reliable, stateless solution. It's incredibly user-friendly and integrates seamlessly into existing workflows. The documentation is clear, and the performance is top-notch. Highly recommend!

    Avatar
    user_44v6K789
    2025-04-23

    mcp-hono-stateless by mhart is an impressive product! It offers a seamless and efficient way to handle stateless operations. The user-friendly interface and excellent performance make it a top choice for developers who need reliable and scalable solutions. Highly recommended for anyone looking to optimize their workflow!

    Avatar
    user_PIoq6wAb
    2025-04-23

    As a loyal user of mcp-hono-stateless by mhart, I am thoroughly impressed with its seamless functionality. The tool's stateless design ensures efficient and scalable solutions for my projects, making development smooth and hassle-free. Highly recommend for anyone looking to enhance their workflow effortlessly!

    Avatar
    user_Qsf29ULj
    2025-04-23

    As a dedicated user of the mcp-hono-stateless, I can confidently say that this product developed by mhart is top-notch. Its stateless architecture ensures scalability and impressive performance. Highly recommend it for those seeking a reliable solution!