marcominerva/McpServerAspNetCore
If you are the rightful owner of McpServerAspNetCore and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This document provides a structured summary of a Model Context Protocol (MCP) server implemented using ASP.NET Core.
MCP Server with ASP.NET Core
Minimal implementation of a Model Context Protocol (MCP) server based on ASP.NET Core 10. The project serves as an example to expose MCP tools to compatible clients, including authentication, automatic discovery, and API documentation.
Project purpose
Provide a simple, ready-to-use starting point to build an MCP server on ASP.NET Core, useful for integrating server-side tools into agents/assistants that speak MCP.
Exposed features
- Framework: ASP.NET Core 10, minimal configuration ready for extension.
- Security: access protected via API Key.
- MCP Tool Discovery: automatic detection/exposure of the server's available MCP tools.
- OpenAPI/Swagger UI: interface to explore and test the exposed endpoints.
- CORS: enabled/configurable to allow access from secure external origins.
- Example server-side tools:
- Weather: retrieve weather conditions for a location.
- Time: get current date and time (e.g., for a specific time zone).
These features make it possible to connect an MCP client and automatically discover/consume the tools published by the server, with support for security, documentation, and interoperability.
Configuration
OpenWeatherMap API Key
The weather tools use the OpenWeatherMap API to retrieve weather data. To use these tools, you need to obtain a free API key:
- Go to OpenWeatherMap and create a free account
- Navigate to your API keys page
- Generate a new API key (or copy your existing one)
- Add the API key to your configuration file
Update appsettings.json
Open src/McpServerAspNetCore/appsettings.json and update the OpenWeatherMapAppId value:
{
"AppSettings": {
"OpenWeatherMapBaseUrl": "https://api.openweathermap.org/data/2.5/",
"OpenWeatherMapAppId": "YOUR_API_KEY_HERE"
}
}
Azure OpenAI Configuration (for Client Apps)
The sample client applications (McpClientConsoleApp.ExtensionsAI and McpClientConsoleApp.Agents) use Azure OpenAI to demonstrate how to integrate MCP tools with AI agents. To run these clients, you need to configure your Azure OpenAI credentials:
- Create an Azure OpenAI resource in the Azure Portal
- Deploy a GPT model (e.g., GPT-4) from the Azure OpenAI Studio
- Get your endpoint URL and API key from the Azure Portal (under "Keys and Endpoint")
- Update the
Constants.csfile in each client project
Update Constants.cs
Open src/McpClientConsoleApp.ExtensionsAI/Constants.cs (or src/McpClientConsoleApp.Agents/Constants.cs) and update the values:
public static class Constants
{
public const string Endpoint = "https://YOUR_RESOURCE_NAME.openai.azure.com/";
public const string DeploymentName = "YOUR_DEPLOYMENT_NAME";
public const string ApiKey = "YOUR_AZURE_OPENAI_API_KEY";
}
Note: For production applications, consider using Azure Key Vault or environment variables to store these sensitive credentials securely instead of hardcoding them.