A .NET MCP tool class can fail because the server never discovers or registers it, because the tool method throws when called, or because the transport and client do not match. The SDK’s supported pattern uses [McpServerToolType] on the class and [McpServerTool] on each exposed method, then registers the type explicitly or scans its assembly. There is no verified universal “two-line fix” for this title: the exact change depends on the exception, failure stage, and SDK version.
How attribute-based tool discovery works
The official MCP C# SDK uses attributes to identify tool types and methods. Mark the containing class with [McpServerToolType], and mark each method to expose with [McpServerTool]. A method can also include a Description attribute to describe the tool.
As an Amazon Associate I earn from qualifying purchases.
[McpServerToolType]
public class MyTools
{
[McpServerTool, Description("Echoes the input message back")]
public static string Echo(string message) => $"Echo: {message}";
}
This example follows the official SDK tool guide. The attributes identify candidates; the server configuration must also register the type or discover it through assembly scanning.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRegister the tool type or scan its assembly
Explicit registration for a known type
For a small server with tools in the server project, explicitly registering the type makes the discovery scope clear. The SDK guide shows this configuration shape:
#1 Best Overall
builder.Services.AddMcpServer()
.WithHttpTransport(o => o.Stateless = true)
.WithTools<MyTools>();
The important registration call here is .WithTools<MyTools>(). The HTTP transport options are part of the documented example, not a required setting for every server.
Assembly scanning for tools grouped elsewhere
If tool classes live in the assembly being scanned, .WithToolsFromAssembly() discovers classes marked with [McpServerToolType] and registers their methods marked with [McpServerTool]. The SDK getting-started guide demonstrates scanning in a stdio server, using AddMcpServer(), WithStdioServerTransport(), and WithToolsFromAssembly().
Rank #2
Choose explicit registration when you want to name a specific type; choose assembly scanning when the server should discover marked tools from an assembly. Neither approach is documented as universally faster or safer. If tools are in a separate assembly, confirm that the scan targets the assembly containing those types.
Recommended Free Tools
Dependency injection is supported, but it is not by itself a diagnosis
Tool methods can accept services registered through dependency injection as parameters. That capability means a service parameter alone does not establish why a class crashed. If the failure happens while an instance tool is being created, inspect the constructor, service registrations, and actual exception. The SDK also supports class/type and factory registration approaches; the static example above does not mean all valid tool methods must be static.
Pin down when the failure occurs
Capture the complete exception and stack trace, then identify whether the failure occurs during startup, when a tool call runs, or while the client connects. These stages point to different checks.
Server startup or tool-list construction
- Check the installed SDK package and version, and confirm the relevant SDK namespace and attributes are in use.
- Verify that the tool class has
[McpServerToolType]and that each intended method has[McpServerTool]. - Confirm that configuration calls
.WithTools<YourToolType>()or scans the assembly containing the tool class with.WithToolsFromAssembly().
Failure during a tool call
- Check whether the incoming JSON arguments bind to the method’s parameters.
- Inspect exceptions raised by the tool method and any injected services it uses.
The SDK documentation describes invocation errors separately from registration. It says ordinary exceptions become tool error results, while protocol exceptions have distinct JSON-RPC behavior; that information does not identify the cause of a particular crash.
Rank #4
Transport or client connection failure
Check transport configuration and the client’s matching endpoint or connection setup independently of tool discovery. The getting-started guide shows separate stdio and HTTP setup paths. A connection problem does not, on its own, show that the tool class or its attributes are the cause.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Check the SDK version before applying version-specific advice
Microsoft announced the official MCP C# SDK v2.0 on July 28, 2026, describing it as implementing the 2026-07-28 revision of the MCP specification. The announcement says stable v1 code continues to compile and run after upgrading. It lists v2 target frameworks as net8.0, net9.0, net10.0, and netstandard2.0, and identifies ModelContextProtocol for hosted or stdio use, ModelContextProtocol.AspNetCore for HTTP servers, and ModelContextProtocol.Core for client or low-level APIs. Check the project’s installed package and the applicable release notes before following version-specific instructions.
Best Value
What evidence is needed to identify the two-line fix?
The official guidance establishes how to mark and register tool classes, but it does not tie this title’s runtime crash to a specific SDK defect or reproducible two-line patch. To identify a precise fix, you need the affected SDK version, the relevant code, the full exception and stack trace, and a minimal reproduction or an authoritative issue or release note. Without those details, changing an attribute, adding static, altering a constructor, or adding a registration call would be a guess rather than a diagnosis.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




