Skip to content

Commit 168a6b6

Browse files
MathurAditya724yusukebeautofix-ci[bot]
authored
feat(mcp): hono/mcp v0.2 (#1318)
* chore: renamed files * chore: corrected the imports * feat: updated the streamable transport class * chore: corrected the test * chore: formated the code * chore: basic stuff * chore: minor changes * chore: more changes * chore: more changes * chore: minor changes * chore: completed test conversion * chore: formatted file * chore: corrected all the tests * chore: renamed the streamableHttp files * chore: added a new index file * wip * chore: minor changes * chore: minor changes * chore: resolved the type errors * chore: minor changes * feat: added sse transport * chore: updated the imports * chore: minor change * ci: apply automated fixes * add `pkce-challenge` to `devDependencies` * update deno.json to resolve the type issue * chore: renamed the files * chore: updated readme * ci: apply automated fixes * chore: added changeset * chore: updated lockfile * ci: apply automated fixes * chore: corrected the merge * chore: updated the tests for streamable htttp * chore: removed SSE * chore: removed console.log * chore: minor changes * chore: unref keepAlive timer to prevent server shutdown blocking * feat: added simple mcp auth router * chore: updated package.json * chore: minor changes * chore: minor changes * chore: minor changes * chore: resolved test issues * chore: minor change * chore: added deno ignore * chore: updated the build step * chore: minor change * chore: minor changes * chore: minor changes * chore: minor changes * chore: resolve the attw issue * chore: minor changes * chore: minor changes * chore: formatted code * chore: checking something * chore: updated the import to be not node specific * chore: minor changes * ci: apply automated fixes * feat: added memory store * chore: minor change * fix: using the new bearer auth middleware * fix: corrected lockfile * fix: corrected the tsdown config * fix: corrected hono version in deno.json * fix: added dynamic import for hono-rate-limiter * chore: shifted pkce-challenge to dep. --------- Co-authored-by: Yusuke Wada <yusuke@kamawada.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 0caca80 commit 168a6b6

35 files changed

+6115
-682
lines changed

.changeset/wild-doodles-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/mcp': minor
3+
---
4+
5+
Minor improvements and added support for Auth

packages/mcp/README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Hono MCP (Model Context Protocol)
22

3-
Connect Hono with a Model Context Protocol (MCP) server over HTTP Streaming Transport.
3+
Connect Hono to a Model Context Protocol (MCP) server over HTTP Streaming Transport.
44

5-
## Usage
5+
## Streamable HTTP Transport
66

77
```ts
88
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
@@ -17,15 +17,45 @@ const mcpServer = new McpServer({
1717
version: '1.0.0',
1818
})
1919

20+
// Initialize the transport
21+
const transport = new StreamableHTTPTransport()
22+
2023
app.all('/mcp', async (c) => {
21-
const transport = new StreamableHTTPTransport()
22-
await mcpServer.connect(transport)
24+
if (!mcp.isConnected()) {
25+
// Connect the mcp with the transport
26+
await mcp.connect(transport)
27+
}
28+
2329
return transport.handleRequest(c)
2430
})
2531

2632
export default app
2733
```
2834

35+
## Auth
36+
37+
The simplest way to setup MCP Auth when using 3rd party auth providers.
38+
39+
```ts
40+
import { Hono } from 'hono'
41+
import { simpleMcpAuthRouter } from '@hono/mcp'
42+
43+
const app = new Hono()
44+
45+
app.route(
46+
'/',
47+
simpleMcpAuthRouter({
48+
issuer: '[auth provider domain]',
49+
resourceServerUrl: new URL('http://localhost:3000/mcp'),
50+
})
51+
)
52+
53+
// ...
54+
// Logic to connect with the transport
55+
```
56+
57+
For implementing custom auth, check out the docs - <https://honohub.dev/docs/hono-mcp>
58+
2959
## Author
3060

3161
Aditya Mathur <https://github.com/mathuraditya724>

packages/mcp/deno.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "@hono/mcp",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"license": "MIT",
55
"exports": {
6-
".": "./src/index.ts"
6+
".": "./src/index.ts",
7+
"./auth": "./src/auth/index.ts"
78
},
89
"imports": {
9-
"hono": "jsr:@hono/hono@^4.8.3"
10+
"hono": "jsr:@hono/hono@^4.10.6",
11+
"hono-rate-limiter": "jsr:@hono-rate-limiter/hono-rate-limiter@^0.4.2"
1012
},
1113
"publish": {
1214
"include": ["deno.json", "README.md", "src/**/*.ts"],

packages/mcp/package.json

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hono/mcp",
3-
"version": "0.1.5",
3+
"version": "0.2.0",
44
"description": "MCP Middleware for Hono",
55
"type": "module",
66
"module": "dist/index.js",
@@ -16,13 +16,25 @@
1616
"test": "vitest"
1717
},
1818
"exports": {
19-
"import": {
20-
"types": "./dist/index.d.ts",
21-
"default": "./dist/index.js"
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.ts",
22+
"default": "./dist/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
2228
},
23-
"require": {
24-
"types": "./dist/index.d.cts",
25-
"default": "./dist/index.cjs"
29+
"./auth": {
30+
"import": {
31+
"types": "./dist/auth/index.d.ts",
32+
"default": "./dist/auth/index.js"
33+
},
34+
"require": {
35+
"types": "./dist/auth/index.d.cts",
36+
"default": "./dist/auth/index.cjs"
37+
}
2638
}
2739
},
2840
"license": "MIT",
@@ -35,14 +47,21 @@
3547
"url": "git+https://github.com/honojs/middleware.git",
3648
"directory": "packages/mcp"
3749
},
38-
"homepage": "https://github.com/honojs/middleware",
50+
"homepage": "https://honohub.dev/docs/hono-mcp",
51+
"dependencies": {
52+
"pkce-challenge": "^5.0.0"
53+
},
3954
"peerDependencies": {
40-
"@modelcontextprotocol/sdk": "^1.12.0",
41-
"hono": ">=4.0.0"
55+
"@modelcontextprotocol/sdk": "^1.17.3",
56+
"hono": "*",
57+
"hono-rate-limiter": "^0.4.2"
4258
},
4359
"devDependencies": {
60+
"@arethetypeswrong/cli": "^0.17.4",
4461
"@modelcontextprotocol/sdk": "^1.19.1",
45-
"hono": "^4.10.1",
62+
"@types/node": "^24.2.1",
63+
"hono": "^4.10.6",
64+
"hono-rate-limiter": "^0.4.2",
4665
"tsdown": "^0.15.9",
4766
"typescript": "^5.8.2",
4867
"vitest": "^3.2.4",

0 commit comments

Comments
 (0)