Sr. Content Developer at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
159978 stories
·
33 followers

Building your first MCP server in ASP.NET Core

1 Share

This blog post is originally published on https://blog.elmah.io/building-your-first-mcp-server-in-asp-net-core/

Artificial Intelligence is no longer limited to answering questions. It can now interact with applications, retrieve data, and perform real tasks. In fact, tons of applications are already doing this. But for AI assistants to communicate with your software, they need a common language. The standard communication is Model Context Protocol (MCP). As the name suggests, it allows AI clients, such as ChatGPT, Claude, and Visual Studio Code, to discover and invoke tools exposed by your application. Instead of building custom integrations for every AI platform, you expose your application's capabilities once, and any MCP-compatible client can use them. In today's post, I will share how to build our first MCP server in ASP.NET Core, create a small book catalog, expose several MCP tools, and test them.

Building your first MCP server in ASP.NET Core

What is Model Context Protocol (MCP)?

Model Context Protocol (MCP) is an open standard created by Anthropic that provides a standard way for AI models to communicate with external tools and applications. MCP standardizes communication between AI clients and applications. Every MCP-compatible client speaks the same protocol. You implement your tools once, and any MCP client can discover and use them. Without MCP, each model can have different request formats, authentication methods, and tool descriptions.

Designing an MCP server in ASP.NET Core API

Let's jump right in and create our first MCP server.

Step 1: Create project

dotnet new webapi -n MCPPlayground

Step 2: Install MCP package

dotnet add package ModelContextProtocol.AspNetCore

The package enables the project to act as an MCP server.

Step 3: Create model

namespace MCPPlayground.Models;
public record Book(
    int Id,
    string Title,
    string Author,
    int Year,
    bool IsAvailable
);

To keep it simple, I am using a value-type record. But for a production-grade application, know your requirements.

Step 4: Add a repository

Let's add a repository with in-memory data.

using MCPPlayground.Models;

namespace MCPPlayground.Data;

public class BookRepo
{
    private readonly List<Book> _books =
    [
        new(1, "Clean Code", "Robert C. Martin", 2008, true),
        new(2, "The Pragmatic Programmer", "Andrew Hunt", 1999, false),
        new(3, "Design Patterns", "Erich Gamma", 1994, true),
        new(4, "Domain-Driven Design", "Eric Evans", 2003, true),
        new(5, "Refactoring", "Martin Fowler", 2018, false)
    ];

    public List<Book> GetAll() => _books;

    public Book? GetById(int id)
        => _books.FirstOrDefault(x => x.Id == id);

    public List<Book> Search(string keyword)
        => _books
            .Where(x =>
                x.Title.Contains(keyword, StringComparison.OrdinalIgnoreCase)
                    || x.Author.Contains(keyword, StringComparison.OrdinalIgnoreCase))
            .ToList();
}

I am exposing 3 methods from the repo. Don't forget to add dependency injection in Program.cs:

builder.Services.AddSingleton<BookRepo>();

Step 5: Create MCP tools

using MCPPlayground.Data;
using MCPPlayground.Models;
using ModelContextProtocol.Server;

namespace MCPPlayground.Tools;

[McpServerToolType]
public class BookTools(BookRepo repository)
{
    [McpServerTool]
    public IEnumerable<Book> GetAllBooks()
    {
        return repository.GetAll();
    }

    [McpServerTool]
    public Book? GetBookById(int id)
    {
        return repository.GetById(id);
    }

    [McpServerTool]
    public IEnumerable<Book> SearchBooks(string keyword)
    {
        return repository.Search(keyword);
    }
}

[McpServerToolType] marks the class as containing MCP tools. While [McpServerTool] marks a method that AI clients can invoke. Any method parameters automatically become tool inputs. C# method names are converted to MCP names like get_all_books if no custom name is specified for [McpServerTool].

Step 6: Setup MCP server configuration

Add MCP configuration in Program.cs:

builder.Services
    .AddMcpServer()
    .WithHttpTransport()
    .WithToolsFromAssembly();

Use the MapMcp method to map the /mcp URL which is the endpoint the AI clients are going to communicate with:

app.MapMcp("/mcp");

The final look of the file is;

using MCPPlayground.Data;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddMcpServer()
    .WithHttpTransport()
    .WithToolsFromAssembly();

builder.Services.AddOpenApi();

builder.Services.AddSingleton<BookRepo>();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
}

