Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: mcp tools#1298

Draft
HugoRCD wants to merge 2 commits intomainfrom
feat/mcp
Draft

feat: mcp tools#1298
HugoRCD wants to merge 2 commits intomainfrom
feat/mcp

Conversation

@HugoRCD
Copy link
Member

@HugoRCD HugoRCD commented Feb 6, 2026

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/mcp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { H3Event } from "../../event.ts";
import type { McpHandlerOptions } from "../mcp.ts";
import { readBody } from "../body.ts";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in v2, we can simply use web API event.res.json()`

"zod": "^4.3.6"
},
"peerDependencies": {
"@modelcontextprotocol/sdk": "^1.25.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to get rid of dep! #1180 is start i think /cc @sandros94

@pi0 pi0 changed the title feat: add native MCP support feat: defineMcpTool Feb 6, 2026
@pi0 pi0 changed the title feat: defineMcpTool feat: mcp tools Feb 6, 2026
@sandros94
Copy link
Member

sandros94 commented Feb 6, 2026

First off, lets address the elephant in the room: the @modelcontextprotocol/sdk library is humongous compared to h3.

A required step IMHO is having support for the native JsonRPC handler, which all modern MCPs are based off. I'll soon revisit #1180 PR and see if it needs something to be addressed. Regardless of MCPs this would also enable other use-cases, since it is well-known spec and vastly adopted (especially when mixing up programming languages).

But in reality the SDK reaches that size because of the following reasons, which are part of the MCP specs:

  • authorization is mostly based on JWT (either direct token or via OAuth/OIDC), this is something I've started digging deep (and ended up loving) almost one year ago support for JOSE (Javascript Object Signing and Encryption) #994
  • built-in validation, not only for project-level information/data but even before accepting the incoming RPC call. It is quite hardcoded ontop of zod, its own toJsonSchema and ajv for validating it. Which they also come with their tradeoffs, not only in bundle size (you can read more about it here)
  • the SDK itself is meant to be ready-to-use, not really a toolset to build-ontop, meaning that it comes with hono, express and various adapters.

There are another couple of aspects which I do not remember atm, but even just for the first two points above I would personally consider IF h3 is even the right place.

Even with forking the SDK, bringing over the bare minimum, we would still need:

  • JWT reader and validator: jose or unjwt (ofc I prefer the latter, but ended up being similar size and performance, just the DX is close to what h3 offers)
  • Validation library agnostic: StandardSchemaV1 support, which we have, and StandardJSONSchema which not only arrived recently but also requires dedicated linking for each validation library
  • A set of cryptographically secure utilities: for example to manage PKCE challanges, string comparison, randomness and so on ends up adding its own size, even forking a small library like unsecure
  • JsonRPC handler

Only at this point, once we have all these tools available (forked or added as deps) we can start building the various functions and constants, and from the experience in h3-mcp-tools (which I really miss and want to get back and develop it) I can confidently say that the final h3 size will at lest double, realistically triple, the current state.

My honest though would be to add this tooling in Nitro, which can treeshake stuff when unused anyway.

@sandros94
Copy link
Member

sandros94 commented Feb 6, 2026

Also, for these very reason I'm considering to just close the JWE issue and related PR (#997). Iron Crypto is not my personal favorite in its topic, but the current implementation is good-enough as is, and too many people already use it.

While on the other hand JWE (and JWS) would require to be as spec-compatible as possible, which inevitable end up increasing h3 size. Not to mention that the current useSession implementation is not compatible with the OAuth spec, which I would argue that it is the most important spec to consider when working with JWTs

This is why I built, maintain and use unjwt. JWT compliant, h3 DX

@pi0
Copy link
Member

pi0 commented Feb 6, 2026

Thanks for your thoughts @sandros94 ❤️

Yes, lets ship json rpc utils first!

With composable approach of h3 utils, i think we can easily make authenticated wrappers for MCP tools (which can live outside of h3 as ready to use opinionated solutions). And as for validation supporting standard schema just makes sense and comes for free.

H3 provides many treeshakable utils already. Users in Nitro can benefit from auto scanning of server/mcp/* tools + h3 as base or better wrapper packages that wrap base tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants