What you need before getting started
dotnet --list-sdks; one line must show 10 or higher. Running a .cs file directly is a .NET 10 feature, so earlier SDKs fail. Use --list-sdks rather than --version, which reports the SDK a global.json selects.Put the server file in .mcp-servers/ in your project, then create .mcp.json in the project root. Commit both, and everyone who clones the project gets the server. The path is relative, so it works on every operating system.
Note: This example is for Claude Code, Claude Desktop, Cursor, and Windsurf. Visual Studio and VS Code use servers instead of mcpServers.
{
"mcpServers": {
"MyUtilityServer": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "./.mcp-servers/mcp-server.cs", "-v", "q"]
}
}
}
Pass tokens and authentication keys securely
Note: The inputs block below belongs to Visual Studio and VS Code, which also use servers. Claude Code, Claude Desktop, Cursor, and Windsurf use mcpServers, and expand ${MY_KEY} from the environment instead.
{
"inputs": [
{
"id": "user_email",
"description": "Your email",
"type": "promptString",
"password": true
}
],
"servers": {
"DotnetMcpFile": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "./.mcp-servers/mcp-server.cs", "-v", "q"],
"env": {
"USER_EMAIL": "${input:user_email}"
}
}
}
}
[McpServerToolType]
public static class EnvironmentExamples
{
[McpServerTool, Description("Gets environment variable value")]
public static string GetEnvironmentVariable(string variableName, string? defaultValue = null)
{
var value = Environment.GetEnvironmentVariable(variableName);
if (string.IsNullOrEmpty(value))
{
if (defaultValue != null)
return $"Environment variable '{variableName}' not found, using default: {defaultValue}";
else
return $"Environment variable '{variableName}' not found";
}
return $"{variableName} = {value}";
}
}
For containerized environments
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine
WORKDIR /app
COPY mcp-server.cs .
ENTRYPOINT ["dotnet", "run", "mcp-server.cs", "-v", "q"]
Get up and running in your project, in 4 steps