MCP SDK for .NET 2
Last reviewed Sep 24, 2026
Prompt Details
Prompt Composition
2prompts
- C# 14106 lines · 4.4K tokens
- MCP SDK for .NET 274 lines · 3.4K tokens
Total180 lines · 7.8K tokens
CWE Coverage
- 20
- 22
- 59
- 78
- 89
- 94
- 117
- 190
- 201
- 208
- 209
- 214
- 257
- 295
- 319
- 323
- 327
- 338
- 346
- 347
- 352
- 362
- 367
- 378
- 426
- 441
- 488
- 502
- 532
- 611
- 639
- 674
- 759
- 770
- 772
- 775
- 798
- 807
- 862
- 915
- 916
- 918
- 942
- 1333
- 1395
- 1427
Prompt Preview
Apply the C# 14 prompt first. These rules cover the ModelContextProtocol 2 line: clients, hosting, ASP.NET Core transports, and optional Apps and Tasks extensions. Use C# 14 on .NET 10.
Registration and handlers
- Register reviewed tool types with
WithTools<T>()and expose only required resources, prompts, and extensions; audit every attributed method before using assembly-wide discovery. - Validate tool arguments, prompt arguments, resource URIs, pagination cursors, and domain limits inside handlers. Generated JSON schemas and
[Description]text do not enforce business constraints or object ownership. - Apply the same checks to delegates,
AIFunctiontools, custom primitives, and low-level handlers. Incoming message filters that handle a request without callingnextmust enforce authorization and validation themselves. - Treat peer instructions, descriptions, annotations, capabilities,
_meta, sampled content, app messages, and tool results as untrusted data. Authorize actions independently ofReadOnly, destructive, or idempotency hints and require approval appropriate to the actual side effects. - Scope tool lists, resource lists, prompt results, cursors, and caches to the verified principal and tenant; hiding an item from discovery never replaces access checks on a direct call.
ASP.NET Core identity
- Configure bearer authentication,
AddAuthorization(),UseAuthentication(), andUseAuthorization(); protect private endpoints withMapMcp(...).RequireAuthorization().AddMcpsupplies OAuth resource metadata and challenges and forwards