Repository navigation
Overview
This release adds an optional MCP package for exposing Huma operations as Model Context Protocol tools, closes a gap where request body values could skip schema validation, and makes Register dramatically faster for models that reference each other. It also includes a few behavior changes, so please read the upgrade notes below.
Upgrade Notes
- JSON bodies with duplicate object keys now return
400. Previously{"a":1,"a":2}was accepted. This only applies to bodies decoded with the default JSON format (#1172) - CBOR field names are now matched case-sensitively and duplicate map keys are rejected. A CBOR key such as
Sourceno longer populates asourcefield (#1172) - Pointers to string-typed arrays are now nullable in the spec. Fields such as
*uuid.UUID,*net.IPand*[]bytenow render as["string", "null"], so generated specs and clients may change (#1157) tokenUrlis omitted when empty. Implicit OAuth flows no longer emit"tokenUrl": "", which the OpenAPI schema rejects (#1170)
Request Validation Fix
Request bodies could carry values that were never validated. encoding/json assigns case-variant keys ("Role" for a role field) and merges duplicate object keys, while validation only checked one key per property and the last duplicate. Constraints such as enum, pattern, maximum or maxLength could be skipped this way. Every case variant is now validated against its property, duplicate keys are rejected, and the CBOR format decodes the same keys validation checks. Upgrading is recommended. Custom JSON or CBOR formats should likewise reject duplicate keys and match field names the way validation does. (#1172)
MCP Tools
The new optional mcp package serves your 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. See the new docs page under Extra Packages and examples/mcp-auth. (#1171)
Faster Registration
Register no longer walks every path through an input's type graph, which grew exponentially when models referenced each other through more than one field. For example, a 22-level input with two pointers per level went from 3.06s and 7.7 GiB to 107µs and 152 KiB. Per-request performance is unchanged. (#1165)
Fixes
- autopatch: generated PATCH responses now keep every value of multi-value headers such as
Set-CookieandLink, instead of only the last (#1166) - humafiber:
ServeHTTPno longer times out after one second or panics on errors, which brought the server down when an autopatch PUT handler was slow. Errors now return a500(#1152) casing.LowerCamelreturns an empty string for empty or separator-only input instead of panicking (#1151)
Documentation
- Documented
humatest.Wrapfor testing adapter-specific middleware (#1154) - Fixed the humacli options example to use the
docstruct tag rather thanhelp(#1156)
Internal
- Applied
go fixmodernizations for Go 1.26, with no behavior changes (#1153)
What's Changed
- refactor: apply go fix modernizations by @robtme in #1153
- fix(humafiber): don't time out or panic in ServeHTTP by @APX403 in #1152
- fix(casing): return an empty string from LowerCamel for empty input by @youdie006 in #1151
- docs: show humatest.Wrap for adapter-specific middleware by @robtme in #1154
- fix(schema): keep nullability for pointers to string-typed arrays by @robtme in #1157
- docs: rename
helpcli options struct tag todocby @mxsgx in #1156 - fix: stop findInType walking every path through the type graph by @robtme in #1165
- fix: omit empty tokenUrl from OAuth flows by @robtme in #1170
- feat(mcp): expose Huma operations as MCP tools by @robtme in #1171
- fix: validate the same body keys the decoder assigns by @robtme in #1172
- fix(autopatch): keep every value of multi-value headers by @APX403 in #1166
New Contributors
Full Changelog: v2.40.0...v2.41.0