Building MCP Servers with .NET: From Development to Publication
The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect to external data sources and tools. Think of it as a bridge between AI models and the real world — letting assistants access databases, APIs, file systems, and custom business logic.
With the release of .NET 10, Microsoft has added native support for creating MCP servers right out of the box. And here's the exciting part — you can now publish your servers to NuGet, making them discoverable by the entire .NET community!
What is MCP and Why Do You Need It?
MCP is often described as "the USB-C port for AI," providing a uniform way to connect LLMs to resources they can use. Simply put, it's like an API, but specifically designed for LLM interactions.
MCP servers can:
- Expose data through Resources (think of these like GET endpoints — they're used to load information into the LLM's context)
- Provide functionality through Tools (similar to POST endpoints — used to execute code or produce side effects)
- Define interaction patterns through Prompts (reusable templates for LLM interactions)
Quick Start: Creating Your First MCP Server
Install the Template
First, let's install the MCP Server template:
dotnet new install Microsoft.Extensions.AI.Templates
Create Your Project
Create a new MCP server using the template:
dotnet new mcpserver -n MyCoolMcpServer
cd MyCoolMcpServer
dotnet build
The template gives you a working MCP server with a sample get_random_number
tool. But let's make it more interesting!
Adding Custom Tools
Let's create a new WeatherTools.cs
class in the Tools
directory:
[McpServerTool]
[Description("Describes random weather in the provided city.")]
public string GetCityWeather(
[Description("Name of the city to return weather for")] string city)
{
var weather = Environment.GetEnvironmentVariable("WEATHER_CHOICES");
if (string.IsNullOrWhiteSpace(weather))
{
weather = "sunny,rainy,stormy,foggy";
}
var weatherChoices = weather.Split(",");
var selectedWeatherIndex = Random.Shared.Next(0, weatherChoices.Length);
return $"The weather in {city} is {weatherChoices[selectedWeatherIndex]}.";
}
Now update your Program.cs
by adding .WithTools<WeatherTools>()
after the previous WithTools
call.
Testing with GitHub Copilot
Configure GitHub Copilot to use your MCP server by creating .vscode/mcp.json
:
{
"servers": {
"MyCoolMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "--project", "."],
"env": {
"WEATHER_CHOICES": "sunny,humid,freezing,perfect"
}
}
}
}
Now test it with prompts like:
- "What's the weather in Seattle?"
- "Give me a random number between 1 and 100"
Preparing for NuGet Publication
Configure Metadata
Update your .mcp/server.json
file to declare inputs and metadata:
{
"description": "A sample MCP server with weather and random number tools",
"name": "io.github.yourusername/MyCoolMcpServer",
"packages": [
{
"registry_name": "nuget",
"name": "YourUsername.MyCoolMcpServer",
"version": "1.0.0",
"package_arguments": [],
"environment_variables": [
{
"name": "WEATHER_CHOICES",
"description": "Comma separated list of weather descriptions",
"is_required": true,
"is_secret": false
}
]
}
],
"repository": {
"url": "https://github.com/yourusername/MyCoolMcpServer",
"source": "github"
},
"version_detail": {
"version": "1.0.0"
}
}
Update Your .csproj File
Make sure your .csproj
file has a unique <PackageId>
:
<PackageId>YourUsername.MyCoolMcpServer</PackageId>
Publishing to NuGet
Pack Your Project
dotnet pack -c Release
Publish
dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json
💡 Pro Tip: Want to test first? Use the NuGet test environment at int.nugettest.org before publishing to production.
Discovering and Using MCP Servers
Once published, your MCP server becomes discoverable on NuGet.org:
- Search: Visit NuGet.org and filter by
mcpserver
package type - Explore: View package details and copy configuration from the "MCP Server" tab
- Install: Add the configuration to your
.vscode/mcp.json
file
NuGet.org now supports hosting and consuming MCP servers built with the ModelContextProtocol C# SDK. This means:
- Discoverability: Developers can find your MCP servers through NuGet search
- Versioning: Proper semantic versioning and dependency management
- Easy Installation: Copy VS Code and Visual Studio MCP configuration
- Community: Join a growing ecosystem of .NET AI tools
Alternative Platform: FastMCP
Beyond NuGet, there's an excellent alternative for publishing your MCP servers — FastMCP.me is the MCP server marketplace that just works. The best part? You can publish your MCP server absolutely free at https://fastmcp.me!
FastMCP offers curated, community-vetted MCP servers ready to supercharge your LLM apps. The platform already features various server categories:
- Web Search: Brave Search, Exa Search, DuckDuckGo
- Browser Automation: Playwright, Puppeteer, Firecrawl
- Productivity: Notion, Jira, Task Master, Confluence
- Memory Management: Context7
- And much more
Publishing on FastMCP.me provides additional benefits:
- Instant visibility in a specialized MCP catalog
- Integration with popular AI tools
- Active developer community
- Simple categorization and search system
Real-World MCP Server Ideas
Here are some powerful MCP servers you could build next:
Enterprise Solutions
- Enterprise Database Gateway: Safely expose SQL Server, PostgreSQL, or MongoDB queries with role-based access control
- Cloud API Orchestrator: Wrap Azure, AWS, or Google Cloud services for AI-driven infrastructure management
Document Processing
- Document Intelligence Hub: Process PDFs, Word docs, and spreadsheets with OCR and content extraction
- Data Analytics Engine: Transform CSV files, generate reports, and create visualizations on demand
DevOps & Automation
- DevOps Command Center: Automate Git operations, CI/CD pipelines, and deployment workflows
- Monitoring System Integrator: Connect to Prometheus, Grafana, or other monitoring systems
Each of these represents a unique opportunity to bridge AI capabilities with real business needs — and share your solutions with the entire .NET community through NuGet or with a broader audience through FastMCP.me.
Conclusion
With .NET 10 and native MCP support, creating AI extensions has never been easier. The combination of .NET's robust libraries and package management creates endless possibilities for AI extensibility.
You can choose the right platform for publication:
- NuGet — for .NET ecosystem integration and enterprise use
- FastMCP.me — for maximum visibility and free publication in a specialized MCP catalog
The future of extensible AI is here, and it's time to start building! 🚀
Useful Links: