Skip to content

CaitieM20/AspireMCPServiceExample

Repository files navigation

MCPServiceGenerator

C# MCP Service Generator. This project shows an example of how to structure an Aspire project to contain a Remote MCP Server which passes through calls to an API backend server. In the world of agents, many existing services will want to expose Remote MCP endpoints so that agents can interact with their APIs.

Prerequisites

  • .NET 9.0 SDK
  • Visual Studio 2022 (17.9+) with the Aspire workload, or
  • Aspire workload installed via dotnet workload install aspire
  • Node.js v22 or higher.

Build Instructions

# From the solution root directory
dotnet build

Run Instructions

# From the soultion root directory
dotnet run --project .\MCPServiceGenerator.AppHost

Compiling TypeSpec

This will regenerate the OpenAPI and REST client libraries.

npx tsp compile TypeSpec

What Gets Started

When you run the application, the Aspire AppHost will:

  • Start the Aspire Dashboard - Web-based monitoring interface
  • Launch MCPServiceGenerator.ApiService - The API backend
  • Launch MCPServiceGenerator.MCPService - The MCP Server backend
  • Configure service discovery - Enables communication between services

The console output will display URLs for:

  • Aspire Dashboard (typically https://localhost:15888)
  • API service endpoints
  • MCP service endpoints

SwaggerUI is available at the /swagger route.

Project Structure

  • MCPServiceGenerator.AppHost - Aspire orchestration host
  • MCPServiceGenerator.ApiService - Web API backend
  • MCPServiceGenerator.ServiceDefaults - Shared configuration and extensions
  • TypeSpec - REST API Specification

Testing

You can test the REST server using SwaggerUI which is available at the /swagger route.

You can test the MCP Servers using MCP Inspector Enter the MCP Service Endpoint to connect.

npx @modelcontextprotocol/inspector

About

Aspire C# MCP Service Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors