Skip to content

feat(mcp): expose Huma operations as MCP tools - #1171

Merged
robtme merged 1 commit into
mainfrom
mcp
Nov 17, 2026
Merged

robtme merged 1 commit into
mainfrom
mcp

Conversation

@robtme

@robtme robtme commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Adds an optional mcp package that serves operations as Model Context Protocol tools over Streamable HTTP. Tool calls are replayed through the API's own router, so validation, middleware and auth apply unchanged. It only imports the stdlib and Huma.

It's intentionally a sub-package rather than part of core, like sse and autopatch: most users won't need it, and it doesn't rely on anything internal to core.

  • I've deliberately avoided implementation details, since anything more would be an overreach for Huma. Auth is discovery only (RFC 9728 metadata, plus Server.SetChallenge to call before your usual 401); validating or issuing tokens stays with your middleware.
  • Call Attach on the root API before registering operations, since hidden operations are only seen through the API it returns. Create groups from that API; Attach panics on a group.
  • Header params listed in ForwardHeaders (e.g. Authorization) aren't tool arguments, so the caller's own header is always used.

Docs page under Extra Packages, plus examples/mcp-auth.

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.53695% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.04%. Comparing base (61c334f) to head (d3e586e).

Files with missing lines Patch % Lines
mcp/mcp.go 97.26% 7 Missing ⚠️
mcp/tool.go 98.46% 4 Missing ⚠️
mcp/auth.go 92.85% 3 Missing ⚠️
mcp/protocol.go 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1171      +/-   ##
==========================================
+ Coverage   94.75%   95.04%   +0.29%     
==========================================
  Files          25       30       +5     
  Lines        5224     5833     +609     
==========================================
+ Hits         4950     5544     +594     
- Misses        269      284      +15     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robtme
robtme force-pushed the mcp branch 5 times, most recently from 93d1418 to 9f7ca98 Compare November 15, 2026 18:56
Adds an optional mcp package serving the Model Context Protocol over Streamable
HTTP, covering both the stateless revision and the handshake-based ones.
Operations opt in with mcp.Tool(), or in bulk via Options.ExposeVisible /
ExposeHidden. Tool calls execute by round-tripping through the API's own
router, so request parsing, validation, middleware and response marshalling are
reused unchanged, and a tool is authenticated exactly as its operation already
was. The package imports nothing outside the standard library and Huma.

Authorization covers discovery only: the package serves RFC 9728 Protected
Resource Metadata, provides Server.SetChallenge for auth middleware to point
connectors at it before writing a 401 with huma.WriteErr, and turns a tool
call's 401 into a transport-level challenge. It validates no tokens and issues
none; that stays with your middleware, as it does for the rest of Huma.

Includes an mcp-auth example and a docs page.
@robtme
robtme merged commit 5c9ee6d into main Nov 17, 2026
7 checks passed
@robtme
robtme deleted the mcp branch November 17, 2026 21:18
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.

1 participant