Repository navigation
feat: request facts, per-request log level and -32021 (T8 follow-ups) - #311
Conversation
…Level Add RequestInfo (protocol version, client capabilities, client info, log level, progress token) and expose it as ServerContext.request. The handler builds it once per request and passes it to the transport's context factory, which replaces the bare progress-token argument. A modern (2026-07-28) request takes all facts from _meta. A legacy request gives only the protocol version (header or _meta) and the progress token, because the server keeps no state from initialize. StreamingServerContext.log now follows the per-request log level of a modern request: it sends notifications/message only at or above _meta logLevel, and none when the request sets no level, as the 2026-07-28 spec requires. Legacy requests keep receiving all messages.
…ontext Add serverLogicWithContext to tools, prompts, resources and resource templates. The logic receives the ServerContext, so it can read the request facts (protocol version, client capabilities, client info, log level) without a streaming server. Until now only streaming tools got a context.
A tool can now declare the client capabilities it needs with withRequiredClientCapabilities. When a modern (2026-07-28) tools/call targets such a tool and _meta clientCapabilities does not declare them, the request fails before any logic runs with -32021 MissingRequiredClientCapability, HTTP 400, and data.requiredCapabilities set to the tool's requirement, as the schema requires. The check runs in requestRejection, so a streaming transport answers with plain JSON and not an SSE stream. Capabilities are compared key by key, recursively for nested objects. Legacy requests carry no capabilities, so they are not checked.
RequestId decoded numeric ids only as Int. A request with a larger id (for example a millisecond timestamp, which the conformance harness sends) failed to decode as a request and was taken for a notification, so the server answered with an empty response. RequestId now also holds a Long; small numbers still decode as Int, so existing ids compare equal.
…ce fixtures The server-stateless scenario (2026-07-28) calls test_missing_capability without declaring sampling and expects -32021 with HTTP 400, and calls test_logging_tool without a logLevel and expects no notifications/message. test_missing_capability declares sampling as a required client capability; test_logging_tool logs once at every level and relies on the per-request log gate. Both checks now pass. The scenario stays in the baseline, because it also covers subscriptions/listen and other later work.
Describe ctx.request (RequestInfo) and which facts a modern and a legacy request give, serverLogicWithContext, the logLevel gate on ctx.log for modern requests, and withRequiredClientCapabilities with its -32021 rejection. Add -32021 to the table of modern request errors.
…og level The shared streaming tests run with a legacy client (Pekko) and with a modern 2026-07-28 client (ZIO, Ox). The modern client sends no _meta logLevel yet, so under the per-request log level rule it must receive no notifications/message. Each spec now states its client protocol version, and the log tests expect the messages for a legacy client and none for a modern one. This covers the log gate end to end over HTTP on all three backends.
server/discover was the era-agnostic bootstrap and skipped all checks. A discover that declares a version (in _meta or in the MCP-Protocol-Version header) is now a modern request and gets the same checks: -32602 for missing _meta keys, -32022 with the supported and requested versions for an unsupported version, -32020 for a header that differs from _meta, and the SEP-2243 Mcp-Method check, all with HTTP 400. A discover with no version, or a legacy one, is still answered, so a probing client can discover the server. Two ordering fixes follow the conformance harness: a header/_meta version mismatch is now reported (-32020) before an unsupported _meta version (-32022), and a modern HTTP request without the MCP-Protocol-Version header fails with -32020.
|
Hello @kubinio123 , could you please look at this? Do you like this approach? 🙏 |
There was a problem hiding this comment.
I found two spec problems in the new -32021 check. Both are in McpHandler.scala (missingCapabilityError / declares), and both fixes are small.
1. A client that sends elicitation: {} is rejected
The elicitation spec says:
For backwards compatibility, an empty capabilities object is equivalent to declaring support for
formmode only
At the moment, a tool that needs elicitation.form rejects a client that declares elicitation: {}, so a valid client gets -32021. The test in McpHandlerSpec checks for this wrong result.
Suggested fix: treat elicitation: {} as { form: {} } before the comparison, and change the test.
2. data.requiredCapabilities should list only the missing capabilities
The spec says the error's data.requiredCapabilities "lists the missing capabilities". At the moment we send every capability the tool needs.
Example: a tool needs sampling and elicitation.form, and the client declares sampling. The error still lists sampling, so the client gets wrong information about what is missing.
Suggested fix: make declares return the part of required that the client did not declare, and send only that part.
…ans form An empty elicitation capability declares form mode only, as the spec says for backwards compatibility. data.requiredCapabilities now lists only the capabilities the client did not declare.
|
@kubinio123 thank you. Both points are fixed in b6c07da.
Could you take another look, please? |
3aa545f
into
softwaremill:2026-07-28-protocol-support
T8 follow-ups — part of #246
Layer 1 of a stack (base
2026-07-28-protocol-support). It adds the request-level rules of 2026-07-28 that #274 left open.Request facts in the server context
RequestInfoonServerContext.request: protocol version, client capabilities, client info, log level, progress token._meta. New keyProtocolMeta.LogLevel(io.modelcontextprotocol/logLevel, from the schema).None, because the server keeps no state frominitialize.serverLogicWithContext, so they can read the facts.Per-request log level
ctx.logsendsnotifications/messageonly at or above_metalogLevel.-32021MissingRequiredClientCapabilitytool(...).withRequiredClientCapabilities(ClientCapabilities(...)).tools/callwhose_meta.clientCapabilitieslacks them is rejected before any logic runs: HTTP 400, plain JSON,data.requiredCapabilitieslists only the missing capabilities. An emptyelicitation: {}counts as form mode only, as the spec says.server/discovervalidationserver/discoverthat declares a version (header or_meta) gets the same checks as other modern requests:-32602for missing_metakeys,-32022for an unsupported version,-32020for a header/_metamismatch or a wrongMcp-Method. All HTTP 400._metamismatch is checked before an unsupported version, and a modern HTTP request withoutMCP-Protocol-Versiongets-32020(both match the harness's own mock server). Stdio is not affected.Other
RequestIdaccepts ids beyond the Int range. The harness sendsid: Date.now(), which the server took for a notification.test_missing_capability(needs sampling) andtest_logging_tool(logs once at every level).docs/server/capabilities.md.Tests and conformance
McpHandlerSpec43 → 64 tests; red→green shown for the log gate,-32021, the Long id and discover validation.testFull289 passed, Integration 117 passed.server-stateless: 24 of 28 checks pass. It stays in the baseline: 3 checks needsubscriptions/listen(T16, next layer), 1 needstest_streaming_elicitation(T14).Not in this PR
logLevel/clientCapabilitieswith-32602(today it becomesNone)._meta.logLevel(T10–T12).Stack
subscriptions/listenx-mcp-header