Running a Python MCP server inside .NET Aspire

.NET Aspire isn’t limited to .NET microservices — you can orchestrate Python components just as easily.
In this post, we’ll look at how to run a Python MCP (Model Context Protocol) server inside an Aspire application, integrate it with the MCP Inspector, and expose it via a Dev Tunnel for testing.

Folder Layout

05_PythonMCP/
├─ AppHost.cs
├─ PythonMCP.csproj
├─ appsettings.json
├─ appsettings.Development.json
├─ NuGet.config
├─ README.md
└─ pymcp/
   ├─ main.py
   ├─ requirements.txt
   └─ (optional) .venv/

AppHost.cs

Here’s the full orchestration file:

var builder = DistributedApplication.CreateBuilder(args);

var inspector = builder.AddMcpInspector("mcp-inspector");

var tunnel = builder.AddDevTunnel("dev-tunnel");

var pyMcpServer = builder.AddPythonApp(
    name: "pymcp",
    appDirectory: "./pymcp",
    scriptPath: "main.py"
).WithHttpEndpoint(env: "PORT");

tunnel.WithReference(pyMcpServer, allowAnonymous: true);

inspector.WithMcpServer(pyMcpServer);

builder. Build().Run();
Continue reading “Running a Python MCP server inside .NET Aspire”

Running a Python FastAPI (Uvicorn) service from .NET Aspire

NET Aspire isn’t limited to .NET services. You can orchestrate a Python service (FastAPI on Uvicorn) right alongside your .NET components—same lifecycle, unified logs, single dotnet run.

Below is a minimal setup that boots a FastAPI app with health endpoint, exposes it via Aspire, and keeps everything tidy in one solution.

Folder layout

04_PythonUvicorn/
├─ AppHost.cs
├─ PythonUvicorn.csproj
├─ appsettings.json
├─ appsettings.Development.json
├─ README.md
└─ uvicornapp-api/          # Python app lives here
   ├─ main.py
   ├─ requirements.txt
   └─ (optional) .venv/

AppHost.cs (Aspire)

var builder = DistributedApplication.CreateBuilder(args);

var uvicorn = builder.AddUvicornApp(
        name: "uvicornapp",
        projectDirectory: "./uvicornapp-api",
        appName: "main:app"
    )
    .WithHttpEndpoint(targetPort: 8000)   // app listens on 8000
    .WithExternalHttpEndpoints();         // optional, expose to host

builder. Build().Run();
Continue reading “Running a Python FastAPI (Uvicorn) service from .NET Aspire”

Website Powered by WordPress.com.

Up ↑