Artificial Intelligence (AI) agents are evolving beyond simple chatbots into systems capable of interacting with enterprise applications, databases, APIs, and business workflows. However, integrating AI models with external tools has traditionally required custom connectors for every application, making development and maintenance complex.
The Model Context Protocol (MCP) addresses this challenge by providing a standardized protocol that allows AI models to discover and invoke tools exposed by applications. Instead of building custom integrations for each AI platform, developers can create an MCP server that exposes business capabilities consistently.
In this article, you'll learn how to build an MCP server using ASP.NET Core, expose enterprise tools, and apply production-ready practices for security, logging, dependency injection, and scalability.
What Is the Model Context Protocol (MCP)?
Model Context Protocol (MCP) is an open protocol that standardizes communication between AI applications and external systems.
An MCP server can expose:
Tools
Resources
Prompts
An AI client discovers these capabilities dynamically instead of relying on hardcoded integrations.
Traditional architecture:
AI Model
|
Custom API Integration
|
Business Application
MCP architecture:
AI Model
|
MCP Client
|
-------------------
| MCP Server |
-------------------
|
Business Services
Database
REST APIs
ERP / CRM
Cloud Services
This architecture enables interoperability between AI assistants and enterprise software while reducing integration effort.
Why Use MCP in Enterprise Applications?
Organizations often maintain dozens of internal systems.
Examples include:
Customer Management
Inventory
HR Systems
ERP
Document Management
Internal APIs
Without MCP, each AI assistant requires custom integration with every system.
With MCP:
One standardized integration
Reusable tools
Easier maintenance
Improved governance
Better scalability
This becomes especially valuable as organizations adopt multiple AI platforms.
Prerequisites
Before starting, ensure you have:
.NET SDK installed
Visual Studio or Visual Studio Code
Basic ASP.NET Core knowledge
Familiarity with dependency injection
Basic REST API concepts
Create an ASP.NET Core Project
Create a new Web API.
dotnet new webapi -n EnterpriseMcpServer
Navigate into the project.
cd EnterpriseMcpServer
Add the required MCP package (package names may evolve as the ecosystem matures, so consult the latest documentation for the implementation you choose).
dotnet add package ModelContextProtocol.AspNetCore
If your chosen MCP library differs, adapt the registration APIs accordingly.
Understanding the Project Structure
A clean enterprise project might look like this:
EnterpriseMcpServer
|
|-- Tools
| EmployeeTools.cs
|
|-- Services
| EmployeeService.cs
|
|-- Models
| Employee.cs
|
|-- Program.cs
|
|-- appsettings.json
Keeping business logic inside services makes testing and maintenance easier.
Configure the MCP Server
Register required services inside Program.cs.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<EmployeeService>();
builder.Services.AddMcpServer()
.WithTools();
var app = builder.Build();
app.MapMcp();
app.Run();
Why This Configuration?
AddSingleton<EmployeeService>()registers reusable business logic.AddMcpServer()enables the MCP server.WithTools()registers discoverable tools.MapMcp()exposes the MCP endpoint.
Keeping MCP configuration centralized simplifies future maintenance.
Create a Business Service
Avoid placing business logic directly inside tools.
public class EmployeeService
{
private readonly List<Employee> employees =
[
new Employee(1,"Alice","Engineering"),
new Employee(2,"Bob","Finance"),
new Employee(3,"David","HR")
];
public IEnumerable<Employee> GetEmployees()
{
return employees;
}
public Employee? FindEmployee(int id)
{
return employees.FirstOrDefault(e => e.Id == id);
}
}
This service can later connect to SQL Server, PostgreSQL, or another data source without changing the MCP tool implementation.
Define the Employee Model
public record Employee(
int Id,
string Name,
string Department
);
Using records provides concise, immutable models suitable for data transfer.
Create MCP Tools
Now expose enterprise functionality.
using ModelContextProtocol.Server;
[McpServerToolType]
public class EmployeeTools
{
private readonly EmployeeService service;
public EmployeeTools(EmployeeService service)
{
this.service = service;
}
[McpServerTool]
public IEnumerable<Employee> GetEmployees()
{
return service.GetEmployees();
}
[McpServerTool]
public Employee? GetEmployee(int id)
{
return service.FindEmployee(id);
}
}
Each method decorated with McpServerTool becomes discoverable by compatible MCP clients.
Instead of calling REST endpoints manually, AI agents can inspect the available tools and invoke them using structured parameters.
How AI Discovers These Tools
When an MCP client connects, it can retrieve metadata about available tools.
Example:
Available Tools
GetEmployees()
Returns all employees
GetEmployee(id)
Returns employee details
The AI model understands:
Tool name
Parameters
Return type
Description (when provided)
This eliminates hardcoded integrations.
Dependency Injection Matters
A common mistake is embedding business logic inside tool classes.
Avoid this:
public class EmployeeTools
{
public List<Employee> GetEmployees()
{
// Business logic here
}
}
Instead:
Tool
|
Service
|
Repository
|
Database
Benefits include:
Easier unit testing
Better separation of concerns
Improved maintainability
Reusable business services
Adding Logging
Enterprise applications should log tool execution for diagnostics and auditing.
public class EmployeeService
{
private readonly ILogger<EmployeeService> logger;
public EmployeeService(
ILogger<EmployeeService> logger)
{
this.logger = logger;
}
public IEnumerable<Employee> GetEmployees()
{
logger.LogInformation("Employee list requested.");
return employees;
}
}
Logging helps diagnose failures, monitor usage, and troubleshoot production issues.
Avoid logging sensitive information such as passwords, tokens, or personally identifiable information.
Security Considerations
Exposing internal tools to AI systems requires careful security planning.
Join the conversation! Your thoughts help the community grow.