DEV Community

Daniel Jonathan
Daniel Jonathan

Posted on

# 🧩 Build an MCP Server with ASP.NET Core

😄 Don’t worry — this time it’s not another BODMAS post!

We’re shifting gears from math rules to building some cool integration tools with ASP.NET Core.

🧭 Overview

The Model Context Protocol (MCP) is an open standard that lets AI models call structured APIs called tools — similar to function calling.

In this article, we’ll build a custom MCP server in .NET 8 using the ModelContextProtocol.AspNetCore package.

We’ll define a simple toolset for data conversions (JSON ↔ XML, Base64 encode/decode), then test it using the MCP Playground.


⚙️ 1. Create a project

dotnet new webapi -n IntegrationSuite
dotnet add package ModelContextProtocol.AspNetCore --prerelease
Enter fullscreen mode Exit fullscreen mode

🧠 2. Define your tool class

using ModelContextProtocol.Server;

[McpServerToolType]
public class ConversionTools
{
    private readonly IFormatConverter _converter;
    public ConversionTools(IFormatConverter converter) => _converter = converter;

    [McpServerTool]
    public ConversionResponse JsonToXml(string json, string? root = null, bool indented = true)
        => _converter.ConvertJsonToXml(json, root, indented);

    [McpServerTool]
    public ConversionResponse XmlToJson(string xml, bool indented = true)
        => _converter.ConvertXmlToJson(xml, indented);
}
Enter fullscreen mode Exit fullscreen mode

🖼️ Screenshot: Tool class implementation

ConversionTools.cs


🧩 3. Wire up the server

builder.Services.AddScoped<IFormatConverter, FormatConverter>();
builder.Services.AddScoped<ConversionTools>();
builder.Services.AddMcpServer(o =>
{
    o.ServerInfo = new() { Name = "IntegrationSuite", Version = "0.1.0" };
})
.WithHttpTransport()
.WithToolsFromAssembly();

var app = builder.Build();
app.MapMcp("/api/mcp");
app.Run();
Enter fullscreen mode Exit fullscreen mode

🖼️ Screenshot: Server setup in Program.cs

Program.cs Setup


🖥️ 4. Launch & Session Logs

Once the MCP server is running, the console output confirms that the server and Postman client have successfully initialized and exchanged messages.

🖼️ Screenshot: Session logs on server startup

MCP Server Logs

What’s happening:

  • The server starts and listens on http://localhost:5098/api/mcp.
  • Postman connects and sends initialize and tools/list requests to discover available tools.
  • You may see warnings like:
  method 'prompts/list' is not available
  method 'resources/list' is not available
Enter fullscreen mode Exit fullscreen mode

These are normal — they simply indicate optional handlers not implemented in your server.

✅ This confirms your MCP session is active and Postman can now invoke any of your defined tools (json_to_xml, xml_to_json, etc.).


🧪 5. Test via Postman

You can easily test your MCP server using Postman, which now includes built-in support for the Model Context Protocol (MCP).

  1. Open Postman and click New → MCP.
  2. Enter your MCP server URL:
   http://localhost:<port>/api/mcp
Enter fullscreen mode Exit fullscreen mode
  1. Click Connect.
  2. Once connected, open the Tools tab to see all available MCP tools.
  3. Select a tool → provide arguments → click Run.
  4. You’ll see structured results in JSON — for example:
   {
     "output": "<xmlroot><item>1</item><item>2</item><item>3</item></xmlroot>",
     "operation": "json->xml",
     "success": true
   }
Enter fullscreen mode Exit fullscreen mode

🖼️ Screenshot: Postman MCP run

Postman MCP Run


🚀 Done!

You now have a working MCP server built with ASP.NET Core, exposing your own .NET tools through a simple HTTP endpoint — ready to integrate with AI or automation workflows.


🔌 More Integration Tool Ideas

Once your MCP server is up and running, you can easily expand it with additional integration tools to connect various services and automate workflows.

Here are a few examples:

  • HTTP Relay Tool — Forward requests or data payloads to external APIs or internal endpoints.
  • Azure Service Bus Tool — Publish or consume messages to streamline event-driven architecture.
  • Azure Blob Storage Tool — Upload, download, or list blobs for file automation.
  • Logic Apps / Power Automate Tool — Trigger or monitor workflows.
  • OneLake Tool — Write event data directly into Microsoft Fabric for data pipeline ingestion.
  • SharePoint / Graph API Tools — Retrieve or update documents and metadata.
  • Email Tools — Send notifications or automated messages through SMTP or Microsoft Graph.
  • Validation Tools — Perform JSON Schema or XML XSD validation.

🧠 Tip: Keep each tool focused on one clear task — like upload_file, trigger_logicapp, or publish_event — and return structured responses with fields like Success, StatusCode, or Message.

Top comments (0)