File tree Expand file tree Collapse file tree 6 files changed +136
-5
lines changed
Expand file tree Collapse file tree 6 files changed +136
-5
lines changed Original file line number Diff line number Diff line change 11{
2- "name" : " muppet -hono" ,
2+ "name" : " with -hono-mcp " ,
33 "version" : " 0.0.1" ,
44 "bin" : " ./dist/index.js" ,
55 "scripts" : {
1616 "@types/node" : " ^22.13.10" ,
1717 "typescript" : " ^5.8.2"
1818 }
19- }
19+ }
Original file line number Diff line number Diff line change 1+ # Muppet SSE Example with Hono on Bun
2+
3+ This example shows how to use the Muppet with SSE transport on Hono. We are using ` SSEHonoTransport ` transport layer from ` muppet/streaming ` to connect.
4+
5+ This can be used with all the runtimes which supports Streaming with hono. More details about that here - < https://hono.dev/docs/helpers/streaming >
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " with-streaming" ,
3+ "version" : " 0.0.1" ,
4+ "bin" : " ./dist/index.js" ,
5+ "scripts" : {
6+ "dev" : " bun run --hot ./src/index.ts"
7+ },
8+ "dependencies" : {
9+ "@modelcontextprotocol/sdk" : " ^1.15.0" ,
10+ "fetch-to-node" : " ^2.1.0" ,
11+ "hono" : " ^4.7.4" ,
12+ "muppet" : " workspace:*" ,
13+ "zod" : " ^3.24.2"
14+ },
15+ "devDependencies" : {
16+ "@types/node" : " ^22.13.10" ,
17+ "typescript" : " ^5.8.2"
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js" ;
2+ import { toFetchResponse , toReqRes } from "fetch-to-node" ;
3+ import { Hono } from "hono" ;
4+ import { Muppet } from "muppet" ;
5+ import { z } from "zod" ;
6+
7+ const mcp = new Muppet < { Variables : { surname : string } } > ( {
8+ name : "muppet-hono" ,
9+ version : "0.0.1" ,
10+ } ) ;
11+
12+ mcp . tool (
13+ {
14+ name : "hello" ,
15+ description : "Say hello" ,
16+ inputSchema : z . object ( {
17+ name : z . string ( ) ,
18+ } ) ,
19+ } ,
20+ ( c ) => {
21+ const name = c . message . params . arguments . name ;
22+ return {
23+ content : [
24+ {
25+ type : "text" ,
26+ text : `Hello ${ name } !` ,
27+ } ,
28+ ] ,
29+ } ;
30+ } ,
31+ ) ;
32+
33+ const app = new Hono ( ) ;
34+
35+ app . all ( "/mcp" , async ( c ) => {
36+ const transport = new StreamableHTTPServerTransport ( {
37+ sessionIdGenerator : undefined ,
38+ } ) ;
39+ await mcp . connect ( transport ) ;
40+
41+ const { req, res } = toReqRes ( c . req . raw ) ;
42+ await transport . handleRequest ( req , res ) ;
43+ return toFetchResponse ( res ) ;
44+ } ) ;
45+
46+ app . get ( "/" , ( c ) => c . text ( "Hello World" ) ) ;
47+
48+ export default app ;
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "target" : " ESNext" ,
4+ "lib" : [" ESNext" , " DOM" ],
5+ "moduleDetection" : " force" ,
6+ "useDefineForClassFields" : false ,
7+ "experimentalDecorators" : true ,
8+ "module" : " ESNext" ,
9+ "moduleResolution" : " bundler" ,
10+ "resolveJsonModule" : true ,
11+ "allowJs" : true ,
12+ "strict" : true ,
13+ "noFallthroughCasesInSwitch" : true ,
14+ "noImplicitOverride" : true ,
15+ "noImplicitReturns" : true ,
16+ "noUnusedLocals" : true ,
17+ "noImplicitAny" : true ,
18+ "noUnusedParameters" : true ,
19+ "declaration" : false ,
20+ "noEmit" : true ,
21+ "outDir" : " dist/" ,
22+ "sourceMap" : true ,
23+ "esModuleInterop" : true ,
24+ "forceConsistentCasingInFileNames" : true ,
25+ "isolatedModules" : true ,
26+ "verbatimModuleSyntax" : true ,
27+ "skipLibCheck" : true
28+ },
29+ "include" : [" ./src/**/*" ]
30+ }
You can’t perform that action at this time.
0 commit comments