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:

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:

Without MCP, each AI assistant requires custom integration with every system.

With MCP:

This becomes especially valuable as organizations adopt multiple AI platforms.

Prerequisites

Before starting, ensure you have:

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?

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:

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:

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.

Recommended practices:

  1. Protect MCP endpoints using authentication.

  2. Apply role-based authorization.

  3. Validate all tool parameters.

  4. Limit tool permissions to the minimum required.

  5. Audit tool invocations.

  6. Rate-limit requests to prevent abuse.

  7. Avoid exposing internal administrative operations unless necessary.

Treat every AI client as an external consumer and apply the same security standards as you would for public APIs.

Production Best Practices

Consider the following when deploying MCP servers:

PracticeWhy It Matters
Dependency InjectionKeeps business logic separate from tool definitions
Structured LoggingSimplifies debugging and monitoring
AuthenticationPrevents unauthorized access
Input ValidationProtects against invalid or malicious input
Version APIsSupports backward compatibility
Centralized ConfigurationSimplifies environment management
Health ChecksImproves operational monitoring

Common Mistakes

MistakeBetter Approach
Business logic inside toolsDelegate to services
Exposing every internal APIPublish only necessary tools
Missing input validationValidate all incoming parameters
Logging sensitive dataLog only operational details
Ignoring authorizationSecure every exposed endpoint
Tight couplingUse dependency injection and interfaces

Troubleshooting

Tools are not visible

Verify that:

Dependency injection errors

Ensure every required service is registered in Program.cs.

Tool execution fails

Check:

Authentication issues

Verify:

Comparing REST APIs and MCP Servers

FeatureREST APIMCP Server
AI Tool DiscoveryNoYes
Standardized Tool MetadataNoYes
Dynamic Tool InvocationLimitedYes
Works with Traditional ApplicationsYesYes
Designed for AI AgentsNoYes
Reusable Across AI PlatformsLimitedYes

REST APIs remain essential for general-purpose integrations, while MCP provides an AI-centric layer that enables standardized tool discovery and invocation.

Frequently Asked Questions

Is MCP a replacement for REST APIs?

No. MCP complements REST APIs by exposing AI-friendly interfaces. Your underlying business services can continue to use REST, gRPC, or other communication protocols.

Can an MCP server connect to databases?

Yes. MCP tools can interact with SQL Server, PostgreSQL, Redis, cloud services, or any supported data source through your application's business layer.

Should business logic be implemented inside MCP tools?

No. Keep tools lightweight and delegate business operations to services. This improves testability and maintainability.

Can existing ASP.NET Core applications support MCP?

Yes. Many existing ASP.NET Core applications can expose selected business capabilities through an MCP server without requiring a complete redesign.

Is MCP suitable for enterprise environments?

Yes. When combined with authentication, authorization, logging, monitoring, and secure deployment practices, MCP provides a standardized way to expose enterprise capabilities to AI agents.

Conclusion

The Model Context Protocol simplifies how AI agents interact with enterprise applications by introducing a standardized approach to tool discovery and invocation. Instead of maintaining multiple custom integrations, developers can expose reusable business capabilities through an ASP.NET Core MCP server.

By combining ASP.NET Core's dependency injection, logging, and middleware pipeline with MCP's standardized protocol, you can build AI-ready services that are easier to maintain, more secure, and better aligned with enterprise architecture. As AI agents become increasingly integrated into business workflows, understanding how to design and deploy MCP servers will be an increasingly valuable skill for .NET developers.