MCPApplication service as MCP tool

Application service as MCP tool

Wrap an existing ASP.NET Core application service with a typed MCP tool.

MCP tools can use the same dependency injection setup as the rest of the ASP.NET Core application.

The common pattern is:

  1. Keep the useful behavior in an ordinary application service.
  2. Register that service in ASP.NET Core dependency injection.
  3. Create a small MCP tool class that calls the service.
  4. Expose only the selected method through MCP.

Reuse application services

The travel sample registers an application service first:

Program.cs
builder.Services.AddScoped<ITravelSummaryService, TravelSummaryService>();

builder.Services.AddRuniqMcp();

That service remains ordinary application code. It does not need to know about MCP.

C#
public sealed class TravelSummaryService : ITravelSummaryService
{
    public TravelSummaryResult CreateSummary(TravelSummaryRequest request)
    {
        var summary =
            $"{request.TravelerCount} traveler(s) can plan a {request.Days}-day trip to {request.City}. " +
            "This response was produced by an ASP.NET Core service and exposed through Runiq.Mcp.";

        return new TravelSummaryResult(
            request.City,
            request.Days,
            request.TravelerCount,
            summary);
    }
}

Expose a selected method

Create an MCP tool class with ModelContextProtocol.Server attributes.

C#
using System.ComponentModel;
using ModelContextProtocol.Server;
using Runiq.ContextTravelGuide.Services;

[McpServerToolType]
public sealed class TravelSummaryMcpTool
{
    private readonly ITravelSummaryService travelSummaryService;

    public TravelSummaryMcpTool(ITravelSummaryService travelSummaryService)
    {
        this.travelSummaryService = travelSummaryService;
    }

    [McpServerTool]
    [Description("Creates a simple travel summary using an ASP.NET Core application service.")]
    public TravelSummaryResult CreateTravelSummary(
        [Description("The city to visit.")] string city,
        [Description("The number of trip days.")] int days,
        [Description("The number of travelers.")] int travelerCount)
    {
        var request = new TravelSummaryRequest(city, days, travelerCount);

        return travelSummaryService.CreateSummary(request);
    }
}

This produces an MCP tool named from the method, such as create_travel_summary, with typed inputs for city, days, and travelerCount.

What to expose

Good MCP tools are narrow application capabilities.

Tool ideaWhy it fits
Travel summaryCalls an existing application service and returns a typed result.
Order status lookupUses the application's order service.
Account entitlement checkRuns existing policy code.
Inventory lookupReads real stock data from the application.
Support article searchExposes an approved search service to MCP clients.

Avoid exposing broad administrative operations or low-level data access directly. The MCP tool should be a stable capability boundary, not an unrestricted entry point into the application.

On this page