Warehouse AI Assistant: A Practical Guide to MCP in .NET with Ollama

Denis FedakDenis Fedak
9 min read

Introduction

Imagine a warehouse operator working with an intuitive interface. A manager getting instant answers to any questions about inventory. A director who can simply ask "How many laptops do we have?" and get accurate information.

Modern inventory management systems must be accessible and efficient. They should understand natural language, process requests, and provide information in a convenient format. What if the system worked like a smart assistant that understands your needs while ensuring complete data security?

In this article, you'll get a detailed guide on creating your own AI-powered inventory management system. We'll step-by-step break down the architecture, configure all components, and create a fully functional solution that you can deploy in your infrastructure. You'll learn how to integrate AI with business logic, ensure data security, and scale the system to your needs.

AI Assistant That Understands Your Business

Model Context Protocol (MCP) is a new standard that radically changes how AI interacts with business systems. As noted in Ksenia Se's article on huggingface (https://huggingface.co/blog/Kseniase/mcp), "Even the most sophisticated models are constrained by their isolation from data – trapped behind information silos and legacy systems." MCP solves this problem by providing a standardized way to connect AI to external data and tools.

Instead of training AI on historical data, MCP gives AI access to real business processes in real-time, allowing models to perform actions in your systems. The protocol defines clear rules for how AI can discover, connect, and use external tools - from database queries to command execution.

Launch the Demo in 5 Minutes

Let's start with practice. To launch the demo, you'll need:

  • Docker

  • Docker Compose

  • Minimum 4 GB, preferably 8 GB, of RAM (for Ollama with LLM model)

  • 10 GB free disk space (for containers and model)

  • Internet connection (for initial Docker image downloads)

All other dependencies (Ollama, .NET 8, SQLite) will be automatically installed in containers.

Clone the repository and launch all services with one command:

git clone https://github.com/fedakdenis/SimpleStock.git
cd SimpleStock
docker-compose up -d

The system will launch four containers: Web application with API for business logic, MCP server for AI integration, console application for interaction, and Ollama with local AI model. In a few minutes, all services will be ready to work.

Console AI Assistant

Launch the console interface to interact with AI:

docker-compose exec simplestock-chat dotnet SimpleStock.Chat.dll

Now you can communicate with the system in natural language. Try asking "Show stock balance" or "Add 5 laptops from Apple Store". The AI will understand your request, even if you make a typo in the supplier name.

All changes made through the AI assistant are instantly reflected in the web interface. You can perform an operation through the chat assistant, then check the result in the browser - the system works with a single database, ensuring complete synchronization between all interfaces.

Web Interface for Inventory Management

Open your browser and go to http://localhost:5000. You'll see a web application with full warehouse inventory management functionality. The interface allows you to view current product balances, add new income and expense operations, and generate reports on product movements.

Thus, the classic application workflow is fully preserved and works in parallel with the AI assistant. You can use the traditional web interface for manual inventory management, while the AI assistant will complement these capabilities by providing a natural language interface for the same operations.

Under the Hood of the System

Let's take a detailed look at the high-level architecture diagram of the project:

  • Users can interact through both the console AI chat and the web interface.

  • The console chat works with an MCP client that exchanges data with the LLM model (Ollama with qwen2.5) and interacts with the MCP server.

  • The MCP server calls tools in the Web API (ASP.NET Core with EF Core), which work with the SQLite database.

  • The Web UI directly interacts with the Web API, sharing the database with the AI interface.

I want to note that the choice of LLM model depends on your needs, hardware capabilities, and budget. For this project, I used qwen2.5:7b - a compact model that provides good quality request processing with moderate resource requirements. Larger models with extended context will certainly provide a richer user experience. During experiments with Claude 4 Sonnet, I was convinced of the impressive capabilities of modern LLMs. I'm confident that full-featured models with Reasoning and Deep Thinking support can effectively perform the role of an operator not only in educational projects but also in full-fledged WMS Enterprise solutions.

But it's worth saying that by running models locally, you guarantee that sensitive data won't leave your infrastructure. You get the benefits of AI without cloud risks: you can ask the assistant questions about internal data without fearing leaks.

MCP Server Registration

The MCP server uses the official C# SDK ModelContextProtocol, ensuring full compatibility with the standard and simplifying integration with various AI models.

MCP server configuration in a .NET application happens through the standard dependency injection system. The server is registered in the service container with HTTP transport support and automatic assembly scanning to find tools:

// Program.cs in MCP server
builder.Services
    .AddMcpServer()
    .WithHttpTransport()
    .WithToolsFromAssembly();

The WithHttpTransport() configuration provides HTTP connection for interaction with AI clients, and WithToolsFromAssembly() automatically discovers all methods marked with the [McpTool] attribute and registers them as available tools for AI. This allows you to easily add new capabilities without changing the main server configuration.

MCP Server Tools

The key component of the system is the MCP server tools, which are methods available for AI models to call. Each tool is marked with the [McpTool] attribute with a unique name and can accept parameters of various types. The AI model receives a description of the tool, including its purpose, parameters, and usage examples.

[McpTool("get_stock_balance")]
public async Task<string> GetStockBalance()
{
    var balances = await _stockService.GetBalances();
    return JsonSerializer.Serialize(balances);
}

[McpTool("add_stock_movement")]
public async Task<string> AddStockMovement(
    string product, 
    int quantity, 
    string movementType,
    string? supplier = null,
    string? recipient = null)
{
    var movement = new StockMovement
    {
        Product = product,
        Quantity = quantity,
        Type = movementType == "income" ? MovementType.Income : MovementType.Expense,
        Supplier = supplier,
        Recipient = recipient,
        Date = DateTime.Now
    };

    await _stockService.AddMovement(movement);
    return $"Successfully added {quantity} {product}";
}

