Add an MCP Server to ASP.NET Core: C# Tools & LM Studio Debugging

Published 01/11/2026

Description

How do you add an MCP server to an existing ASP.NET Core project? In this hands-on C# tutorial, I extend my LLM Memory Calculator with Model Context Protocol tools so an AI client can retrieve Hugging Face model details and calculate estimated memory requirements. Contents: 0:00 - Introduction 0:10 - Description 0:57 - Nuget Package 1:37 - Tool 8:42 - Plumbing 10:05 - Debugging 15:02 - Conclusion use the ModelContextProtocol.AspNetCore NuGet package to host an HTTP-based MCP server alongside my existing MVC application. The official C# SDK provides HTTP transport, tool registration, and endpoint mapping for this approach. Rather than placing MCP methods inside an MVC controller, I create separate tool classes that reuse the application’s existing processors through dependency injection. I then connect LM Studio to the local development endpoint and use breakpoints to debug actual tool calls. The walkthrough covers: Choosing the MCP C# SDK package for an ASP.NET Core application Organizing MCP tools separately from MVC controllers Defining tools with McpServerToolType and McpServerTool attributes Adding tool names, titles, descriptions, and behaviour annotations Describing request objects and input properties for AI clients Reusing existing application services through dependency injection Using async methods and cancellation tokens for external requests Registering tools and configuring stateless HTTP transport Mapping the MCP endpoint to /mcp Connecting LM Studio to a localhost development server Troubleshooting the “unable to verify leaf signature” certificate error Debugging model-configuration and memory-calculation requests The certificate issue is an important part of the demo: a connection that works in the browser can still fail in the client. I show how I configure NODE_EXTRA_CA_CERTS with the trusted certificate file and fully restart LM Studio before testing again. Finally, I demonstrate both tools t