app.UseHttpsRedirection();
app.MapMcp("/mcp");
app.Run();

Step 7: Run the project

dotnet run

The project is running and listening at http://localhost:5082/mcp

Unlike APIs, where you manually call REST endpoints, the MCP server allows AI models to discover and call the tools. I will use the MCP Inspector to test, which will automatically discover available tools from the server. Simply select a tool, provide its arguments, and execute it. This mirrors how AI assistants such as Cursor or Claude discover and invoke an application's capabilities through Model Context Protocol.

MCP flow

Step 8: Install MCP inspector

For the MCP inspector, you need to have Node.js. Check if node and npm is installed by running:

node -v
npm -v

If not already installed, go to the official website: https://nodejs.org. Download the LTS (Long Term Support) version. Once the download completes:

  • Run the installer.
  • Click Next until installation completes.
  • Keep "Add to PATH" checked (default).
  • Finish the installation.

Verify the installation:

node -v
npm -v

Then run the following in a new terminal:

npx @modelcontextprotocol/inspector@latest

This will install and run the latest version of the inspector:

Console

When the inspector is running, the browser opens up the UI:

MCP inspector

Step 9: Test the MCP server

Add a new server for our application:

Adding a server

You can use the following configuration for the server:

Adding server

Make sure to turn the connected toggle button on:

Server

All the tools I designed will be visible in the tools window:

Tools

Calling the get_all_books tool:

Result

Will show the in-memory data from the repository:

Result

Another tool get_book_by_id:

get by id method

Will show a single book from the repository:

Results

We can also search book sby the keyword parameter:

search method

The data is fetched successfully:

Result

Step 10: Add descriptions to the tools

To better define each tool for AI model integration, it is recommended to add descriptions:

using System.ComponentModel;
using MCPPlayground.Data;
using MCPPlayground.Models;
using ModelContextProtocol.Server;

namespace MCPPlayground.Tools;

[McpServerToolType]
public class BookTools(BookRepo repository)
{
    [McpServerTool]
    [Description("Returns all books available in the library.")]
    public IEnumerable<Book> GetAllBooks()
    {
        return repository.GetAll();
    }

    [McpServerTool]
    [Description("Returns a single book by its unique identifier.")]
    public Book? GetBookById(
        [Description("The unique ID of the book.")] int id)
    {
        return repository.GetById(id);
    }

    [McpServerTool]
    [Description("Searches books by title or author.")]
    public IEnumerable<Book> SearchBooks(
        [Description("A keyword to search in the book title or author name.")] string keyword)
    {
        return repository.Search(keyword);
    }
}

The descriptions are visible in the inspector:

get all

That's it. We have now developed our first MCP server using ASP.NET Core and the ModelContextProtocol.AspNetCore NuGet package. In this post, I focused on testing the tools through the inspector. But in real life, your tools will be called from an AI client. How you set up an MCP server in your favorite client depends on what client you use. As an example, you would use the following command for Claude:

claude mcp add --transport http book-mcp http://localhost:5082/mcp

Conclusion

As AI assistants become part of everyday development, one challenge quickly appears: how should an AI securely and consistently interact with your applications? In this post, I tackled this question by guiding you on how to design an MCP server in ASP.NET Core, which is surprisingly straightforward. With just a few configuration lines and a couple of attributes, you can expose your application's capabilities as AI-callable tools.

As applications adopt more AI, learning how to build MCP servers will become an increasingly valuable skill for .NET developers. Whether you're integrating AI into internal business systems or creating intelligent developer tools, MCP serves as a standardized and extensible foundation for connecting language models to real-world functionality. Something we are already fully utilizing on elmah.io's MCP server.

Code: https://github.com/elmahio-blog/MCPPlayground.git



Read the whole story
alvinashcraft
just a second ago
reply
Pennsylvania, USA
Share this story
Delete

Sysinternals Autoruns 13.100 is last working final version for Windows 7

1 Share

By Mark Russinovich




Published:   -  2.61 MB

v13.99 no longer works on Windows 7.  You'll get the following error

---------------------------
autoruns.exe - Entry Point Not Found
---------------------------
The procedure entry point GetProcessInformation could not be located
in the dynamic link library KERNEL32.dll. 
---------------------------
OK   
---------------------------


Function GetProcessInformation was introduced in Windows 10 (1607), eventhougth the function definitions say's otherwise GetProcessInformation function (processthreadsapi.h) - Win32 apps | Microsoft Learn, introduced for Win8.



