agentleFS
MicrosoftKnown publishermicrosoft/mcp-dotnet-samples/AGENTS.md

mcp-dotnet-samples

AGENTS.md198 starsChanged 15 months agoMITView on GitHub

The Model Context Protocol (MCP) .NET Samples repository demonstrates how to build MCP servers using .NET 9.0. This repository contains four comprehensive sample implementations that showcase different aspects of MCP server development, from GitHub integration to web services, data management, and email communications.

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

13 rules. About 0 are common, 12 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Search and retrieve GitHub Copilot instructions

    line 45
  2. Distinctive:

    Create, read, update, delete operations

    line 71
  3. Distinctive:

    Use dependency injection for all services

    line 125
  4. Distinctive:

    Follow the MCP protocol specifications

    line 127
  5. Distinctive:

    Use consistent parameter naming and descriptions

    line 161
  6. Distinctive:

    Follow Azure naming conventions with abbreviations file

    line 163
  7. Distinctive:

    Test MCP server initialization and registration

    line 210
  8. Distinctive:

    Verify tool and prompt functionality end-to-end

    line 211
  9. Distinctive:

    Test error handling and edge cases

    line 212
  10. Distinctive:

    Follow conventional commit format:

    line 271
  11. Distinctive:

    Start Development: Use VS Code with MCP integration

    line 297
  12. Very specific:

    Use azd up for automated deployment

    line 313
  13. Distinctive:

    Use structured logging with ILogger

    line 325

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md - MCP .NET Samples

Project Overview

The Model Context Protocol (MCP) .NET Samples repository demonstrates how to build MCP servers using .NET 9.0. This repository contains four comprehensive sample implementations that showcase different aspects of MCP server development, from GitHub integration to web services, data management, and email communications.

Project Structure and Architecture

Repository Organization

mcp-dotnet-samples/
├── .github/                    # GitHub configuration and workflows
│   ├── workflows/             # CI/CD pipeline definitions
│   ├── copilot-instructions.md # GitHub Copilot coding standards
│   └── templates/             # Issue and PR templates
├── shared/                    # Common shared libraries
│   └── McpSamples.Shared/     # Shared MCP implementation utilities
├── awesome-copilot/           # GitHub Copilot integration sample
│   ├── src/McpSamples.AwesomeCopilot.HybridApp/
│   ├── infra/                 # Azure Bicep templates
│   └── .vscode/              # VS Code MCP configuration
├── markdown-to-html/          # Markdown conversion sample
│   ├── src/McpSamples.MarkdownToHtml.HybridApp/
│   ├── infra/                 # Azure Bicep templates
│   └── .vscode/              # VS Code MCP configuration
├── outlook-email/             # Email communication sample
│   ├── src/McpSamples.OutlookEmail.HybridApp/
│   ├── infra/                 # Azure Bicep templates
│   └── .vscode/              # VS Code MCP configuration
├── todo-list/                 # Todo management sample
│   ├── src/McpSamples.TodoList.HybridApp/
│   ├── infra/                 # Azure Bicep templates
│   └── .vscode/              # VS Code MCP configuration
├── Dockerfile.*              # Multi-stage Docker configurations
├── Directory.Build.props     # Global MSBuild properties
└── global.json              # .NET SDK configuration

Sample Components

1. Awesome Copilot Sample

  • Purpose: Integrates with GitHub's awesome-copilot repository to provide Copilot customizations
  • Key Features:
    • Search and retrieve GitHub Copilot instructions
    • File metadata processing
    • JSON-based configuration management
  • Technologies: File I/O, HTTP clients, JSON processing

2. Markdown to HTML Sample

  • Purpose: Converts Markdown content to HTML with customizable options
  • Key Features:
    • Markdown parsing and HTML generation
    • Configurable HTML output options
    • Azure integration for scalable processing
  • Technologies: Markdown processing, HTML generation, web services

3. Outlook Email Sample

  • Purpose: Sends emails through Outlook with comprehensive authentication scenarios
  • Key Features:
    • Email sending capabilities via Microsoft Graph API
    • OAuth authentication with Azure API Management
    • API key authentication with Azure Functions
    • No-authentication local development mode
    • Azure Functions and Container Apps deployment support
  • Technologies: Microsoft Graph, OAuth, Azure Functions, API Management

4. Todo List Sample

  • Purpose: Manages todo items with full CRUD operations
  • Key Features:
    • Create, read, update, delete operations
    • Data persistence
    • RESTful API patterns
  • Technologies: Data management, API development, persistence

Coding Conventions and Standards

C# and .NET Standards

Language and Framework

  • Target Framework: .NET 9.0 (as specified in Directory.Build.props)
  • Language Version: Latest C# features enabled
  • Nullable Reference Types: Enabled for all projects
  • Implicit Global Usings: Enabled to reduce boilerplate

Code Organization

// Namespace structure
namespace McpSamples.{SampleName}.{ComponentType};

// Class organization
public class ExampleMcpServer : IMcpServer
{
    // Private readonly fields first
    private readonly ILogger<ExampleMcpServer> _logger;
    
    // Constructor
    public ExampleMcpServer(ILogger<ExampleMcpServer> logger)
    {
        _logger = logger;
    }
    
    // Public methods
    [McpServerTool(Name = "example_tool")]
    [Description("Example tool implementation")]
    public async Task<string> ExampleToolAsync(
        [Description("Input parameter")] string input)
    {
        // Implementation
    }
}

Naming Conventions

  • Classes: PascalCase with descriptive names
  • Methods: PascalCase with verb-noun pattern
  • Properties: PascalCase
  • Private Fields: _camelCase with underscore prefix
  • Parameters: camelCase
  • Constants: UPPER_SNAKE_CASE

MCP Server Development Standards

