
Prompt Injection Through Tool Results
Text your tools return can carry instructions the model may follow. Why you can't filter that away, and how to design a C# MCP server so it can't do much harm.
BLOG
Short, practical write-ups on building AI features in C#. No roundups, no hype.

Text your tools return can carry instructions the model may follow. Why you can't filter that away, and how to design a C# MCP server so it can't do much harm.

Large tool results cost tokens and make agents worse. Cursor paging, trimmed text, aggregate tools and a size budget test for C# MCP servers.

Write tools let an agent change real data. How to design them in C#: read-only by default, no bulk actions, idempotent writes and user confirmation with MRTR.

Lock down a remote C# MCP server with ASP.NET Core: JWT and OAuth metadata, role-based tools, per-user data access, rate limits and an audit trail.

MCP gives you three primitives. The real difference is who decides to use them. How to choose between tools, resources and prompts in a C# server.

How the MCP C# SDK scopes services per request, the lifetime mistakes that break EF Core in tool calls, and the one setting that catches them early.

Test a C# MCP server the way a real client sees it: in-memory client/server tests in xUnit, one real-process smoke test, and the Inspector for manual checks.

MCP C# SDK 2.0 made HTTP servers stateless by default. What that changes, how to keep state across tool calls anyway, and when to opt back into sessions.

When a C# MCP server should run as a local stdio process and when it belongs behind Streamable HTTP, plus how to serve the same tools over both.

How the MCP C# SDK turns exceptions into tool errors, why most of them reach the model as a useless generic message, and how to write errors it can act on.

Mapping every API endpoint to an MCP tool confuses the model. Design C# MCP tools around tasks, not CRUD, and expose only what each client needs.

The model picks your MCP tools based on their descriptions alone. How to write C# tool and parameter descriptions that lead to the right tool call.

A stdio MCP server owns stdout. One stray Console.WriteLine or log line corrupts the protocol. How to route logs to stderr and debug it in .NET.

Store LLM prompts as files, version them automatically with a content hash, and log which prompt produced every answer. A simple pattern for .NET apps.

LLMs guess when your schema forces them to. Design C# types that allow "unknown", ask for evidence, and verify it in code to catch made-up answers.

Develop against a local model, run a hosted one in production. How to switch LLM providers in .NET by config, and what silently changes when you do.

Add caching, logging and tool calling to any LLM in .NET with ChatClientBuilder, and learn why the order of your middleware changes what you get back.

Use GetResponseAsync<T> in Microsoft.Extensions.AI to get typed objects from an LLM, handle bad output safely, and keep the model from guessing.

How IChatClient from Microsoft.Extensions.AI works with Ollama and OllamaSharp: first call, tokens, streaming, chat history, ChatOptions, thinking models, DI, logging, caching and switching providers.