Launch most recent and correct version every time with 👉 Clipboard Plaintext Power Tool: 20+ Power Tools 😎


Why drop support for Windows 7 when?

Windows OS has over 1.5 billion active users globally as of 2025, and @2.5% thus 37.5 million are still active Windows 7 users! 










Last working version on Windows 7

The last good know version to work on Windows 7 is Process Explorer v17.06 back in 28 May 2024. 

Get it here Autoruns 13.000 Wayback Machine (archive.org) 

Read the whole story
alvinashcraft
14 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Hands on: How to Bring Your Own Local AI Model to Visual Studio Insiders (Preview)

1 Share
Visual Studio 18.10 Insiders can connect its new Agent directly to locally running AI models, but my test showed that getting a model into the IDE and getting frontier-model performance from it are two different things.
Read the whole story
alvinashcraft
34 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

.NET Conf 2026

1 Share

.NET Conf 2026 banner

Hey .NET Fans! It’s that time of year again: .NET Conf is back November 10-12, 2026.

We’ll spend three days learning from the people who build and use .NET, catching up with the community, and launching .NET 11. The event is free and online, so mark your calendar and join us from wherever you are.

Get ready for the release of .NET 11

We’ve been busy building .NET 11, and there’s already plenty to try. The latest previews include work across the runtime, libraries, SDK, ASP.NET Core, C#, .NET MAUI, Entity Framework Core, and more. We’re especially excited about C# 15 union types and the move to CoreCLR for .NET MAUI apps on Android, iOS, and Mac Catalyst. ASP.NET Core and Blazor also have a lot in store, including richer static SSR and form validation, smaller Blazor WebAssembly apps, a new development server, and smoother Aspire integration. Minimal APIs gain async validation and C# union type support, and OpenAPI 3.2 is now the default. Alongside the .NET 11 work, we’ve also released v2.0 of the official MCP C# SDK, with a stateless-by-default protocol designed to make building and scaling AI tools with ASP.NET Core more straightforward.

Catch up on what we’ve shared so far:

You can also hear directly from the teams in recent .NET Community Standups. There’s more on the way between now and November. We think you’re going to love what the teams have been working on, and we can’t wait to show you the rest at .NET Conf.

Schedule coming soon

We’re hard at work putting the product team schedule together. When the conference site and session list go live, we’ll publish those sessions on our new https://dot.net/conf mini-site and on the community-run https://dotnetconf.net site.

Interested in speaking?

We know you’re eager to submit your community sessions, and we hope to open the call for speakers within the next week. When it opens, we’ll share the news here on the .NET Blog, on both conference sites, and through our social channels. We’ll add selected community sessions to the schedule later.

For now, save November 10-12 and start thinking about what you might want to share. We’re excited to get the .NET community together again.

The post .NET Conf 2026 appeared first on .NET Blog.

Read the whole story
alvinashcraft
42 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Start here: Azure SQL Foundations series

1 Share

Most developers I talk to aren’t asking whether Azure SQL Database can handle their next app. They’re asking where to start when it comes to modernization, migration, and AI in the database. If you’re reading this, you’re probably in a similar boat: you’ve got an existing schema or databases, a scaling question you haven’t had to answer yet, and a growing list of AI features you’re expected to have an opinion about.

Azure SQL Foundations Social Card1 image

That’s why we built the path we kept describing in calls, with customers, and in the community. The Azure SQL Database Foundations series are four videos that take you from your first Hyperscale database to AI features running against your own operational data. We also included how to assess and migrate (with AI and skills!) to Hyperscale in the first place, and the common optimizations you should consider. Every episode ships with a repo, so you can follow along in your own environment instead of watching someone else’s terminal.

The series

# Video What you’ll get out of it
1 Get started with Azure SQL Database Hyperscale How Hyperscale handles AI and analytics workloads on the SQL foundation you already know.
2 Migrate and optimize with Azure SQL Database Hyperscale Migration in action. Modernize your SQL environment with AI and without application rewrites.
3 Optimize scale and performance with Azure SQL Database Hyperscale Scale compute and storage independently, and tune for your actual workload.
4 Bring AI into your apps with Azure SQL Database Hyperscale Build agentic AI apps with vector, RAG, and LLMs without moving data between systems.

Watch the series: https://aka.ms/azuresqlfoundationseries

Get the repos: https://aka.ms/azuresqlfoundations

Then go deeper with the Developer Guide

