<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba" -->

---
title: Defining MCP Tools in C#: Attributes, JSON Schema, and...
description: A practical implementation reference for defining MCP (Model Context Protocol) tools in C# using the official .NET SDK. Covers the attribute-based approach...
canonical: https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Defining MCP Tools in C#: Attributes, JSON Schema, and Error Handling | daily.dev
og:description: A practical implementation reference for defining MCP (Model Context Protocol) tools in C# using the official .NET SDK. Covers the attribute-based approach...
og:url: https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba
og:image: https://api.daily.dev/og/posts/a9g2DLMBA.png
og:image:alt: Defining MCP Tools in C#: Attributes, JSON Schema, and Error Handling
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Defining MCP Tools in C#: Attributes, JSON Schema, and Error Handling

**[We Are .NET](https://daily.dev/sources/wearedotnet)** · 16 min read · 3 upvotes · 0 comments

## Summary

A practical implementation reference for defining MCP (Model Context Protocol) tools in C# using the official .NET SDK. Covers the attribute-based approach with [McpServerToolType] and [McpServerTool], how JSON Schema 2020-12 is generated from method signatures, injecting DI services and CancellationToken (which are excluded from the schema), return type options (string, ContentBlock, CallToolResult), error handling distinctions between McpException and McpProtocolException, tool list-changed notifications and their transport constraints, and naming/description best practices that affect model behavior.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.devleader.ca/2026/07/12/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling>

## Similar posts on daily.dev

- [Build Your First MCP Server in C\# with the Official SDK](https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh) · Code with Mukesh · 16 upvotes · 1 comments
- [Your first MCP server with ASP.NET](https://daily.dev/posts/your-first-mcp-server-with-asp-net-0kwwmyuuj) · Tim Deschryver · 20 upvotes · 3 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#), [#mcp](https://daily.dev/tags/mcp), [#dependency-injection](https://daily.dev/tags/dependency-injection)

[View this post on daily.dev](https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Defining MCP Tools in C#: Attributes, JSON Schema, and Error Handling","url":"https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba"},"datePublished":"2026-07-12T22:03:27.097Z","dateModified":"2026-07-12T22:03:48.890Z","description":"A practical implementation reference for defining MCP (Model Context Protocol) tools in C# using the official .NET SDK. Covers the attribute-based approach...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0e2c5658535b42d913b205334ca85b41?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0e2c5658535b42d913b205334ca85b41?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"We Are .NET","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"We Are .NET","logo":"https://media.daily.dev/image/upload/s--BsnVOa3i--/f_auto/v1718347410/logos/wearedotnet","url":"https://daily.dev/sources/wearedotnet"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/defining-mcp-tools-in-c-attributes-json-schema-and-error-handling-a9g2dlmba","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#,mcp,dependency-injection","timeRequired":"PT16M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"We Are .NET","item":"https://daily.dev/sources/wearedotnet"},{"@type":"ListItem","position":3,"name":"Defining MCP Tools in C#: Attributes, JSON Schema, and Error Handling"}]}
```

