MCP Elicitation with Python SDK 2.3.0: Build Human-Approval Tools with Resolve (2026 Guide)
A tool call should not have to guess when a person needs to make the decision. Imagine an MCP server that can prepare a deployment, check a refund, or queue a destructive operation—but must stop and ask before it proceeds. That is what MCP elicitation is for: a server can request structured input from the client, and the client decides how to present that request to the user.
The important change for developers is that the current MCP protocol no longer relies on the server opening a separate request back to the client while a tool is running. With the 2026-07-28 protocol, the server returns an input-required result and the client retries the original call with the answer. The official Python SDK hides most of that protocol work behind a resolver. You write one tool and one approval model; the SDK handles the round-trip for both modern and legacy connections.
This guide builds a small release-approval MCP server with Python SDK 2.3.0. The example records an approval in memory and deliberately does not deploy anything. You can use the same pattern around a real deployment, payment, or data-management service after adding your own authentication and authorization checks.
What you will build
- An MCP tool named
request_deploymentwith a constrained service and environment. - A Pydantic approval form that the MCP client can show to a person.
- A resolver that asks for approval without exposing the approval field as model-supplied tool input.
- A client callback that handles accept, decline, cancel, and URL-mode requests safely.
- A local Streamable HTTP server and a small Python client for testing.
How elicitation works in current MCP
Elicitation is a request for additional user input during an MCP interaction. In form mode, the server supplies a human-readable message and a restricted schema. The client renders the form, lets the user review it, and sends the result back. The server must treat the response as user input—not as proof that the user is authorized to perform the requested action.
| Protocol era | How the question travels | What the Python SDK does |
|---|---|---|
| 2026-07-28 | The server returns an InputRequiredResult containing an input request. The client fulfils it and retries the original call with the response. | Resolve(...) lets the SDK create the request and drive the retry loop. |
| 2025-11-25 and earlier | The server can send an elicitation/create request over the legacy back-channel. | The same resolver is mapped to the legacy request when the connection supports it. |
For new code, prefer a resolver-backed dependency over calling ctx.elicit() directly. The direct ctx.elicit() and ctx.elicit_url() helpers are server-initiated requests and do not work on a 2026-07-28 connection, which has no server-to-client back-channel. A resolver is the era-portable path.
Prerequisites and compatibility
- Python 3.10 or newer.
- uv for project and dependency management, or an equivalent Python environment.
- MCP Python SDK 2.3.0, pinned for this tutorial.
- A terminal for running the sample server and client.
As checked on November 24, 2026, the official Python SDK GitHub releases page lists v2.3.0 as its latest release. The v2 line uses MCPServer; older v1 examples that import FastMCP or call ctx.elicit() should not be copied unchanged into this project.
Step 1: Create the project and pin the SDK
Create a new folder and install the SDK with its command-line extra:
uv init mcp-approval-demo
cd mcp-approval-demo
uv add "mcp[cli]==2.3.0"
The exact pin makes the imports and behavior in this guide reproducible. Upgrade deliberately after reading the SDK release notes and running your tests; do not silently float a production dependency to a new major version.
Step 2: Create the approval model and resolver
Create server.py. The form contains only primitive fields, which is important because MCP elicitation schemas are deliberately narrower than ordinary tool input schemas. Nested Pydantic models and arbitrary collections are not valid form fields.
from typing import Annotated, Literal
from pydantic import BaseModel, Field
from mcp.server import MCPServer
from mcp.server.mcpserver import (
AcceptedElicitation,
CancelledElicitation,
DeclinedElicitation,
Elicit,
ElicitationResult,
Resolve,
)
mcp = MCPServer("Release Approval Demo")
# Demo-only state. Replace this with a durable audit store in production.
APPROVAL_LOG: list[dict[str, str]] = []
class DeploymentApproval(BaseModel):
approved: bool = Field(
description="Approve this deployment?"
)
reason: str = Field(
default="",
description="Optional reason for the decision",
)
async def ask_for_approval(
service: str,
environment: str,
) -> Elicit[DeploymentApproval]:
# Keep this message deterministic for the same tool arguments.
return Elicit(
f"Approve deploying {service} to {environment}?",
DeploymentApproval,
)
@mcp.tool()
async def request_deployment(
service: Literal["api", "worker"],
environment: Literal["staging", "production"],
approval: Annotated[
ElicitationResult[DeploymentApproval],
Resolve(ask_for_approval),
],
) -> str:
"""Request human approval for a deployment. Demo only; it does not deploy."""
match approval:
case AcceptedElicitation(data=decision) if decision.approved:
APPROVAL_LOG.append({
"service": service,
"environment": environment,
"reason": decision.reason,
"status": "approved",
})
return (
f"Approval recorded for {service} -> {environment}. "
"Demo only: no deployment was executed."
)
case AcceptedElicitation():
return "The form was submitted, but approval was not granted."
case DeclinedElicitation():
return "The user declined the approval request. No action was taken."
case CancelledElicitation():
return "The user cancelled the approval request. No action was taken."
if __name__ == "__main__":
mcp.run(
transport="streamable-http",
host="127.0.0.1",
port=8000,
)
There are three details worth understanding:
- The resolver runs before the tool body. The SDK matches its
serviceandenvironmentparameters to the tool's validated arguments. - The approval parameter is not model-supplied. The model sees the tool's service and environment fields, but it does not get to fill the
approvaldependency itself. The resolver supplies it after the client responds. - The tool handles all three outcomes. An accepted form can still contain
approved=False. A declined request and a cancelled request are separate outcomes. Neither should trigger the protected operation.
The message is derived only from the tool arguments. Do not add a fresh timestamp, random identifier, or other changing value to the elicitation question on each retry. The SDK binds the recorded response to the question; a question that changes on every round can be treated as a different question and asked again.
Step 3: Build a client that can answer elicitation
A server cannot assume that every MCP host supports elicitation. The client must declare the capability and provide a callback. The following client uses the official SDK's Client and defaults to automatic protocol negotiation.
Create client.py:
import anyio
from mcp import Client
from mcp.client import ClientRequestContext
from mcp.types import (
ElicitRequestParams,
ElicitRequestURLParams,
ElicitResult,
)
async def answer_elicitation(
context: ClientRequestContext,
params: ElicitRequestParams,
) -> ElicitResult:
if isinstance(params, ElicitRequestURLParams):
# Never open an external URL without showing its destination
# and obtaining the user's consent.
print(f"External destination requested: {params.url}")
choice = input("Have you reviewed the URL and consent to open it? [y/N] ")
return ElicitResult(
action="accept" if choice.strip().lower() == "y" else "decline"
)
print()
print(params.message)
choice = input("Type approve, decline, or cancel: ").strip().lower()
if choice == "decline":
return ElicitResult(action="decline")
if choice == "cancel":
return ElicitResult(action="cancel")
reason = input("Reason (optional): ").strip() if choice == "approve" else ""
return ElicitResult(
action="accept",
content={
"approved": choice == "approve",
"reason": reason,
},
)
async def main() -> None:
async with Client(
"http://127.0.0.1:8000/mcp",
elicitation_callback=answer_elicitation,
) as client:
print("Negotiated protocol:", client.protocol_version)
result = await client.call_tool(
"request_deployment",
{
"service": "api",
"environment": "production",
},
)
print("Tool result:", result.content)
if __name__ == "__main__":
anyio.run(main)
The callback deliberately distinguishes the three user choices:
- Approve: submit the form with
approved=Trueand an optional reason. - Decline: return the protocol's decline action. The server receives a declined outcome.
- Cancel: return the cancel action. The server receives a cancelled outcome.
The URL-mode branch is included as a safety boundary for clients that use URL elicitation elsewhere. It displays the destination and asks for consent; it does not silently navigate. The deployment example itself uses form mode only.
Step 4: Run the server and client
Open one terminal and start the server:
uv run python server.py
Open a second terminal in the same project folder and run the client:
uv run python client.py
For an approval, the interaction should look like this (the reason and negotiated protocol depend on your choice and client):
Negotiated protocol: 2026-07-28
Approve deploying api to production?
Type approve, decline, or cancel: approve
Reason (optional): Change window approved by release manager
Tool result: [TextContent(... Approval recorded for api -> production.
Demo only: no deployment was executed. ...)]
If you type decline or cancel, the tool returns the corresponding no-action message. The sample writes an in-memory approval record only when the form is accepted with approved=True. It does not connect to Kubernetes, a cloud provider, or a CI/CD system.
Step 5: Understand what the SDK is doing for you
On a 2026-07-28 connection, the server's resolver produces an input-required response. The client callback fulfils the elicitation request, and the SDK retries the same tool call with the answer attached. The high-level Client.call_tool() method drives this loop; your application receives the final tool result rather than having to write the protocol loop itself.
The SDK bounds automatic input-required retries. Its documented default is 10 rounds. If your workflow can ask several sequential questions, design a clear upper bound and return a useful error when the interaction cannot complete.
On a legacy connection, the resolver uses the legacy elicitation request mechanism when the transport provides a back-channel. This compatibility is why the resolver is preferable to hard-coding a protocol version check in every tool.
Step 6: Test approval, decline, and cancel paths
Do not test only the happy path. At minimum, exercise these cases:
| Test | Client response | Expected tool behavior |
|---|---|---|
| Approval | Accept with approved=True | Record approval; protected action may proceed only after server-side policy checks. |
| Business rejection | Accept with approved=False | Return not approved; do not act. |
| Decline | action="decline" | Return declined; do not act. |
| Cancel | action="cancel" | Return cancelled; do not act. |
| Client has no callback | No elicitation capability declared | Expect a capability error; do not silently assume approval. |
You can also test the server in memory using Client(mcp), as shown in the SDK's testing guide. Supply an elicitation callback that returns a known answer and assert the final tool result. In-memory tests are useful for fast logic checks; keep at least one integration test against the transport and host you plan to deploy because capability negotiation and UI behavior are client-dependent.
Step 7: Choose the right resolver result type
The sample uses ElicitationResult[DeploymentApproval] because the tool needs to distinguish accepted, declined, and cancelled outcomes. If your tool should run only when a valid answer is accepted, annotate the unwrapped model instead:
approval: Annotated[
DeploymentApproval,
Resolve(ask_for_approval),
]
With the unwrapped model, the tool receives the validated model on acceptance; a decline or cancellation prevents the tool body from running and becomes an error result. Use the full ElicitationResult form when decline and cancel are normal business outcomes that your tool should handle explicitly.
Step 8: Prepare request state for multiple workers
A local single-process server can use the SDK's default request-state protection. A production deployment is different. Multi-round-trip requests may be retried as a new HTTP request. By default, the SDK creates a random request-state key when the server process starts. If the retry reaches another worker—or the original process restarts—the second process cannot verify the token.
For multiple workers or restart-surviving flows, configure the same secret key on every instance and keep the server identity consistent. Generate a 32-byte secret:
python -c "import secrets; print(secrets.token_hex(32))"
Then load the same value from a secret manager or protected environment variable on every replica:
import os
from mcp.server.mcpserver import RequestStateSecurity
state_key = bytes.fromhex(os.environ["MCP_REQUEST_STATE_KEY"])
mcp = MCPServer(
"release-approval",
request_state_security=RequestStateSecurity(
keys=[state_key],
audience="release-approval",
),
)
Do not commit the key to source control or place it in a client-visible configuration. Every replica must share the same key and audience. During rotation, deploy a verification ring that accepts the old and new keys before switching the minting key, then retire the old key only after in-flight requests have expired.
Security rules for real approval workflows
- Elicitation is not authorization. Authenticate the caller and enforce role, tenant, environment, and resource policy on the server. Never trust a tool argument or client-supplied HTTP header as the caller's identity.
- Do not ask for secrets in form mode. Passwords, API keys, access tokens, card details, and payment credentials must not be placed in a form that is exposed to the MCP client or model context. Use an out-of-band secure URL flow for sensitive interactions.
- Show the exact action. Include the target service, environment, amount, resource, or other material facts in the approval message. Do not ask users to approve a vague phrase such as “continue”.
- Make the operation idempotent. A tool may be retried after a network interruption. Use a durable operation ID and enforce one-time execution in the downstream system.
- Audit the decision. Store who approved, what they approved, the resource, the time, the outcome, and the operation ID. Keep secrets and unnecessary personal data out of the log.
- Fail closed. Missing callback, invalid schema, decline, cancellation, expired state, or authorization failure must never fall through to the protected action.
- Protect the endpoint. Use TLS and an appropriate authorization layer for remote deployments. Bind a development server to localhost; do not expose the sample approval endpoint publicly.
Troubleshooting
Elicitation not supported
The connected client did not declare the elicitation capability. Pass an elicitation_callback to the SDK Client, or use a host that supports elicitation. A decline is a valid user response; a missing capability is a protocol failure and should be handled separately.
NoBackChannelError from ctx.elicit()
You are using the legacy push-style API on a 2026-07-28 connection. Move the question into a resolver with Elicit and Resolve. Do not try to fix this by merely adding an elicitation callback—the modern protocol has no server-initiated request channel.
The form fails schema validation
Keep the elicitation model flat and use primitive fields such as strings, integers, numbers, booleans, or supported string literals. Avoid nested Pydantic models, arbitrary lists, and complex unions. Validate the model schema before connecting it to a client.
The question appears repeatedly
Make the resolver's message and schema deterministic for the same tool arguments. Avoid random IDs, current timestamps, live counters, or changing defaults inside the question. Also inspect the client's retry limit if the workflow legitimately requires several rounds.
Invalid or expired requestState
The token may have expired, been altered, been replayed with different arguments, or reached a worker that does not share the signing key and audience. For a multi-worker deployment, configure the same RequestStateSecurity keys and audience on every replica.
Frequently asked questions
Does the LLM get to approve its own tool call?
No. The resolver supplies the approval dependency, and the client callback gathers the response. The model cannot fill the dependency by adding an approval field to the tool arguments. Your server must still authenticate the caller and enforce policy independently.
Does this work with older MCP clients?
The resolver API is designed to work across the legacy 2025-era protocol and the 2026-07-28 multi-round-trip protocol. The actual interaction still depends on the client declaring and implementing elicitation support.
Can I collect an API key with the approval form?
No. Form-mode elicitation is for non-sensitive structured input. Send the user to a secure out-of-band URL for credentials or payment information, and keep those values out of the model and MCP form response.
Should I use ctx.elicit() or Resolve(Elicit(...))?
For new code, use the resolver. Direct ctx.elicit() is a legacy server-to-client request and fails on 2026-07-28 connections. The resolver lets the SDK choose the correct mechanism for the negotiated protocol.
Related GyanAangan guides
- MCP Python SDK v2.3.0 Upgrade Guide — broader SDK changes and production migration details.
- Secure Multi-Tenant MCP Servers with Python SDK 2.3.0 — OAuth, scopes, and tenant isolation.
- Build a Local Notes MCP Server in Python — a practical server and MCP Inspector starting point.
- Temporal vs Celery for AI Workflows — durable execution, retries, and approval workflows outside the MCP protocol.
- LangGraph Human-in-the-Loop Agents — a complementary agent-level approval pattern.
Primary sources and version notes
Last checked: November 24, 2026. The code in this guide is based on the official Python SDK v2.3.0 release and its tagged examples. The official release page lists v2.3.0 as the latest SDK release at the time of checking.
- MCP Python SDK v2.3.0 release notes — release date, compatibility, and changes.
- Python SDK v2.3.0 Elicitation guide — form and URL concepts, outcomes, and client callback.
- Python SDK v2.3.0 Dependencies guide —
Resolve,Elicit, and resolver behavior. - Python SDK v2.3.0 Multi-round-trip guide —
InputRequiredResult, retries, request state, and client handling. - Python SDK v2.3.0 Deploy and scale guide — shared request-state keys and multi-worker behavior.
- Python SDK v2.3.0 Running your server guide — Streamable HTTP and CLI behavior.
- MCP 2026-07-28 Elicitation specification — form and URL mode security requirements.
Limitations: This is a documentation-based implementation guide, not a claim of a live deployment test. The example is intentionally in-memory and performs no real deployment. Host support and UI presentation vary by MCP client; test against the exact host you intend to use. For a real multi-worker service, configure shared request-state keys and a consistent audience before enabling retries across replicas.
