How to Implement MCP Elicitation in ASP.NET Core 10 Using C# – Interactive User Input, Form Validation and Secure Approval Workflows (2026)
How to Implement MCP Elicitation in ASP.NET Core 10 Using C# – Interactive User Input, Form Validation and Secure Approval Workflows (2026)
An IT support assistant receives “Office Wi-Fi disconnects.” It knows the issue title, but it still needs a category and priority. With MCP elicitation in C#, the ASP.NET Core server can ask the MCP client to collect those fields, let the user review them, and continue only after the user responds. This tutorial builds both sides of that exchange with .NET 10 and the official MCP C# SDK 2.3.1.
The example uses the 2026-07-28 protocol and Multi Round-Trip Requests (MRTR). It produces a support-ticket preview and has no database write, external help-desk integration, or model dependency. You can test accept, decline, cancel, and invalid input from a terminal before introducing a real host UI or an approval process.
What is MCP elicitation?
MCP elicitation is a server request for additional user input, presented and mediated by the MCP client during an existing operation. The server explains what it needs, the client shows who is asking and lets the user decide, and the server interprets and validates the returned response. A client can render the same request in a terminal, a chat application, or a graphical form.
| Mechanism | Who provides the input? | What is it for? |
|---|---|---|
| Tool call | A client or its agent provides arguments | Start an operation such as preparing a support ticket |
| Form elicitation | A user reviews and supplies structured values | Fill in missing ticket category and priority |
| URL elicitation | A user interacts with a consented browser destination | Complete a sensitive or out-of-band step |
| Sampling | A client obtains model-generated content | Request model output in compatible legacy integrations |
| Ordinary web form | A user submits directly to the web application | Run a browser-owned flow outside the MCP tool contract |
The MCP tool and the prompt solve different problems. The tool advertises an operation and accepts a title. The elicitation form supplies information that depends on the user’s judgment. Model output cannot substitute for a user’s review or authorization. Sampling is deprecated in the current protocol, so treat older sampling examples as compatibility material. See the official C# SDK v2 announcement and the MCP elicitation specification.
How do modern MCP round trips work?
- The client calls
preview_ticketwith a title and advertises form support. On the July 2026 protocol, capability metadata lives in_meta.io.modelcontextprotocol/clientCapabilitieson each request. - The server returns an
InputRequiredResult. The C# tool expresses this by throwingInputRequiredExceptionwith anInputRequest.ForElicitation(...)entry namedticket-formand an opaquerequestState. - The client calls its elicitation handler. The operator reviews the fields and chooses accept, decline, or cancel.
- The SDK sends a new call with the original operation,
requestState, andinputResponses. The server verifies the state and checks the matching answer.
The server can release the first HTTP request while the user is thinking. Any server instance that can verify the state can process the next request. A timeout on the client and an expiry on server state address two different failure modes. The first bounds how long the UI waits. The second bounds how long a continuation is usable. See Multi Round-Trip Requests.
Older examples use ElicitAsync as a server-to-client request on a stateful connection. The 2025-11-25 version has separate rules for initialization and callbacks. The C# SDK continues to support that API on compatible stateful sessions, such as stdio or appropriately configured stateful HTTP. Calling it on a stateless server fails. This tutorial pins the modern version so a legacy negotiation cannot quietly change the example. Compare the November 2025 spec with the current SDK elicitation guide.
What if the client does not support elicitation?
Check both protocol behavior and mode support. A missing elicitation capability means the client cannot receive the form. A URL-only capability does not imply form support. The current spec treats an explicitly empty elicitation object as form-only for backward compatibility. This tool returns a clear error for unsupported clients. Another design could offer a separate tool with explicit required arguments for noninteractive callers.
Capability checks tell you which interaction a client can render. They do not authenticate the user, authorize a write, or prove that the user has already agreed to share data.
Form mode, URL mode, and consent
Use form mode for structured, non-secret fields
Form mode uses a restricted JSON Schema subset. Use a flat object with string, number or integer, boolean, and enum fields. The protocol defines single- and multi-select enum forms and recognizes string formats such as email, uri, date, and date-time. Avoid nested objects and arbitrary arrays. The required list identifies fields needed on acceptance. Client-side validation is useful feedback. Server-side validation decides whether the values can be used. Review the exact schema rules in the requested schema section.
The sample form asks for these three values.
| Field | Required | Server rule |
|---|---|---|
category |
Yes | Exact member of network, hardware, software |
priority |
Yes | JSON integer, 1 through 3 |
note |
No | If present, text up to 120 UTF-16 code units and no control characters |
Treat the note as untrusted text. The UI should render it as text and should never interpret it as HTML, a shell command, or a new instruction to an AI system. Do not request passwords, API keys, access tokens, or payment credentials in a form. The ticket preview does not need contact details, so it asks for none.
Use URL mode for sensitive out-of-band interaction
URL mode sends a message and a URL for the client to present to the user. The client shows the requesting server and destination host, asks before navigation, and avoids prefetching or inspecting the sensitive browser interaction. Use a verified HTTPS destination. Keep credentials, personal data, and preauthenticated links out of the URL. If an external account is involved, bind the pending interaction to the authenticated user and client, verify completion independently, and reject expired or mismatched state.
Accepting a URL prompt gives the client permission to navigate. The server still needs proof that the interaction completed, such as a verified callback that consumes a short-lived nonce. A consent response alone should never commit a payment or connect an account. SDK v2 documents UrlElicitationRequiredException for URL-required interactions. Older examples use an elicitationId for their stateful protocol flow. For this version, use the current URL-mode flow and the appropriate continuation/error path. MCP OAuth protects access to the MCP server itself, while URL elicitation can guide an already connected user through a separate downstream authorization step. See URL mode security and MCP authorization.
The runnable sample implements form mode. The URL-mode diagram is a design guide. An implementation needs a real HTTPS endpoint, an authenticated browser interaction, server-side proof of completion, and tests for each failure branch.
Set up the ASP.NET Core 10 solution
Install the .NET 10 SDK and an editor. The commands use a POSIX shell with OpenSSL for generating the local lab key. NuGet access is required during restore. Start in an empty folder, then create the web project, client, and check runner.
The server uses the ASP.NET Core transport package. The console client uses Core directly. ASP.NET Core Data Protection comes from the shared ASP.NET Core framework. The sample versions are pinned so restoring the same source is reproducible. See the official SDK 2.3.1 release and Core package metadata.
Build the server, schema, and validation
Configure the HTTP endpoint and dependency injection
Replace TicketServer/Program.cs. This is a loopback-only development lab. Both processes receive a random shared key through Tickets__LabKey. The server caps request size, checks the host, rejects requests with an Origin header in this terminal-only setup, and checks the key before invoking MCP. Every accepted request uses the same lab identity. Use standard authentication and per-user authorization for remote deployment.
Validate the title and form payload
Create TicketPolicy.cs. The title is bounded and checked before prompting. After acceptance, the server validates exact names, JSON types, range, and string length. A submitted string "2" does not satisfy the integer rule. Empty optional notes can simply be omitted. Rejecting unexpected fields also prevents accidentally retaining extra data.
Bind the continuation to the caller and request
Create TicketContinuation.cs. The time-limited protector encrypts and authenticates the caller and title with a dedicated purpose. The state becomes invalid after two minutes, under the wrong identity, with an altered title, or after tampering. It can be reused within that window because the tool only produces a preview. A write would need a durable, one-time approval record, shared idempotency state, and an atomic consume-and-commit operation. If several servers handle the modern flow, configure their key rings and application isolation deliberately. See ASP.NET Core Data Protection.
Implement the support-ticket tool
Create TicketTools.cs. A call without state requests input. A call carrying continuation data must match the original title and caller, and supply exactly the ticket-form response. Accept creates the preview only after validation. Decline and cancel return distinct statuses without details. The application’s success log stores only the outcome, and tool errors use fixed messages. Configure SDK and transport logging separately and avoid collecting request bodies and authorization headers.
Build the C# client and review UI
Replace TicketClient/Program.cs. The client pins the modern protocol, advertises form support, and uses a single elicitation handler. It limits the interaction to one expected form, shows the server identity, lets the user edit the response, and requires explicit acceptance. The form UI times out after 45 seconds. The entire operation has a 60-second budget, and Ctrl+C cancels it. The caller passes cancellation through the SDK. The terminal example uses an asynchronous wait around blocking console input, so the OS read itself can persist until input arrives or the short-lived process exits.
For a full graphical client, validate the rendered schema, enforce field types and limits before submission, and present accessible review controls. This lab deliberately allows entering an invalid priority so you can see the server reject it.
Run the workflow and verify the results
Run both terminals in the project root. Export the same randomly generated key in both sessions. Keep it out of source, logs, and screenshots. Leave the server bound to loopback.
The arguments for the initial tools/call are shown below without the JSON-RPC envelope and capability metadata. The SDK assembles those pieces.
Choose edit, enter network, 2, and VPN drops, then type accept after review. The accepted form content carries the category, numeric priority, and optional note. The resulting structured content observed locally was:
| Test | Reproduce it | Outcome |
|---|---|---|
| Accept | Enter the values above and accept | JSON preview with validated fields |
| Decline | Enter decline at the first prompt |
status: declined and no preview details |
| Cancel | Enter cancel at the first prompt |
status: canceled and no preview details |
| Invalid priority | Enter 4 and accept |
Tool error and client exit code 2 |
| Unsupported | Run dotnet run --project TicketClient -- --unsupported |
Tool error before the form is shown |
| Missing authentication | Run curl -i http://127.0.0.1:5080/mcp without a key |
HTTP 401 |
A tool error can arrive within HTTP 200. Inspect the tool result and the client exit status. The transport and application operate at different layers. Use a fresh call after a validation failure. A retry is appropriate only after the invalid fields are corrected.
Run isolated policy and continuation checks
Put this code in TicketChecks/Program.cs, then run dotnet run --project TicketChecks. These checks run without the MCP transport. The scenarios above separately exercise the full loopback workflow with both SDK components.
The local build and run used .NET SDK 10.0.100 with the pinned packages. The loopback checks covered the six outcomes in the table. Browser URL completion, production OAuth, distributed key rings, and the 45-second wait were outside the executed scenarios.
Design a separate approval workflow for writes
If the next step is to create a real ticket, split preview from commitment. Start with a stable, server-generated operation ID and a preview of the exact target and payload. Require the user to review that specific action. Bind approval to the user, tenant, client, target, and operation payload. On commit, authenticate again, check the current permission and target, verify the approval has not expired, and consume it atomically with the write. Handle duplicate submissions using an idempotency key and return the existing result when appropriate.
For production, enforce HTTPS and validate token issuer, audience, expiry, and scopes. The lab key cannot distinguish two people, and the lab’s HTTP binding is suitable only for the local reproduction. Restrict where clients can navigate. Never turn a model-generated URL into an automatic browser action. Use per-user quotas and request limits, keep form contents out of logs, and document retention of approval records. If an existing web app uses JWT, the ASP.NET PB JWT authentication guide explains application authentication. Use the MCP authorization specification to design the MCP boundary.
Troubleshooting MCP elicitation
| Symptom | Check | Fix |
|---|---|---|
| Tool refuses to show a form | MRTR support and form capability | Pin the protocol for this lab and configure the elicitation handler |
ElicitAsync throws on HTTP |
Transport is stateless | Use MRTR with the current protocol |
| HTTP 401 or 403 | Lab key, host, or Origin header | Use matching keys and the fixed loopback terminal client |
| Continuation invalid | State expired, changed, or failed identity/title binding | Start a new operation and review the fresh prompt |
| Integer looks valid but fails | Payload sent a JSON string or out-of-range number | Send a whole numeric value from 1 to 3 |
| Browser tab opened but approval is pending | URL navigation was accepted, completion is unverified | Verify the browser callback and pending operation before retrying |
| Dev shell seems to hang | Console is waiting for entry | Cancel with Ctrl+C and check the deadline and process logs |
Frequently asked questions
Can I use elicitation with a tool hosted in ASP.NET Core?
Yes. Host the MCP endpoint using the C# SDK ASP.NET Core transport package. In the modern protocol, use InputRequiredException from the tool and configure the MCP client’s handler to process the form.
Does MCP elicitation work without an LLM?
Yes. The console client calls the MCP tool directly. It collects the response from the user and the server applies deterministic validation. An LLM can help decide when to call a tool, but user consent should still come through an explicit review.
What’s the difference between decline and cancel?
Decline means the user chose not to provide the requested input. Cancel means they dismissed or aborted the interaction. Both prevent a preview in this sample. The server records different outcomes so a host can show the right status.
Can I ask for an API key in a form?
No. Use a secure out-of-band flow for credentials. The server should request only the data needed for the current task, and the client should clearly identify the server and let the user decline.
Do I need a database for MRTR?
The protocol permits an opaque state value or a reference to server state. This read-only preview uses protected state. A durable approval workflow often needs a database to support audit, one-time consumption, expiry, and idempotency across instances.
Conclusion and further reading
A good elicitation flow keeps the user in control of missing information. This sample uses a short-lived continuation, checks capability before prompting, validates the response on the server, and stops at a read-only preview. Those boundaries give you a concrete starting point for adding an accessible UI or a separately authorized write.
- MCP elicitation specification, July 2026 and MRTR.
- MCP November 2025 elicitation specification and C# SDK elicitation guide.
- Microsoft’s C# SDK v2 announcement and SDK 2.3.1 release.
- MCP authorization and ASP.NET Core Data Protection.
- Build an MCP server in C# for the hosting and tool basics.
- Integrate the OpenAI API in ASP.NET Core 10 if you are building an agent that will call the MCP server.
Related follow-up tutorials could cover building an accessible schema-driven form renderer, verifying OAuth callback completion for URL elicitation, or consuming a single-use approval atomically with a help-desk write.
Comments
Post a Comment