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:
- Keep the useful behavior in an ordinary application service.
- Register that service in ASP.NET Core dependency injection.
- Create a small MCP tool class that calls the service.
- Expose only the selected method through MCP.
Reuse application services
The travel sample registers an application service first:
That service remains ordinary application code. It does not need to know about MCP.
Expose a selected method
Create an MCP tool class with ModelContextProtocol.Server attributes.
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 idea | Why it fits |
|---|---|
| Travel summary | Calls an existing application service and returns a typed result. |
| Order status lookup | Uses the application's order service. |
| Account entitlement check | Runs existing policy code. |
| Inventory lookup | Reads real stock data from the application. |
| Support article search | Exposes 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.