Get started with single-file MCP servers
What you need before getting started
Create .mcp.json in your project root
Note: This example is for Visual Studio and similar clients. For Claude Code, use mcpServers
instead of servers
.
{
"servers": {
"MyUtilityServer": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "C:\\\\path\\\\to\\\\your\\\\mcp-server.cs"]
}
}
}
Pass tokens and authentication keys securely
Note: These examples are for Visual Studio and similar clients. For Claude Code, use mcpServers
instead of servers
.
{
"inputs": [
{
"id": "user_email",
"description": "Your email",
"type": "promptString",
"password": true
}
],
"servers": {
"DotnetMcpFile": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "C:\\\\path\\\\to\\\\your\\\\mcp-server.cs"],
"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-preview-alpine
WORKDIR /app
COPY mcp-server.cs .
ENTRYPOINT ["dotnet", "run", "mcp-server.cs"]
Get up and running in 3 steps