Skip to content

petender/demo-mcp-productcatalog

Repository files navigation

Product Catalog MCP Server

Overview

The Product Catalog MCP Server is a .NET 8 web application that implements a Model Context Protocol (MCP) server for managing retail product inventory. It provides a standardized interface for AI assistants and other applications to interact with product data through a set of well-defined tools and APIs.

The scenario provides an MCP Server product catalog backend which can be integrated into Copilot Studio (see Demoguide instructions) or Azure AI Foundry demos.

This scenario is part of the broader Azure Demo Catalog, available at Trainer-Demo-Deploy.

What is MCP (Model Context Protocol)?

The Model Context Protocol is a standard that enables AI assistants to securely connect with external data sources and tools. This server acts as a bridge between AI models and product inventory data, allowing natural language interactions with product management operations.

Architecture

Technology Stack

  • Framework: ASP.NET Core 8.0
  • Protocol: Model Context Protocol (MCP)
  • Data Storage: JSON file-based storage
  • Language: C# with nullable reference types enabled

Core Components

  1. Program.cs - Application entry point and service configuration
  2. ProductCatalogTools.cs - MCP tool definitions for product operations
  3. ProductService.cs - Business logic for product management
  4. Models.cs - Data models and DTOs
  5. Configuration - Server configuration settings

Data Model

Products are represented by the Product class with the following properties:

public class Product
{
    public string Name { get; set; }           // Product name
    public string Description { get; set; }   // Product description  
    public string EAN { get; set; }          // European Article Number (barcode)
    public decimal Cost { get; set; }        // Product price/cost
    public int UnitsInStock { get; set; }    // Current inventory count
    public string Brand { get; set; }        // Product manufacturer/brand
    public List<string> Categories { get; set; } // Product categories/tags
}

Features & Capabilities

Core Product Management

  • βœ… Add Products - Create new products in the inventory
  • βœ… Update Products - Modify existing product information
  • βœ… Remove Products - Delete products from the inventory
  • βœ… List Products - Retrieve all products in the catalog
  • βœ… Search Products - Find products by name, description, EAN, brand, or categories

Inventory Management

  • βœ… Stock Tracking - Monitor units in stock for each product
  • βœ… Stock Updates - Modify inventory levels
  • βœ… Low Stock Detection - Identify products with low inventory levels

Data Persistence

  • Products are stored in JSON format in Data/products.json
  • In-memory operations with file-based initialization
  • Thread-safe operations using locking mechanisms

Available MCP Tools

The server exposes the following tools through the MCP protocol:

Tool Name Description Parameters
ListProducts Returns all products in inventory None
AddProduct Adds a new product name, description, ean, cost, unitsInStock, brand?, categories?
UpdateProduct Updates existing product by EAN ean + optional fields to update
UpdateStock Updates stock quantity ean, newStock
RemoveProduct Removes product by EAN ean
SearchProducts Searches products by term searchTerm
GetLowStockProducts Gets products below threshold threshold

Tool Details

ListProducts

Returns the complete list of all products in the inventory.

AddProduct

Adds a new product to the inventory. Requires:

  • name (string): Product name
  • description (string): Product description
  • ean (string): EAN barcode
  • cost (decimal): Product cost
  • unitsInStock (int): Stock quantity
  • brand (string, optional): Product brand
  • categories (string, optional): Comma-separated categories

UpdateProduct

Updates an existing product by EAN. Optional parameters:

  • name, description, cost, brand, categories

UpdateStock

Updates the stock quantity for a specific product by EAN.

RemoveProduct

Removes a product from the inventory by EAN.

SearchProducts

Searches for products using a search term that matches against name, description, EAN, brand, or categories.

GetLowStockProducts

Returns products with stock levels below a specified threshold (default: 10 units).

Project Diagrams

Project Structure