Tools provide complete control over what operations AI can perform. The MCP security system ensures that AI can only use permitted tools, preventing unauthorized access to data or execution of dangerous operations. Each tool can include parameter validation, operation logging, and error handling.

AI Integration

AI integration happens through SSE (Server-Sent Events) transport, which provides efficient bidirectional communication between the MCP client and server.

// Chat Console
var mcpClient = await McpClientFactory.CreateAsync(
    new SseClientTransport(new SseClientTransportOptions
    {
        Endpoint = new Uri(simpleStockMcpUri)
    }));

var tools = await mcpClient.ListToolsAsync();

The MCP client automatically receives metadata of all available tools, including their descriptions, parameters, and usage examples. This information is passed to the AI model, which uses it to understand system capabilities and correctly call tools.

Request Processing

The request processing process begins with analyzing the user's natural language. The AI model analyzes the incoming message, determines user intentions, and selects appropriate tools to perform the task. The system supports processing ambiguous requests, typos, and contextual commands.

The AI model can combine multiple tools to perform complex tasks. For example, the request "Show balance and add 10 mice" might lead to sequential calls to get_stock_balance and add_stock_movement. The system supports contextual dialogues where AI remembers previous operations and can clarify details with the user.

Also, modern models are capable of combining the use of various tools. So, if you ask the model about the cost of goods in the warehouse, to get prices for each item, the model can turn to the Web Search tool.

Request Examples

Below are real examples of interaction with the AI assistant, demonstrating various scenarios for working with the inventory management system.

Example 1: Inventory Query

You >> Show stock balance
SimpleStock >> Here is the current stock balance:

- **3M Post-it Notes Variety Pack**: 120 pcs.
- **Canon imageCLASS Printer**: 20 pcs.
- **Cisco Catalyst 9300 Switch**: 12 pcs.
- **Dell OptiPlex 7090 Desktop**: 12 pcs.
- **Dell UltraSharp 27" 4K Monitor**: 14 pcs.
- **Fellowes Bankers Box Storage**: 60 pcs.
- **Herman Miller Aeron Chair**: 40 pcs.
- **HP EliteBook 850 G9 Laptop**: 12 pcs.
- **IKEA BEKANT Standing Desk**: 30 pcs.
- **iPad Pro 12.9-inch M2**: 30 pcs.
- **Logitech MX Master 3S Mouse**: 55 pcs.
- **MacBook Pro**: 5 pcs.
- **MacBook Pro 16-inch M3**: 4 pcs.
- **Microsoft Surface Studio 2+**: 4 pcs.
- **NETGEAR Nighthawk Pro Gaming Router**: 23 pcs.
- **Razer BlackWidow V4 Pro Keyboard**: 30 pcs.
- **Samsung Galaxy Tab S9 Ultra**: 27 pcs.
- **Ubiquiti UniFi Access Point**: 35 pcs.

**Total items:** 533 pcs.

Example 2: Ambiguous Request Handling

You >> Add couple laptops to Developers team
SimpleStock >> Sure, I will add a few MacBook Pros to the Developers team. Let's add 5 MacBook Pros for now.

Here are the details of the stock movement:
- **Type**: Expense
- **Product**: MacBook Pro
- **Quantity**: 5 pcs.
- **Recipient**: Developers team

The expense has been successfully added.

Would you like to perform any other actions or have more items added?

Example 3: Typo Tolerance

You >> Buy 10 MacBook in Aplle Store
SimpleStock >> The purchase of 10 MacBook Pros from the Apple Store has been successfully recorded as an income.

Here are the details:
- **Type**: Income
- **Product**: MacBook Pro
- **Quantity**: 10 pcs.
- **Supplier**: Apple Store

If you need to perform any further actions or have more questions, feel free to let me know!

Example 4: Natural Language Queries

You >> How many laptops do we have on the store?
SimpleStock >> To provide you with an accurate count of laptops in stock, I will fetch the current balance for all laptop models.

Here are the current inventory levels for laptops:

- **MacBook Pro**: 15 pcs.
- **Dell OptiPlex 7090 Desktop**: 12 pcs.
- **HP EliteBook 850 G9 Laptop**: 12 pcs.
- **Microsoft Surface Studio 2+**: 4 pcs.

**Total laptops:** 43 pcs.

If you need more detailed information or another specific product, please let me know!

Conclusion

We've built a working inventory management system with an AI assistant based on MCP. The project shows how you can quickly integrate AI into business processes.

What's next? You can add integration with external suppliers through API, connect analytics and demand forecasting, integrate with ERP systems. MCP allows you to connect any tools - from document work to procurement automation.

It will be interesting to see how such solutions develop. Perhaps soon AI assistants will become standard for all business systems, and MCP - the main protocol for their integration. For now - experiment, adapt to your needs, and share results!


AI apps for .NET developers (https://learn.microsoft.com/en-us/dotnet/ai/)

Model Context Protocol (https://modelcontextprotocol.io/)

Ollama (https://ollama.ai/)

GitHub Repository (https://github.com/fedakdenis/SimpleStock)

0
Subscribe to my newsletter

Read articles from Denis Fedak directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Denis Fedak
Denis Fedak

Hi, I'm a senior .NET developer who loves digging into the guts of ASP.NET Core, Entity Framework, and high-load backend systems. I write to make sense of the tricky stuff — and to save future me (and maybe you) a few headaches.