The Azure SQL Foundation Series - Developer Guide

The Azure SQL Database Foundations: Developer Guide picks up where the videos leave off, with GitHub repos for each section. Three things it covers:

  1. Deploy databases using modern DevOps practices. Provision and automate with Azure CLI, PowerShell, Bicep, ARM templates, and Terraform.
  2. Build AI-ready apps on operational data. Vector search and RAG, with Azure OpenAI, Semantic Kernel, LangChain, Azure AI Search, and Microsoft Fabric.
  3. Ship faster with modern data APIs. Data API Builder, SQL MCP Server, JSON support, and recent T-SQL enhancements.

Next steps

 

The post Start here: Azure SQL Foundations series appeared first on Microsoft for Developers.

Read the whole story
alvinashcraft
47 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Visual Studio August Update — Work Smarter Across Models and Branches

1 Share

The August update gives you more control over two parts of development that can get complicated quickly: choosing the right level of AI assistance and managing work across Git branches and repositories. You can now tune model thinking effort for the task in front of you, share custom agents across your organization, and see your Copilot usage without breaking your flow. Git workflows get a meaningful upgrade too. Worktrees let you keep multiple branches active at once, while first-class submodule support brings common management tasks directly into Visual Studio. Grab the Visual Studio 2026 Stable Channel update and dig into what is below.

Adjust model thinking effort to match your task Not every question needs the same amount of reasoning. For supported models, you can now set thinking effort to

Low, Medium, or High, balancing response depth, speed, and token usage around the work you are doing. Use Low for straightforward questions and code suggestions, Medium for everyday development, and High when you are working through a tricky algorithm, architecture decision, or hard-to-debug problem. You can adjust the setting from the Model picker or the expanded Language Models view. Thinking effort controls showing the medium setting for supported models

Organization-level custom agents Teams can now share custom agents across repositories instead of configuring the same specialized help one project at a time. GitHub organization and enterprise owners can publish agents for everyone in the organization, helping Copilot follow shared workflows and expectations more consistently. Visual Studio automatically detects organization-level agents when you work in an eligible repository and adds them to the

agent picker. Hover over an agent to see its description and organization source, or select the definition button to open its definition file. This functionality requires a GitHub organization. Copilot agent picker showing an organization agent, its description, and the button that opens its definition

Access your Copilot usage Curious how much of your Copilot plan you have used? Open the context window from the prompt box, then select

View all Copilot usage to jump to your full plan details. Usage notifications are easier to act on too, so you will know when you are close to your limit and what options you have to keep working. It is a small change that puts useful information closer to the moment you need it. Copilot context window with the usage button highlighted and a tooltip for viewing all Copilot usage

Worktrees: work on multiple branches at once Ever stashed half-finished work just to investigate another branch?

Git worktree support gives each branch its own working directory, so your current changes stay in place while you switch to another task. In the Git Repository window, right-click a branch and select New Worktree From. You can create the worktree from a new or existing branch, or start from a commit in the history graph. Open it in the current window or a new Visual Studio instance when you want both branches side by side. When the extra working directory is no longer needed, right-click it and select Delete Worktree. Worktree context menu with commands to create, open, and delete a worktree Your worktrees appear alongside branches in the Git Repository window, branch picker, and repository picker. Git Repository window showing active branches and detached worktrees in the branch tree

Git submodule support One of our

most requested Git improvements is here. Visual Studio now gives submodules a dedicated section in the Git Repository window, better visibility in Git Changes, and a repository picker that clearly shows the parent-child hierarchy. From the Submodules section, you can add, update, and delete submodules. Visual Studio discovers them automatically when you open a solution or folder and keeps them out of the general local repositories list, reducing clutter. Git Repository window with a Submodules section and commands to update or delete a selected submodule Submodules are read-only by default. To make changes inside them, go to Tools > Options > Source Control > Git, find Automatically activate multiple repositories, and select Yes, include submodules. This is the first milestone for the experience, with more improvements planned. Repository picker showing a parent repository and its nested submodule hierarchy * * *From our entire team, thank you for choosing Visual Studio! For the latest updates, resources, and news, check out the

Visual Studio Hub and stay in touch. Happy coding! The Visual Studio team

The post Visual Studio August Update — Work Smarter Across Models and Branches appeared first on Visual Studio Blog.

Read the whole story
alvinashcraft
53 seconds ago
reply
Pennsylvania, USA
Share this story
Delete
Next Page of Stories