graph TD
    Root[πŸ“ demo-mcp-productcatalog] --> Program[πŸ“„ Program.cs]
    Root --> Project[πŸ“„ product-catalog-mcp-server.csproj]
    Root --> Build[πŸ“„ build.ps1]
    Root --> ReadMe[πŸ“„ README.md]
    Root --> AppSettings[πŸ“„ appsettings.Development.json]
    
    Root --> Config[πŸ“ Configuration]
    Config --> ConfigFile[πŸ“„ ProductCatalogMCPServerConfiguration.cs]
    
    Root --> Data[πŸ“ Data]
    Data --> Products[πŸ“„ products.json]
    
    Root --> Services[πŸ“ Services]
    Services --> IService[πŸ“„ IProductService.cs]
    Services --> Service[πŸ“„ ProductService.cs]
    
    Root --> Tools[πŸ“ Tools]
    Tools --> Models[πŸ“„ Models.cs]
    Tools --> MCPTools[πŸ“„ ProductCatalogTools.cs]
    
    Root --> Props[πŸ“ Properties]
    Props --> Launch[πŸ“„ launchSettings.json]
    
    Root --> Infra[πŸ“ infra]
    Infra --> DeployPS[πŸ“„ deploy.ps1]
    Infra --> DeploySH[πŸ“„ deploy.sh]
    Infra --> Bicep[πŸ“„ main.bicep]
    Infra --> BicepParam[πŸ“„ main.bicepparam]
    Infra --> InfraReadMe[πŸ“„ README.md]
    
    Root --> Bin[πŸ“ bin]
    Bin --> Debug1[πŸ“ Debug]
    Debug1 --> Net80[πŸ“ net8.0]
    Net80 --> Artifacts[πŸ“„ Built artifacts...]
    
    Root --> Obj[πŸ“ obj]
    Obj --> Debug2[πŸ“ Debug]
    Debug2 --> Net80Obj[πŸ“ net8.0]
    Net80Obj --> BuildFiles[πŸ“„ Build files...]

    style Root fill:#e1f5fe
    style Program fill:#fff3e0
    style Project fill:#fff3e0
    style Config fill:#f3e5f5
    style Data fill:#e8f5e8
    style Services fill:#fff8e1
    style Tools fill:#fce4ec
    style Props fill:#f1f8e9
    style Infra fill:#e0f2f1
    style Bin fill:#f5f5f5
    style Obj fill:#f5f5f5
Loading

Application Architecture

graph LR
    subgraph "MCP Server Application"
        Entry[Program.cs<br/>Entry Point] --> MCPTools[ProductCatalogTools<br/>MCP Tools]
        Entry --> BusinessLogic[ProductService<br/>Business Logic]
        MCPTools --> BusinessLogic
        
        DataModels[Models.cs<br/>Data Models] --> MCPTools
        DataModels --> BusinessLogic
        
        AppConfig[Configuration<br/>Settings] --> Entry
        DataStore[products.json<br/>Data Store] --> BusinessLogic
    end
    
    subgraph "Infrastructure"
        IaC[bicep templates<br/>IaC] --> Deployment[Azure Deployment]
        Scripts[PowerShell Scripts<br/>Automation] --> Deployment
    end
    
    subgraph "MCP Protocol"
        Assistant[AI Assistant] --> Transport[HTTP Transport]
        Transport --> MCPTools
        MCPTools --> Operations[Product Operations]
        Operations --> Inventory[Inventory Management]
    end

    style Entry fill:#ffeb3b
    style MCPTools fill:#4caf50
    style BusinessLogic fill:#2196f3

    style DataModels fill:#ff9800
    style DataStore fill:#9c27b0
    style IaC fill:#607d8b
    style Assistant fill:#f44336
Loading

OPTION 1: Running the app locally from your Dev environment with DevTunnel

For a quick and simple setup, use these five basic commands:

1. Run the dotnet app

From within the application folder in your favorite terminal/console, execute

dotnet run

which starts the application on http://Localhost:47002

2. Run the DevTunnel to expose your locally running app to a public URL/Endpoint:

1. log on to DevTunnel

devtunnel user login

What it does: Authenticates you with the DevTunnel service using your Microsoft account. This is required before you can create or manage tunnels.

2. Create a Tunnel

devtunnel create product-catalog-mcp -a --host-header unchanged

What it does:

  • Creates a new tunnel named product-catalog-mcp
  • -a flag makes the tunnel accessible to anyone (anonymous access)
  • --host-header unchanged preserves the original host header, which is important for applications that depend on specific host values

3. Create a Port Mapping

devtunnel port create product-catalog-mcp -p 47002

What it does: Creates a port mapping for the product-catalog-mcp tunnel, forwarding traffic to local port 47002 where the Product Catalog MCP Server is running.

4. Start the Tunnel

devtunnel host product-catalog-mcp

What it does: Starts hosting the product-catalog-mcp tunnel, making your local application accessible via a public URL. This command will display the public URL that you can use to access your Product Catalog MCP Server from anywhere.

Note: Keep the terminal window with devtunnel host product-catalog-mcp open while you need the tunnel active. Make sure your Product Catalog MCP Server is running on port 47002 before starting the tunnel.

OPTION 2: Deploy the app to Azure App Service

⬇️ Installation

  • Azure Developer CLI - AZD
  • When installing AZD, the above the following tools will be installed on your machine as well, if not already installed:
  • GitHub CLI
  • Bicep CLI
  • You need Owner or Contributor access permissions to an Azure Subscription to deploy the scenario.

πŸš€ Deploying the scenario in 4 steps:

  1. Create a new folder on your machine.
mkdir -p petender/demo-mcp-productcatalog
  1. Next, navigate to the new folder.
cd petender/demo-mcp-productcatalog
  1. Next, run azd init to initialize the deployment.
azd init -t petender/demo-mcp-productcatalog
  1. Last, run azd up to trigger an actual deployment.
azd up

⏩ Note: you can delete the deployed scenario from the Azure Portal by deleting the Resource Group, or by running azd down from within the initiated folder.

Closing

This MCP server provides a robust foundation for AI-powered product management applications while maintaining simplicity and reliability in its core operations.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors