Repository navigation
feat(adapters): Hono adapter (#66) - #84
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
📝 WalkthroughWalkthroughAdds a new package ChangesHono Adapter for mcp-authkit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/adapter-hono/package.json`:
- Around line 41-50: Update the vulnerable package versions in package.json:
bump "`@hono/node-server`" from "1.19.0" to at least "1.19.13" (in
devDependencies) and bump "hono" from "4.0.0" to at least "4.12.18" (in both
peerDependencies and devDependencies), then reinstall/update the lockfile
(npm/yarn/pnpm) so the lockfile reflects the upgrades; target the dependency
entries for "`@hono/node-server`" and "hono" when making the changes.
In `@packages/adapter-hono/src/index.test.ts`:
- Line 216: The test uses the Node-22-only API Promise.withResolvers (const gate
= Promise.withResolvers<void>()); replace this with a Node-20-compatible manual
deferred: add a small helper deferred<T>() that constructs a Promise and
captures its resolve/reject (returning { promise, resolve, reject }), then
change the instantiation to const gate = deferred<void>(); update any uses of
the resolver to use gate.promise where the Promise was expected and call
gate.resolve()/gate.reject() where the test previously used the withResolvers
resolvers; reference symbols: Promise.withResolvers, gate, deferred, and replace
usages throughout the test.
In `@packages/adapter-hono/src/integration.test.ts`:
- Line 210: Replace the use of Promise.withResolvers for the test-level gate by
creating a manual promise with externally-captured resolve/reject functions:
instead of calling Promise.withResolvers() for the variable gate, create a new
Promise that assigns its resolve and reject to outer variables (or a small
helper createResolvable) and expose those functions alongside the promise so
existing test code that awaits gate or calls gate.resolve()/gate.reject()
continues to work; update any references to gate to use the promise object and
its captured resolve/reject functions (referencing the symbol gate and the
original Promise.withResolvers usage).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c128d233-db4f-4964-a5e6-4819dddcd948
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
packages/adapter-hono/README.mdpackages/adapter-hono/package.jsonpackages/adapter-hono/src/adapt.tspackages/adapter-hono/src/index.test.tspackages/adapter-hono/src/index.tspackages/adapter-hono/src/integration.test.tspackages/adapter-hono/tsconfig.jsonpackages/core/package.jsonpackages/core/src/adapters/hono.tsvitest.config.ts
f7dee5a to
ed65653
Compare
Adds `mcp-authkit-adapter-hono`, exposed via `mcp-authkit/adapters/hono`, mirroring the Express adapter. Provides `honoMiddleware(authkit, mcp)` plus per-route helpers `mcp`, `metadata`, `pats`, and `challenge`. The adapter privately bridges Hono's Web Fetch `Context` to Node-style `IncomingMessage`/`ServerResponse` so the framework-agnostic v0.1 `Handlers` run unchanged. Responses stream through a `PassThrough` — the `mcp` handler is never buffered, which matters for large MCP payloads. The Host header is synthesised from the Web Request URL so the DNS-rebinding check (spec §14) sees the real authority. Tests cover the same handler matrix as `adapter-express` (mcp / metadata / pats / 401 challenge), plus Hono-specific streaming verification and end-to-end host-header validation against a real `@hono/node-server`. Closes #66.
- Replace Promise.withResolvers (Node 22+) with a manual deferred helper so the streaming tests run on Node 20. - Bump @hono/node-server from ^1.19.0 to ^1.19.13 (security: GHSA-9hgr-4rmp-vgxw, GHSA-4r7q-rh3h-r9gq for authorization bypass and middleware bypass) and hono from ^4.0.0 to ^4.12.18 (advisories resolved by ^4.12.18).
ed65653 to
b5615d8
Compare
Closes #66.
Summary
Adds
mcp-authkit-adapter-hono(re-exported undermcp-authkit/adapters/hono),mirroring the Express adapter. Provides
honoMiddleware(authkit, mcp)plusper-route helpers
mcp,metadata,pats, andchallenge.Implementation
packages/adapter-hono/src/adapt.ts): buildsa synthetic
IncomingMessagefromc.req.raw(Web Request) and asynthetic
ServerResponsewhose writes hit aPassThrough. The firsthead-committing call (
writeHead,flushHeaders,write, orend)resolves a
Responsewhose body isReadable.toWeb(passthrough)— Honoships that stream as the response body, so the MCP handler is never
buffered.
Hostheader (the authority is inthe URL). The adapter synthesises
req.headers.hostfromURL.hostsothe spec §14 DNS-rebinding check sees the real authority.
depend on
mcp-authkitat the package.json level. Core(
packages/core/src/adapters/hono.ts) re-exports the public API andasserts structural compatibility at compile time.
hono ^4.0.0.Tests
Same handler matrix as
adapter-express:mcpforwarding + 401 challenge (no-bearer and invalid-bearer paths)metadata+patsper-route forwardingWWW-Authenticate,Cache-Control) flow throughchallenge()helper with and without reasononErrorHono-specific:
test only resolves AFTER reading the chunk, then writes the rest. A
buffered implementation would deadlock; the test passes because the
body streams.
Readable.End-to-end (
integration.test.ts) over real@hono/node-server+ realcreateAuthKit+fetch:mcp/pats401 challenges round-trip over the wire.Spec sections touched
§5.9 (Hono adapter), §5.10 (import paths), §10 (Hono adapter requirements).
Test plan
pnpm lintpnpm typecheckpnpm test(365 passed, +24 new)pnpm buildGenerated by Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests
Chores