Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions conformance-baseline-2026-07-28.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ server:
- tasks-request-state-removal
- tasks-required-task-error
- tasks-wire-fields
# server-to-client input requests during tools/call — T5, https://github.com/softwaremill/chimp/issues/243
- input-required-result-basic-elicitation
- input-required-result-basic-list-roots
- input-required-result-basic-sampling
- input-required-result-capability-check
- input-required-result-multiple-input-requests
- input-required-result-multi-round
- input-required-result-non-tool-request
# an integrity-protected requestState — T14 request-state helper, https://github.com/softwaremill/chimp/issues/252
- input-required-result-request-state
- input-required-result-result-type
- input-required-result-tampered-state
# full stateless lifecycle (needs subscription serving)
- server-stateless
# x-mcp-header custom headers in the tool DSL — T13, https://github.com/softwaremill/chimp/issues/251
- http-custom-header-server-validation
# the harness records a failure in a non-primary run of these scenarios (the primary run passes)
- sep-2164-resource-not-found
- input-required-result-missing-input-response
- input-required-result-ignore-extra-params
client:
# OAuth client flows — chimp's client has no full OAuth support yet
- auth/authorization-server-migration
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/chimp/protocol/Mrtr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ object InputResponse:
* opaque `requestState` the client echoes back on its response, and the modern result envelope fields.
*/
final case class InputRequiredResult(
inputRequests: Map[String, InputRequest],
inputRequests: Option[Map[String, InputRequest]] = None,
requestState: Option[String] = None,
resultType: ResultType = ResultType.Incomplete,
resultType: ResultType = ResultType.InputRequired,
_meta: Option[Map[String, Json]] = None
) derives io.circe.Codec
12 changes: 6 additions & 6 deletions core/src/main/scala/chimp/protocol/Versioning.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ object ProtocolMeta:
data = Some(Json.obj("requiredCapabilities" -> required.asJson.deepDropNullValues))
)

/** The type of a modern (2026-07-28+) result: `complete` for a finished result, `incomplete` for one that needs another round trip (MRTR
* input-required).
/** The type of a modern (2026-07-28+) result: `complete` for a finished result, `input_required` for one that needs another round trip
* (MRTR).
*/
enum ResultType(val name: String):
case Complete extends ResultType("complete")
case Incomplete extends ResultType("incomplete")
case InputRequired extends ResultType("input_required")

object ResultType:
given Encoder[ResultType] = Encoder.instance(resultType => Json.fromString(resultType.name))
given Decoder[ResultType] = Decoder.decodeString.emap:
case "complete" => Right(Complete)
case "incomplete" => Right(Incomplete)
case other => Left(s"Unknown result type: $other")
case "complete" => Right(Complete)
case "input_required" => Right(InputRequired)
case other => Left(s"Unknown result type: $other")

/** Whether a cached response may be shared across authorization contexts (`Public`) or not (`Private`). */
enum CacheScope:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ class Schema20260728ConformanceSpec extends SchemaConformance:
)
validate(
"InputRequiredResult",
InputRequiredResult(inputRequests = Map("name" -> request), requestState = Some("state-1"))
InputRequiredResult(inputRequests = Some(Map("name" -> request)), requestState = Some("state-1"))
)
InputRequiredResult(requestState = Some("state-1")).asJson.hcursor.get[String]("resultType") shouldBe Right("input_required")

