Minor Changes
-
#1624
6032170Thanks @SamMorrowDrums! - Add request-time OAuth scope challenges for tools, resources, resource templates,
and prompts. Each primitive'sscopeChallengecallback receives the parsed
request and verified authentication info, then either continues or returns the
exact scope set for aninsufficient_scoperesponse.requireScopesprovides a
small helper for static all-of checks.createMcpHandlerand Streamable HTTP transports return HTTP 403 with an
insufficient_scopechallenge before handler execution or SSE setup. The
preflight is active whenever a registered primitive carries ascopeChallenge
callback — there is no handler- or transport-level configuration. The
challenge'sWWW-Authenticateheader is built by the same formatter as the
bearer-auth 401/403 answers, and itsresource_metadataparameter is derived
from the verifiedAuthInfo:requireBearerAuth/verifyBearerTokennow
stamp their configuredresourceMetadataUrlonto theAuthInfothey return
(new optionalAuthInfo.resourceMetadataUrlfield), with a fallback to the
well-known location for an HTTP(S) RFC 8707resourceidentifier; the
parameter is omitted when neither is available.
Patch Changes
-
#2698
7b781edThanks @maxisbey! - Read Streamable HTTP request bodies with a size limit. Every SDK-owned body read —
WebStandardStreamableHTTPServerTransport(and the Node transport built on it),
createMcpHandler,toNodeHandler, andcreateMcpHonoApp's JSON pre-parse — now stops at
4 MiB by default (the limit the legacy SSE transport already uses; the Express adapter and stdio
bound their reads too) and answers413 Payload Too Largebefore anything is parsed.
toWebRequest(when it reads the Node stream itself) now rejects once the body exceeds the
limit with an error whosenameis'RequestBodyTooLargeError'andstatusis413, and
toNodeHandleranswers that with413; hand-wired callers oftoWebRequestshould handle the
rejection or pass a pre-parsed body, andisLegacyRequestreports such a request as non-legacy
so the modern handler answers it. JSON-RPC batch arrays are limited to 100 messages; a longer
batch is answered400/-32600and none of it is dispatched.The limit is configurable with a new
maxRequestBodySizeoption (bytes, default
DEFAULT_MAX_REQUEST_BODY_SIZE= 4 MiB, exported from@modelcontextprotocol/server) on
WebStandardStreamableHTTPServerTransportOptions,CreateMcpHandlerOptions(forwarded to its
stateless legacy leg;isLegacyRequestandlegacyStatelessFallbacktake the same option),
CreateMcpHonoAppOptions, andToNodeHandlerOptions/ToWebRequestOptions(the adapter's
bound applies before the handler's, so raise both). The bounded reader is exported as
readRequestBodyfor adapter authors. Hosts that pre-parse the body and pass it as
parsedBodyskip the SDK's read and its size limit entirely; the batch bound applies either way.createMcpHonoAppandcreateMcpExpressAppnow run their Host/Origin validation before the
JSON body parser, so a request from a disallowed Host or Origin with an invalid JSON body is
answered403rather than400, and its body is not read. -
Updated dependencies [
6fa4227,03842cd,3e90449,7b781ed,75dc7ea,6032170,6a05402,70de0c8]:- @modelcontextprotocol/server@2.1.0