Server Registration

  • Use dependency injection for all services
  • Implement proper lifetime management
  • Follow the MCP protocol specifications

Tool Implementation

[McpServerTool(Name = "tool_name")]
[Description("Clear description of what the tool does")]
public async Task<ToolResult> ToolNameAsync(
    [Description("Parameter description")] string parameter)
{
    // Validate input
    if (string.IsNullOrWhiteSpace(parameter))
        throw new ArgumentException("Parameter cannot be null or empty");
    
    // Implement functionality
    var result = await ProcessAsync(parameter);
    
    // Return structured result
    return new ToolResult { Content = result };
}

Prompt Implementation

[McpServerPrompt(Name = "prompt_name", Title = "Human-readable title")]
[Description("Description of the prompt's purpose")]
public string GetPrompt([Description("Context parameter")] string context)
{
    return $"Structured prompt template with {context}";
}

Azure and Infrastructure Standards

Bicep Template Organization

  • Use consistent parameter naming and descriptions
  • Implement proper resource tagging
  • Follow Azure naming conventions with abbreviations file
  • Include monitoring and security configurations

Container Configuration

  • Multi-stage Docker builds for optimization
  • Proper health check implementations
  • Environment variable configuration
  • Security scanning and minimal base images

Testing Protocols and Guidelines

Unit Testing Framework

  • Framework: MSTest or xUnit (depending on sample requirements)
  • Mocking: Moq for dependency mocking
  • Coverage: Minimum 80% code coverage for business logic

Test Structure

[TestClass]
public class ExampleMcpServerTests
{
    private readonly Mock<ILogger<ExampleMcpServer>> _mockLogger;
    private readonly ExampleMcpServer _server;
    
    public ExampleMcpServerTests()
    {
        _mockLogger = new Mock<ILogger<ExampleMcpServer>>();
        _server = new ExampleMcpServer(_mockLogger.Object);
    }
    
    [TestMethod]
    public async Task ExampleTool_WithValidInput_ReturnsExpectedResult()
    {
        // Arrange
        var input = "test input";
        var expectedOutput = "expected result";
        
        // Act
        var result = await _server.ExampleToolAsync(input);
        
        // Assert
        Assert.AreEqual(expectedOutput, result.Content);
    }
}

Integration Testing

  • Test MCP server initialization and registration
  • Verify tool and prompt functionality end-to-end
  • Test error handling and edge cases
  • Validate Azure deployment configurations

Running Tests

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run specific test project
dotnet test ./tests/McpSamples.{Sample}.Tests/

Pull Request Guidelines and Workflow

Branch Naming Convention

  • feature/description-of-feature
  • bugfix/description-of-fix
  • docs/description-of-documentation-change

PR Requirements Checklist

  • Code Quality: Follows established coding standards
  • Tests: Includes appropriate unit and integration tests
  • Documentation: Updates relevant documentation
  • Build: Successfully builds with .NET 9.0
  • Azure: Infrastructure changes are validated
  • Security: No hardcoded secrets or vulnerabilities
  • Performance: No significant performance regressions
  • MCP Compliance: Follows MCP protocol specifications

PR Description Template

## Summary
Brief description of the changes made.

## Changes Made
- List specific changes
- Include any new features or modifications
- Mention any removed functionality

## Testing Performed
- Unit tests: [Pass/Fail]
- Integration tests: [Pass/Fail]
- Manual testing: [Description]
- Azure deployment: [Validated/Not applicable]

## Breaking Changes
List any breaking changes or migration requirements.

## Screenshots
Include screenshots for UI changes (if applicable).

## Additional Notes
Any additional context or considerations for reviewers.

Commit Message Format

Follow conventional commit format:

type(scope): description

feat(awesome-copilot): add search functionality for instructions
fix(shared): resolve MCP server initialization issue  
docs(readme): update installation instructions
refactor(todo-list): optimize data access patterns
test(markdown): add unit tests for HTML conversion

Development Environment Setup

Prerequisites

  • .NET 9.0 SDK
  • Visual Studio Code with C# Dev Kit extension
  • Docker Desktop for containerization
  • Azure CLI for Azure operations
  • Azure Developer CLI (azd) for deployment

Local Development Workflow

  1. Clone Repository: git clone <repository-url>
  2. Install Dependencies: dotnet restore
  3. Build Solution: dotnet build
  4. Run Tests: dotnet test
  5. Configure MCP: Copy appropriate .vscode/mcp.json configuration
  6. Start Development: Use VS Code with MCP integration

VS Code Configuration

Each sample includes pre-configured VS Code settings for MCP integration:

  • .vscode/mcp.stdio.local.json - Local STDIO communication
  • .vscode/mcp.http.local.json - Local HTTP communication
  • .vscode/mcp.stdio.container.json - Container-based STDIO

The outlook-email sample includes additional configurations for:

  • .vscode/mcp.http.local-func.json - Local Azure Functions
  • .vscode/mcp.http.remote-func.json - Remote Azure Functions
  • .vscode/mcp.http.remote-apim.json - Azure API Management integration

Deployment and Operations

Azure Deployment

  • Use azd up for automated deployment
  • Configure environment variables appropriately
  • Monitor applications using Application Insights
  • Implement proper logging and error handling

Container Operations

  • Build containers using provided Dockerfiles
  • Tag images appropriately for Azure Container Registry
  • Configure health checks and resource limits
  • Implement graceful shutdown handling

Monitoring and Observability

  • Use structured logging with ILogger
  • Implement Application Insights telemetry
  • Monitor MCP server performance and usage
  • Set up alerts for critical failures

This document serves as the primary reference for development practices and standards within the MCP .NET Samples repository. All contributors should familiarize themselves with these guidelines to ensure consistency and quality across the codebase.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.