it should "produce CallToolRequestParams carrying inputResponses and requestState that match the spec schema" in:
validate(
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and [sttp](https://github.com/softwaremill/sttp), supporting the variety of the
server/prompts
server/resources
server/capabilities
server/mrtr
server/examples

.. toctree::
Expand Down
50 changes: 49 additions & 1 deletion docs/server/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val work = tool("work")
val server = StreamingMcpServer[Identity]().addStreamingTool(work)
```

Server-wide capabilities are enabled by registering a handler — only what you wire up is advertised: `.withCompletion`, `.withLoggingLevel`, `.withSubscriptions`. `.withLoggingLevel` and `.withSubscriptions` serve only legacy clients: `2026-07-28` removed `logging/setLevel` and `resources/{,un}subscribe`, so a modern client gets a `404` for them (see below).
Server-wide capabilities are enabled by registering a handler — only what you wire up is advertised: `.withCompletion`, `.withLoggingLevel`, `.withSubscriptions`, `.withPublisher`. `.withLoggingLevel` and `.withSubscriptions` serve only legacy clients: `2026-07-28` removed `logging/setLevel` and `resources/{,un}subscribe`, so a modern client gets a `404` for them (see below). `.withPublisher` serves only modern clients (see [publishing list changes and resource updates](#publishing-list-changes-and-resource-updates)).

## Protocol versions

Expand All @@ -45,6 +45,7 @@ A request is **modern** when its `_meta` or its `MCP-Protocol-Version` header de
| the `MCP-Protocol-Version` header is missing (HTTP only), or it and `_meta` declare different versions | `-32020` HeaderMismatch | `400` |
| `Mcp-Method` / `Mcp-Name` header missing or different from the body (HTTP only) | `-32020` HeaderMismatch | `400` |
| removed method (`initialize`, `ping`, `logging/setLevel`, `resources/subscribe`, `resources/unsubscribe`) or unknown method | `-32601` MethodNotFound | `404` |
| `subscriptions/listen` on a server without a publisher, or on the sync HTTP transport | `-32601` MethodNotFound | `404` |
| `tools/call` of a tool whose required client capabilities `_meta` does not declare | `-32021` MissingRequiredClientCapability | `400` |

Over HTTP, a modern request must carry the SEP-2243 standard headers: `Mcp-Method` with the body's `method`, and `Mcp-Name` with `params.name` on `tools/call` and `prompts/get`, or `params.uri` on `resources/read`. Header names are case-insensitive, values are case-sensitive, and surrounding whitespace is ignored. chimp's own client sends these headers and the `_meta` when you give it a modern protocol version — see [client transport](../client/transport.md).
Expand All @@ -57,6 +58,7 @@ Each handler can read the facts of its request from `ctx.request`, a `RequestInf
- `clientCapabilities` and `clientInfo` — what the client declares in `_meta`.
- `logLevel` — the per-request log level from `_meta`.
- `progressToken` — the progress token from `_meta`.
- `inputResponses` and `requestState` — on the retry of an input-required outcome, the answers of the client and the echoed state (see [asking the client for input](mrtr.md)).

A modern request carries all of these in `_meta`. The server keeps no state between requests, so a legacy request gives only the protocol version (from the `MCP-Protocol-Version` header or `_meta`) and the progress token. The other facts are `None`.

Expand All @@ -82,3 +84,49 @@ val ask = tool("ask")

val server = McpServer[Identity]().addTool(ask)
```

## Publishing list changes and resource updates

A server tells its clients that its tools, prompts or resources changed, or that a resource was updated, through a `NotificationPublisher`. Create one, give it to the server with `.withPublisher`, and call it from any part of your application, not only from a tool:

- `toolsListChanged()`, `promptsListChanged()`, `resourcesListChanged()` — send the list-changed notification of that list.
- `resourceUpdated(uri)` — send `notifications/resources/updated` for one resource URI.
- `close()` — end all open subscriptions, for example when the server shuts down.

The methods are thread-safe and return `Unit`, not an effect. In an effect system, wrap the call, for example `ZIO.succeed(publisher.toolsListChanged())`.

```scala mdoc:compile-only
import chimp.server.*
import chimp.server.ox.OxServerHttpTransport
import io.circe.Codec
import sttp.shared.Identity
import sttp.tapir.*

case class NoteInput(text: String) derives Codec, Schema

val publisher = NotificationPublisher()

val addNote = tool("add_note")
.input[NoteInput]
.handle: _ =>
publisher.resourcesListChanged()
ToolResult.text("note added")

val server = McpServer[Identity]().addTool(addNote).withPublisher(publisher).streaming
val endpoint = OxServerHttpTransport(List("mcp")).serve(server)
```

A `2026-07-28` client receives these notifications on a [`subscriptions/listen`](https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions) stream:

- With a publisher, `server/discover` advertises `listChanged` for tools, prompts and resources, and `subscribe` for resources. The capability of a list is there only when the server has that feature, for example `prompts` only when the server has prompts. The `initialize` result for legacy clients does not change: it advertises no list changes, and `subscribe` only for `.withSubscriptions`.
- The first message on the stream is `notifications/subscriptions/acknowledged`. Its filter is the part of the requested filter that the server honours. The server sends no other notification types.
- Each message on the stream carries the id of the listen request in `_meta`, under `io.modelcontextprotocol/subscriptionId`.
- `notifications/resources/updated` goes only to the streams which list the URI in `resourceSubscriptions`.
- Progress and log notifications do not go on a listen stream. They stay on the stream of their request.
- Over HTTP, a subscription ends when the client closes the stream. The server notices a closed stream at the latest when it next sends on it.
- Over stdio, all subscriptions share the one channel. The client ends one with `notifications/cancelled` that names the listen request. When the input ends, the server ends each open subscription.
- When the server ends a subscription (on `close()`, or at the end of the stdio input), it sends a successful `subscriptions/listen` result with the subscription id. Over stdio, it then sends `notifications/cancelled` for the listen request.

```{note}
A listen stream needs a streaming transport. On the sync HTTP transport (`McpServer.endpoint`), the server answers `subscriptions/listen` with `-32601` and advertises no list changes.
```
70 changes: 70 additions & 0 deletions docs/server/mrtr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Asking the client for input

In protocol version `2026-07-28`, a server does not send requests to the client while it handles a request. Instead, a handler can end a `tools/call`, `prompts/get` or `resources/read` with an **input-required** outcome. The client gets the input that the handler asks for, and then sends the same request again with the answers. The server keeps no state between the two requests. This is the [multi round-trip requests](https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr) (MRTR) pattern.

## Requesting input

A tool, prompt or resource handler returns `InputRequired` instead of its result. `InputRequired` names each input request with a key that the handler chooses:

| Input request | What the client does | Client capability that it needs |
|---|---|---|
| `InputRequired.elicitForm(message, schema)` | asks the user to fill in a form | `elicitation` (form mode) |
| `InputRequired.elicitUrl(message, url)` | asks the user to open a URL | `elicitation.url` |
| `InputRequired.sample(params)` | samples its LLM | `sampling` |
| `InputRequired.listRoots` | sends its roots | `roots` |

On the retry, the handler reads the answers under the same keys from `ctx.request`: `elicitResult(key)`, `samplingResult(key)` and `rootsResult(key)`. A handler that never returns `InputRequired` works as before.

```scala mdoc:compile-only
import chimp.server.*
import io.circe.{Codec, Json}
import sttp.shared.Identity
import sttp.tapir.*

case class NoInput() derives Codec, Schema

val nameSchema = Json.obj(
"type" -> Json.fromString("object"),
"properties" -> Json.obj("name" -> Json.obj("type" -> Json.fromString("string")))
)

val greet = tool("greet")
.input[NoInput]
.serverLogicWithContext[Identity]: (_, ctx, _) =>
ctx.request.elicitResult("user_name").flatMap(_.content).flatMap(_.get("name")).flatMap(_.asString) match
case Some(name) => ToolResult.text(s"Hello, $name!")
case None => InputRequired("user_name" -> InputRequired.elicitForm("What is your name?", nameSchema))
```

Prompts and resources use the same `InputRequired` from their `serverLogicWithContext`.

### Several rounds and the request state

A handler can ask again on the retry, as many times as it needs. To remember what happened in the earlier rounds, it attaches a **request state** with `.withRequestState(state)`. The client sends the state back without a change on its retry, and the handler reads it from `ctx.request.requestState`. `InputRequired.withRequestState(state)` makes an outcome that has a state and no input requests: the client then retries at once.

```{warning}
The request state goes through the client, so treat it as input from an attacker. If the state controls authorization, resource access or business logic, protect its integrity, and reject a state that you cannot verify.
```

### Missing answers

If the retry does not have an answer that the handler needs, return a new `InputRequired` that asks for it again. Do not fail the request. The client can omit an answer, or send it under a different key. Keys that the handler did not ask for are ignored.

### Client capabilities

A handler can read `ctx.request.clientCapabilities` and ask only for what the client supports. For example, it can ask for sampling when the client declares `sampling`, and for a form if not.

## Rules that chimp enforces

chimp applies these rules, so a handler does not have to:

| Problem | Result |
|---|---|
| an input request that needs a capability which the client did not declare | `-32021` MissingRequiredClientCapability with `data.requiredCapabilities`, HTTP `400` |
| `inputResponses` is not an object, or one of its values is not a sampling, roots or elicitation result | `-32602` InvalidParams, HTTP `400`; the handler does not run |
| `requestState` is not a string | `-32602` InvalidParams, HTTP `400`; the handler does not run |
| `InputRequired` on a legacy (`2025-11-25` or earlier) request | `-32603` InternalError which names protocol version `2026-07-28` |

An `InputRequired` always has at least one input request or a request state. Only `tools/call`, `prompts/get` and `resources/read` can end with it.

On a streaming HTTP server, chimp opens the event stream when the handler sends its first message. If the handler ends with the `-32021` before it sends a message, chimp sends a plain JSON error with HTTP `400`. If the handler already sent a message, for example a progress notification, the `-32021` is the last message on the event stream.
2 changes: 2 additions & 0 deletions docs/server/prompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ val endpoint = McpServer(prompts = List(greeting)).endpoint(List("mcp"))
```

Prompt messages reuse the `ToolContent` content types, so they can embed images (`ToolContent.Image`) and resources (`ToolContent.ResourceContent`) just like tool results.

A prompt can also ask the client for input before it returns its messages: see [asking the client for input](mrtr.md).
3 changes: 3 additions & 0 deletions docs/server/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `serverLogic` — effectful read logic, with the request headers.
- `handleSecured` (synchronous) or `securedServerLogic` (effectful) — logic that also receives the principal made by the server's security logic; usable only on a secured server — see [transport security](transport.md).
- Register with `.addResource` / `.addResourceTemplate`. Subscriptions are wired with `.withSubscriptions`; they serve legacy clients only, as `2026-07-28` removed `resources/{,un}subscribe` (see [protocol versions in server capabilities](capabilities.md)).
- On `2026-07-28`, a client subscribes to resources with the `resourceSubscriptions` filter of `subscriptions/listen`, which replaces `resources/subscribe`. Send the updates with `NotificationPublisher.resourceUpdated(uri)`; the server sends each update only to the streams which list its URI (see [publishing list changes and resource updates](capabilities.md#publishing-list-changes-and-resource-updates)).

```scala mdoc:compile-only
import chimp.server.*
Expand All @@ -26,3 +27,5 @@ val endpoint = McpServer(resources = List(readme), resourceTemplates = List(item
```

Returning `Left(ResourceError(...))` (or reading an unknown URI) responds with a JSON-RPC error carrying the offending `uri`.

A resource can also ask the client for input before it returns its contents: see [asking the client for input](mrtr.md).
2 changes: 2 additions & 0 deletions docs/server/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ val adder = tool("adder")

The output type carries into the logic, which returns a `ToolResult[SumOutput]`; `ToolResult.error` is accepted whatever the output type. A
result with structured output but no content is also sent as serialized JSON text, as the spec recommends.

A tool can also ask the client for input before it returns its result: see [asking the client for input](mrtr.md).
Loading
Loading