Building an Agent-Ready Blazor App on .NET 11: MCP Tools That Wait for Your Approval
Letting a language model call your code is the easy part. The hard part is control: which calls are safe to run on their own, and which need a person to say yes. If the model can change data, a wrong guess becomes a wron
Letting a language model call your code is the easy part. The hard part is control: which calls are safe to run on their own, and which need a person to say yes. If the model can change data, a wrong guess becomes a wrong payout.
I built a small chat app on .NET 11 where a model reads commission data through an MCP server, and anything that changes data waits for the user to click Approve. This post covers the template, the tool definitions, the Blazor AI components and the approval flow, including what worked and what needed work.
π§ͺ Synthetic data only: five fictional advisors, four closed months and one open month. Tested headless against the real pipeline, in a browser with an offline stand-in model, and with a real local model (qwen2.5:7b through Ollama).
Full code:
arbabazmi
/
dotnet11-web-samples
ASP.NET Core 11 sample projects: C# 15 unions, MCP + Blazor AI, Native AOT benchmark
.NET 11 Web Samples
Three small ASP.NET Core 11 projects that try what is new on the web side of .NET 11, and write down what worked, what surprised me and what did not. All data is synthetic. Everything here was built and run on .NET SDK 11.0.100.
| # | Project | Folder | What it shows |
|---|---|---|---|
| 1 | Fee calculator API | src/FeeCalc.Api | C# 15 union types, mapped to HTTP with exhaustive switch
|
| 2 | MCP server + Blazor AI chat | src/CommissionMcp.Server, src/CommissionMcp.Web | An MCP server, and a chat page where a model calls its tools and a person approves any change |
| 3 | Native AOT benchmark | src/Aot.Bench | Cold start, memory and image size: JIT vs Native AOT on .NET 10 and .NET 11 |
Each project folder has its own README with the details, commands and findings. This page is the overview.
Prerequisites
| Needed for | Install |
|---|---|
| Everything |
.NET SDK 11.0.100 (pinned in global.json) |
| Project |
What .NET 11 gives you
Three pieces, wired together in this project:
-
An MCP server template.
dotnet new mcpserveris in the SDK (checked on SDK 11.0.100). You choose a local (stdio) or remote (HTTP) server. The remote one is stateless by default and uses the official C# MCP SDK, version 2.1.0. -
Blazor AI components. The experimental package
Microsoft.AspNetCore.Components.AI(0.1.0-preview.1) gives you a chat page that streams a response, shows tool calls, and has a block for approving a tool before it runs. -
Microsoft.Extensions.AI. The common
IChatClientinterface, plus the middleware that actually runs tool calls and asks for approval.
The design in one picture
One message, step by step:
- The user sends a message.
ChatPagehands it toUIAgent. -
UIAgentpasses the conversation to the middleware, which forwards it to the model with the tool list fromMcpToolProvider. - The model answers with text, or asks to call a tool.
- For a read-only tool, the middleware calls the MCP server and gives the result back to the model.
- For a wrapped tool, the middleware stops and raises an approval request.
UIAgentshows it as an approval block and the turn waits for the user. - Approve: the middleware calls the server. Reject: it tells the model the call was rejected and never contacts the server.
- The model writes its final answer, which streams back to the page.
Three tools, one of them dangerous
The distinction is not in the tool names. It is in the annotations each tool declares, which any MCP client can read.
| Tool | What it does | Annotations | Asks the user? |
|---|---|---|---|
get_advisor_summary(advisorId) |
Profile, YTD commission, last closed month, open-month payout | readOnly: true | No |
get_statement(advisorId, month) |
Line items, gross, adjustments, net payout for a month | readOnly: true | No |
adjust_payout(advisorId, amount, reason) |
Adds an adjustment to the open month | readOnly: false, destructive: true | Yes |
The server also protects itself: an amount must be non-zero, at most 5,000 either way, with at most two decimals, and a reason of at least five characters. Problems come back as readable tool errors, not server faults.
The key code
1. Declare what the tool is (CommissionTools.cs)
[McpServerTool(Name = "adjust_payout", ReadOnly = false, Destructive = true, Idempotent = false, OpenWorld = false)]
[Description("Changes an advisor's payout for the open month by adding an adjustment. ...")]
public Adjustment AdjustPayout(
[Description("Advisor id such as A-102")] string advisorId,
[Description("Adjustment amount in dollars, between -5000 and 5000, at most two decimals")] decimal amount,
[Description("Why the adjustment is being made (at least 5 characters)")] string reason)
=> Run(() => store.AdjustPayout(advisorId, amount, reason));
The attribute states the tool's nature. The [Description] texts are what the model reads to decide how to call it.
2. Decide who needs approval from the annotations (McpToolProvider.cs)
public static bool NeedsApproval(McpClientTool tool) => tool.ProtocolTool.Annotations?.ReadOnlyHint != true;
private static AITool Wrap(McpClientTool tool) => NeedsApproval(tool) ? new ApprovalRequiredAIFunction(tool) : tool;
An MCP tool from the C# client is already an AIFunction, so it can go straight into the chat options. Anything not explicitly read-only is wrapped in ApprovalRequiredAIFunction. A tool with no annotations at all is treated as a write tool, so forgetting an annotation fails safe.
3. Give the agent a client that can run tools (ChatClientFactory.cs and Chat.razor)
// the provider client plus the middleware that runs tool calls and raises approval requests
Create(config).AsBuilder().UseFunctionInvocation().Build();
// per conversation
_agent = new UIAgent(ChatClient, new ChatOptions { Tools = [.. tools] });
UIAgent does not run tools. It turns a streaming reply into blocks for the page. The tool loop and the approval requests come from the middleware, so leaving out UseFunctionInvocation() means tool calls are never executed.
4. Show the approval to the user (Chat.razor)
<BlockRenderer TBlock="FunctionApprovalBlock" Context="block">
<code>@block.ToolName</code>
@foreach (var arg in block.Arguments) { <dt>@arg.Key</dt><dd>@arg.Value</dd> }
@if (block.Status == ApprovalStatus.Pending)
{
<button @onclick="block.Approve">Approve</button>
<button @onclick="() => block.Reject(RejectReason)">Reject</button>
}
</BlockRenderer>
The block exposes the tool name, its arguments and a status. Reject takes a reason, which ends up in what the model is told.
Watch it work
Recorded in the running app with the offline Demo model (shown top right), against the real MCP server, the real middleware and the real Blazor AI blocks.
Approve: the change runs only after the click, and the server records adjustment ADJ-0002.
Reject: nothing reaches the server, and the model is told the call was declined.
With a real model
The offline stand-in proves the plumbing. To check a real model, the app can talk to Ollama (Chat:Provider=Ollama), which needs no key and runs on your machine. I used qwen2.5:7b. Three opt-in headless tests ran against it and passed: a read-only question, an approved change, and a rejected change.
A read-only question: the tool call is a one-line row you can open, followed by the model's summary.
A payout change waits for a click. The card shows the amount as money and says what it does. Nothing has run yet.
Two things the real model showed that the stand-in could not:
- The model asked for a lookup and a change in one step, and the framework asked approval for both, including the read-only lookup. The card now labels it as a read-only lookup asked together with the change, so you may need two clicks.
- Real models often send an empty text block before their tool calls. The page draws nothing for it.
What goes over the wire
An MCP tool call is JSON-RPC over HTTP. This is what the server returns when the amount is over the limit, captured with curl:
POST /mcp
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"adjust_payout",
"arguments":{"advisorId":"A-102","amount":9000,"reason":"Too large on purpose"}}}
result:
{"content":[{"type":"text","text":"An error occurred invoking 'adjust_payout': Amount 9000.00 exceeds the per-adjustment limit of 5000.00."}],"isError":true}
The server throws an McpException, and the SDK turns it into a normal result with isError: true. The model can read it and tell the user what went wrong.
What worked, what surprised me, what needed work
β Worked
- The template gave a working remote MCP server in one command, stateless by default.
- Approval driven by the server's read-only annotation, with no hard-coded tool names.
- Rejecting leaves data unchanged, and the model receives a clear "rejected" result.
- The Blazor AI blocks (
FunctionApprovalBlock,FunctionInvocationContentBlock) were easy to restyle.
π€ Surprised me
-
UIAgentdoes not run tools; the middleware does. -
SendMessageAsyncdoes not return until the whole turn ends, including a pending approval. - A successful tool result arrives as
TextContent; a failed one as raw MCP JSON withisError. - The preview package depends on release-candidate packages, one with a moderate security advisory.
π§ Needed work
- The docs did not show how MCP tools plug in. The path that worked is described above.
- A page-level render mode logged a Sections warning. Setting it on
RoutesandHeadOutletfixed it. - The package's chat stylesheet must be linked explicitly. Without it the input was a tiny unstyled box.
- Tests had to start the send, wait for the paused state, act, then await the send.
The numbers
- 3 MCP tools, 1 that asks for approval
- 32 tests passing (21 server, 11 web), plus 3 opt-in live-model tests
- 0 secrets in the repository
- 5 fictional advisors, synthetic data only
The chat-flow tests drive the real UIAgent against the real MCP server: a read-only question, a write that pauses and changes nothing until approved, a rejection, an approved call the server refuses, and a follow-up that reuses the advisor from an earlier turn.
What this does not prove yet
- One real model, one size. Only qwen2.5:7b through Ollama was tried. Larger or hosted models may choose different tools or arguments. The approval code does not depend on which model is behind it.
- The real-model Approve click in the browser is unverified. The real model asked for two approvals and my script clicked only the first, so that run timed out. Approve and Reject were verified in the browser with the offline model, and with the real model in headless tests.
- The components are experimental (0.1.0-preview.1). Names and behaviour may change.
-
No second MCP client demo yet. The server was called with the C# client and with
curl, not with a separate app such as the MCP Inspector.
Run it yourself
Needs the .NET 11 SDK. Code is in src/CommissionMcp.Server and src/CommissionMcp.Web.
git clone https://github.com/arbabazmi/dotnet11-web-samples
cd dotnet11-web-samples
dotnet run --project src/CommissionMcp.Server --urls http://localhost:5290
# in a second terminal:
dotnet run --project src/CommissionMcp.Web --urls http://localhost:5005
# open http://localhost:5005
With no setup the app uses the offline Demo model. For a local model, install Ollama, run ollama pull qwen2.5:7b, and set Chat:Provider=Ollama and Chat:Model=qwen2.5:7b. For a hosted model, set Chat:Provider, Chat:Model and Chat:ApiKey with dotnet user-secrets; any OpenAI-compatible endpoint works.
β οΈ Don't start the web app with --no-launch-profile: that runs it in Production, which doesn't serve the page scripts and styles.
How are you handling human approval for agent tool calls? Annotations, hard-coded allow-lists, or something else? I'd like to hear in the comments.
Versions: .NET SDK 11.0.100, ModelContextProtocol 2.1.0, Microsoft.AspNetCore.Components.AI 0.1.0-preview.1, Microsoft.Extensions.AI 11.0.1. Synthetic data only.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.




