
MRTR: Human-in-the-Loop MCP Tools Over Stateless HTTP
Summary
Pause an MCP tool mid-call to confirm with the user, on the new stateless 2026-07-28 protocol.
On July 28, 2026 the Model Context Protocol shipped its biggest revision since launch, and one line in the changelog quietly broke a pattern thousands of MCP servers rely on: the server-initiated back-channel is gone. Under SEP-2577, a running tool can no longer reach out mid-execution to ask the user a question. That means ctx.elicit() — the call every “are you sure?” confirmation and every “which folder?” prompt was built on — stops working the moment your connection negotiates the modern protocol.
The replacement is MRTR: Multi Round-Trip Requests (SEP-2322). Instead of blocking inside the tool and waiting on an open stream, a tool now returns a description of what it needs. The client answers, then re-issues the same call with the answer attached, and the tool runs again from the top. Each round is a complete request/response cycle, which is exactly why it survives on stateless, serverless, and load-balanced deployments where no two rounds are guaranteed to hit the same worker.
This guide teaches the guard pattern end to end: why the old approach breaks, how to build a confirmation tool that pauses before doing something destructive, how to carry state safely across rounds, and how to make it all run behind a plain round-robin load balancer. Every code sample uses the real FastMCP 4.0 and MCP Python SDK APIs shipped for the 2026-07-28 spec. By the end you will have a working delete-with-confirmation tool and a client that drives the whole loop automatically.
What actually changed on 2026-07-28
The headline of the release is a stateless protocol core. MCP dropped the initialize/initialized handshake and the Mcp-Session-Id header. Every request is now self-describing: it carries its protocol version, client identity, and capabilities in _meta, so any request can land on any server instance behind a round-robin load balancer without shared session storage.
Statelessness is great for scaling, but it removed the mechanism elicitation depended on. The old ctx.elicit() worked by holding the tool open and pushing a request back down a bidirectional stream to the client. With no session and no server-initiated stream, there is nowhere for that request to go. So the spec redesigned user interaction around round trips instead of held-open connections.
The era gate is strict and deliberate. ctx.elicit() only works on handshake-era connections (2025-11-25 and earlier). The new InputRequiredResult only exists on 2026-07-28. Mix them up and FastMCP raises a clear era-mismatch error instead of failing obscurely. If you must serve both, you branch on ctx.request_context.protocol_version.
Prerequisites
- Python 3.10+ and basic async/await familiarity.
- FastMCP 4.0 or newer (the modern-protocol APIs land in 4.0):
pip install fastmcp. - A rough mental model of MCP tools: a server exposes functions, a client (an AI app) calls them.
- For the multi-replica section, a way to set a shared environment variable across processes.
pip install "fastmcp>=4.0"
python -c "import fastmcp; print(fastmcp.__version__)"
Step 1: The old way, and why it breaks
Here is the classic handshake-era confirmation tool. It calls ctx.elicit(), blocks until the user answers, then acts. This still works when the connection negotiates 2025-11-25 or earlier — and it is worth knowing, because you may still support older clients.
from fastmcp import FastMCP, Context
mcp = FastMCP("Legacy Server")
@mcp.tool
async def approve_action(ctx: Context) -> str:
# Handshake-era only: blocks mid-call on a server->client request.
result = await ctx.elicit("Approve this action?", response_type=bool)
if result.action == "accept" and result.data:
return "Done."
raise ValueError("Action rejected")
On a 2026-07-28 connection this raises an era error, because there is no back-channel for the server to push the question through. The fix is not a patch to ctx.elicit() — it is a different shape of tool. Instead of blocking, the tool returns a request and gets re-invoked with the answer.
Step 2: The guard pattern mental model
A modern elicitation tool is a guard. Every time it runs, it re-runs from the top, checks whether the answers it needs are already present, and either asks for more or proceeds to the real work. Two request-scoped properties on Context drive the whole thing:
ctx.input_responses— the client’s answers to what you asked on the previous round. It isNoneon the very first round (nothing has been asked yet) and a mapping of answers on later rounds.ctx.request_state— a small opaque string you can carry from one round to the next.Noneon the first round; otherwise it echoes back whatever you last put inInputRequiredResult.request_state.
To ask for input, you return an InputRequiredResult whose input_requests map describes what you need. Each request has a key; the client’s answer comes back under that same key in ctx.input_responses. The framework does not hold the call open between rounds — it is genuinely a fresh execution each time.
Step 3: Build a confirmation guard
Let’s build the single most common real-world case: a destructive tool that must confirm before it acts. We wrap a small helper, ask(), that builds an InputRequiredResult eliciting one field, then write a purge_cache tool that refuses to run until the user says yes.
from fastmcp import FastMCP, Context
from mcp.types import (
InputRequiredResult,
ElicitRequest,
ElicitRequestFormParams,
)
mcp = FastMCP("Ops Server")
def ask(key: str, message: str, field: str, request_state: str | None = None) -> InputRequiredResult:
"""Return an InputRequiredResult that elicits a single field from the client."""
params = ElicitRequestFormParams(
message=message,
requested_schema={
"type": "object",
"properties": {field: {"type": "string"}},
"required": [field],
},
)
elicitation = ElicitRequest(method="elicitation/create", params=params)
return InputRequiredResult(
result_type="input_required",
input_requests={key: elicitation},
request_state=request_state,
)
@mcp.tool
async def purge_cache(namespace: str, ctx: Context) -> str | InputRequiredResult:
"""Delete every key in a cache namespace. Confirms first."""
responses = ctx.input_responses
# Round 1: nothing asked yet -> ask for confirmation.
if responses is None:
return ask("confirm", f"Type the namespace '{namespace}' to confirm deletion.", "confirm")
# Round 2: the answer is here. Validate it, then do the work.
answer = responses["confirm"]
if answer.action != "accept":
return "Cancelled. Nothing was deleted."
typed = answer.content["confirm"]
if typed != namespace:
return f"Aborted: '{typed}' does not match '{namespace}'."
# ... real deletion happens here ...
return f"Purged all keys in namespace '{namespace}'."
The important discipline: always check answer.action before reading answer.content. A client can decline or cancel, and in those cases content is absent. A decline is a normal answer delivered to your tool like any other round — not an exception — so you handle it deliberately.
Step 4: Multiple rounds, carrying state forward
Real workflows ask for more than one thing. Because each round is a fresh execution, you cannot rely on local variables to remember what happened last time — you carry small values forward in request_state. Here is a booking tool that asks for a destination, then a date, then confirms, across three rounds.
@mcp.tool
async def book_flight(ctx: Context) -> str | InputRequiredResult:
responses = ctx.input_responses
# Round 1: ask where.
if responses is None:
return ask("destination", "Where would you like to fly?", "destination")
# Round 2: destination is in; ask when, stash destination in request_state.
if "destination" in responses:
destination = responses["destination"].content["destination"]
return ask(
"date",
f"When would you like to fly to {destination}?",
"date",
request_state=f"dest={destination}",
)
# Round 3: date is in; read destination back out of request_state.
destination = ctx.request_state.split("=", 1)[1]
date = responses["date"].content["date"]
return f"Booked a flight to {destination} on {date}"
The tool runs three times for one logical call. First run: input_responses is None, so it asks for a destination. Second run: the destination is present, so it asks for a date and stashes the destination. Third run: the date is present, so it reads the destination back out of request_state and returns the booking. Nothing on the server stays alive between rounds; everything it needs rides on the request.
Step 5: Drive the loop from a client
You do not hand-roll the retry loop. fastmcp.Client drives it automatically: point it at a 2026-era connection with mode="auto" and give it an elicitation handler. It fulfils each round’s requests and re-calls until the tool returns its final result.
from fastmcp import Client
from fastmcp.client.elicitation import ElicitResult
async def handler(message, response_type, params, ctx):
# Answer each round based on what the server asked.
if "Where" in message:
return ElicitResult(action="accept", content=response_type(destination="Paris"))
return ElicitResult(action="accept", content=response_type(date="2026-08-01"))
async with Client(mcp, mode="auto", elicitation_handler=handler) as client:
result = await client.call_tool("book_flight", {})
print(result.data) # "Booked a flight to Paris on 2026-08-01"
The client caps how many rounds it will drive with input_required_max_rounds (default 10), so a buggy guard that keeps asking cannot loop forever — exceeding the cap raises an error instead of hanging. In production, your MCP host (Claude, an IDE, your own agent) provides the handler and typically surfaces the elicitation as a UI prompt to a real human.
Step 6: Run it stateless, across replicas
Everything above already works over stateless HTTP. To serve the modern protocol as a plain web service, run the streamable-HTTP transport in stateless mode:
mcp.run(transport="streamable-http", stateless_http=True, json_response=True)
There is one subtlety for horizontally scaled deployments. The request_state you return is sealed by the framework before it hits the wire and unsealed and verified before your tool runs again — you never touch crypto yourself. By default each process seals under a per-process ephemeral key, which is correct for a single worker but means state minted by one replica is rejected by another. When consecutive rounds may land on different replicas, give every replica the same key:
import os
from fastmcp import FastMCP
from mcp.server.request_state import RequestStateSecurity
mcp = FastMCP(
"Booking Server",
request_state_security=RequestStateSecurity(
keys=[os.environ["REQUEST_STATE_KEY"].encode()]
),
)
Keys must be at least 32 bytes of secret randomness. The keys list is a rotation ring: keys[0] seals, every key can unseal, so you rotate without downtime by rolling [old, new] → [new, old] → [new] across deployments. Generate one with:
python -c "import secrets; print(secrets.token_hex(32))"
Worked example: a full delete-with-confirmation trace
Here is what the purge_cache tool from Step 3 looks like on the wire, round by round, when a client calls it for the namespace sessions.
# Round 1 -- client calls the tool
POST /mcp Mcp-Method: tools/call Mcp-Name: purge_cache
{"params": {"name": "purge_cache", "arguments": {"namespace": "sessions"}}}
# Round 1 result -- tool returns an ask (input_required)
{"result": {"result_type": "input_required",
"input_requests": {"confirm": {"method": "elicitation/create",
"params": {"message": "Type the namespace 'sessions' to confirm deletion.",
"requested_schema": {...}}}}}}
# Round 2 -- client re-calls with the answer attached
POST /mcp Mcp-Method: tools/call Mcp-Name: purge_cache
{"params": {"name": "purge_cache", "arguments": {"namespace": "sessions"},
"inputResponses": {"confirm": {"action": "accept",
"content": {"confirm": "sessions"}}}}}
# Round 2 result -- final answer
{"result": {"content": [{"type": "text",
"text": "Purged all keys in namespace 'sessions'."}]}}
Notice the routing headers Mcp-Method and Mcp-Name on every request. On 2026-07-28 these are mandatory, and they let a gateway, rate limiter, or WAF route and meter on headers without parsing the JSON body. If the user had declined at round 2, answer.action would be "decline", content would be absent, and the tool would return “Cancelled” instead of deleting anything.
Common pitfalls and gotchas
- Era mismatch. Returning an
InputRequiredResulton a handshake-era (≤ 2025-11-25) connection raises a clear error. If you support both eras, branch onctx.request_context.protocol_version: return the guard result on modern connections, fall back toctx.elicit()on older ones. - Reading content before checking action. Always test
answer.action == "accept"first. On decline or cancel,contentis missing and indexing it throws. - Relying on local state between rounds. Each round is a fresh execution. Anything you need later must travel in
request_state(kept small — it round-trips every leg) or be re-derived from the arguments. - Forgetting the shared key across replicas. Per-process ephemeral keys reject state minted elsewhere. Multi-replica deployments must set a shared
RequestStateSecuritykey of at least 32 bytes, or continuation rounds fail verification. - Assuming the loop is free. Every round runs the full middleware chain and is a complete request. Do not put an LLM generation loop behind a guard round unless you specifically want the caller’s model — call the model directly from the server instead.
- Caching asks. Never cache an
InputRequiredToolResult; replaying a stale question to a later caller is a bug. FastMCP’s built-in response cache already skips them. - Empty confirmation schema. When you just want yes/no, ask for a
bool. An empty schema gives some clients nothing to render and shows a broken, non-functional form.
Quick reference
| Concept | Handshake era (≤ 2025-11-25) | Modern (2026-07-28) |
|---|---|---|
| Ask for input | await ctx.elicit(msg, response_type=...) | return InputRequiredResult(...) |
| How it reaches the user | Server->client request on open stream | Tool returns; client re-calls |
| Read the answer | result.action / result.data | ctx.input_responses[key].action / .content |
| Carry state across steps | Local variables (call stays open) | ctx.request_state (sealed opaque string) |
| Actions | accept / decline / cancel | accept / decline / cancel |
| Works on stateless / LB | No | Yes |
| Client driver | elicitation_handler | elicitation_handler + auto retry |
One-line summary: on the modern protocol, asking is a return value, not a blocking call, and your tool is a guard that re-runs until it has everything it needs.
Next steps
- Add a
boolconfirmation guard to your most destructive existing tool first — it is the highest-value, lowest-risk migration. - Mix request types: an
InputRequiredResultcan carry aCreateMessageRequest(sampling) orListRootsRequestalongside an elicitation, answered by the same client handlers. - Apply the same pattern to prompts and resources —
InputRequiredResultis a result type, soprompts/getandresources/readcan ask for input identically. - Read the official spec at modelcontextprotocol.io/specification/2026-07-28 and the FastMCP elicitation docs before shipping to production.
Sources: Model Context Protocol blog, “The 2026-07-28 Specification” (SEP-2322, SEP-2577); FastMCP “User Elicitation” documentation, gofastmcp.com.
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,605 newsletter subscribers.