mcp-csharp-publish
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseC# MCP Server Publishing
C# MCP 服务器发布
Publish and deploy MCP servers to their target platforms. stdio servers are distributed as NuGet tool packages. HTTP servers are containerized and deployed to Azure or other container hosts. Both can optionally be listed in the official MCP Registry.
将MCP服务器发布部署到目标平台。stdio类型的服务器以NuGet工具包的形式分发,HTTP类型的服务器会被容器化后部署到Azure或其他容器托管平台,两类服务器都可选择上架到官方MCP Registry方便用户检索。
When to Use
适用场景
- Packaging a stdio MCP server for NuGet distribution
- Creating a Docker container for an HTTP MCP server
- Deploying to Azure Container Apps or App Service
- Publishing to the official MCP Registry for discoverability
- Setting up metadata for the MCP Registry
server.json
- 打包stdio类型的MCP服务器用于NuGet分发
- 为HTTP类型的MCP服务器创建Docker容器
- 部署到Azure Container Apps或App Service
- 发布到官方MCP Registry提升可发现性
- 为MCP Registry配置元数据
server.json
Stop Signals
不适用场景提示
- Server not tested yet? → Use first
mcp-csharp-test - Server not working locally? → Use
mcp-csharp-debug - No server project yet? → Use
mcp-csharp-create - Publishing a non-MCP NuGet package? → Use instead
nuget-trusted-publishing
- 服务器还未测试? → 先使用
mcp-csharp-test - 服务器本地运行不正常? → 先使用
mcp-csharp-debug - 还没有服务器项目? → 先使用
mcp-csharp-create - 要发布非MCP的NuGet包? → 改用
nuget-trusted-publishing
Inputs
输入参数
| Input | Required | Description |
|---|---|---|
| Transport type | Yes | |
| Target destination | Yes | NuGet.org, Docker registry, Azure Container Apps, Azure App Service, MCP Registry |
| Project path | Yes | Path to the |
| Package ID / server name | Required for publishing | NuGet |
| 参数 | 必填 | 说明 |
|---|---|---|
| 传输类型 | 是 | |
| 目标目的地 | 是 | NuGet.org、Docker镜像仓库、Azure Container Apps、Azure App Service、MCP Registry |
| 项目路径 | 是 | |
| 包ID/服务器名称 | 发布时必填 | NuGet的 |
Workflow
工作流程
Step 1: Choose the publishing path
步骤1:选择发布路径
| Transport | Primary Destination | Users Run With |
|---|---|---|
| stdio | NuGet.org | |
| HTTP | Docker → Azure | Container URL |
Both paths can optionally publish to the MCP Registry for discoverability.
| 传输类型 | 主要发布目的地 | 用户使用方式 |
|---|---|---|
| stdio | NuGet.org | |
| HTTP | Docker → Azure | 容器URL |
两条路径都可选择额外发布到MCP Registry提升可发现性。
Step 2a: NuGet publishing (stdio servers)
步骤2a:NuGet发布(stdio服务器)
- Configure with package properties:
.csproj
xml
<PropertyGroup>
<PackAsTool>true</PackAsTool>
<ToolCommandName>mymcpserver</ToolCommandName>
<PackageId>YourUsername.MyMcpServer</PackageId>
<Version>1.0.0</Version>
<Authors>Your Name</Authors>
<Description>MCP server for interacting with MyService</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>mcp;modelcontextprotocol;ai;llm</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>- Build and pack:
bash
dotnet build -c Release
dotnet pack -c Release- Test locally before publishing:
bash
dotnet tool install --global --add-source bin/Release/ YourUsername.MyMcpServer
mymcpserver --help # verify it runs
dotnet tool uninstall --global YourUsername.MyMcpServer- Push to NuGet.org:
bash
dotnet nuget push bin/Release/*.nupkg \
--api-key YOUR_NUGET_API_KEY \
--source https://api.nuget.org/v3/index.json- Verify — users configure in :
mcp.json
json
{
"servers": {
"MyMcpServer": {
"type": "stdio",
"command": "dnx",
"args": ["YourUsername.MyMcpServer@1.0.0", "--yes"]
}
}
}For detailed NuGet packaging and trusted publishing setup, see references/nuget-packaging.md.
- **配置**的包属性:
.csproj
xml
<PropertyGroup>
<PackAsTool>true</PackAsTool>
<ToolCommandName>mymcpserver</ToolCommandName>
<PackageId>YourUsername.MyMcpServer</PackageId>
<Version>1.0.0</Version>
<Authors>Your Name</Authors>
<Description>MCP server for interacting with MyService</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>mcp;modelcontextprotocol;ai;llm</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>- 构建并打包:
bash
dotnet build -c Release
dotnet pack -c Release- 发布前本地测试:
bash
dotnet tool install --global --add-source bin/Release/ YourUsername.MyMcpServer
mymcpserver --help # 验证可正常运行
dotnet tool uninstall --global YourUsername.MyMcpServer- 推送到NuGet.org:
bash
dotnet nuget push bin/Release/*.nupkg \
--api-key YOUR_NUGET_API_KEY \
--source https://api.nuget.org/v3/index.json- 验证 — 用户在中配置使用:
mcp.json
json
{
"servers": {
"MyMcpServer": {
"type": "stdio",
"command": "dnx",
"args": ["YourUsername.MyMcpServer@1.0.0", "--yes"]
}
}
}如需了解详细的NuGet打包和可信发布设置,请查看references/nuget-packaging.md。
Step 2b: Docker containerization (HTTP servers)
步骤2b:Docker容器化(HTTP服务器)
- Create Dockerfile:
dockerfile
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY /app .- 创建Dockerfile:
dockerfile
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY /app .Non-root user for security
出于安全考虑使用非root用户
RUN adduser --disabled-password --gecos '' appuser
USER appuser
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3
CMD curl -f http://localhost:8080/health || exit 1 ENTRYPOINT ["dotnet", "MyMcpServer.dll"]
CMD curl -f http://localhost:8080/health || exit 1 ENTRYPOINT ["dotnet", "MyMcpServer.dll"]
2. **Build and test locally:**
```bash
docker build -t mymcpserver:latest .
docker run -d -p 3001:8080 -e API_KEY=test-key --name mymcpserver mymcpserver:latest
curl http://localhost:3001/health- Push to container registry:
bash
undefinedRUN adduser --disabled-password --gecos '' appuser
USER appuser
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3
CMD curl -f http://localhost:8080/health || exit 1 ENTRYPOINT ["dotnet", "MyMcpServer.dll"]
CMD curl -f http://localhost:8080/health || exit 1 ENTRYPOINT ["dotnet", "MyMcpServer.dll"]
2. **本地构建并测试:**
```bash
docker build -t mymcpserver:latest .
docker run -d -p 3001:8080 -e API_KEY=test-key --name mymcpserver mymcpserver:latest
curl http://localhost:3001/health- 推送到镜像仓库:
bash
undefinedDocker Hub
Docker Hub
docker tag mymcpserver:latest <yourusername>/<mymcpserver>:1.0.0
docker push <yourusername>/<mymcpserver>:1.0.0
docker tag mymcpserver:latest <yourusername>/<mymcpserver>:1.0.0
docker push <yourusername>/<mymcpserver>:1.0.0
Azure Container Registry
Azure Container Registry
az acr login --name yourregistry
docker tag mymcpserver:latest <yourregistry>.azurecr.io/<mymcpserver>:1.0.0
docker push <yourregistry>.azurecr.io/<mymcpserver>:1.0.0
undefinedaz acr login --name yourregistry
docker tag mymcpserver:latest <yourregistry>.azurecr.io/<mymcpserver>:1.0.0
docker push <yourregistry>.azurecr.io/<mymcpserver>:1.0.0
undefinedStep 3: Deploy to Azure (HTTP servers)
步骤3:部署到Azure(HTTP服务器)
Azure Container Apps (recommended — serverless with auto-scaling):
bash
az containerapp create \
--name mymcpserver \
--resource-group mygroup \
--environment myenvironment \
--image <yourregistry>.azurecr.io/<mymcpserver>:1.0.0 \
--target-port 8080 \
--ingress external \
--min-replicas 0 \
--max-replicas 10 \
--secrets api-key=my-actual-api-key \
--env-vars API_KEY=secretref:api-keyAzure App Service (traditional web hosting):
bash
az webapp create \
--name mymcpserver \
--resource-group mygroup \
--plan myplan \
--deployment-container-image-name <yourregistry>.azurecr.io/<mymcpserver>:1.0.0For detailed Azure deployment, see references/docker-azure.md.
Azure Container Apps(推荐 — 支持自动扩缩容的无服务器服务):
bash
az containerapp create \
--name mymcpserver \
--resource-group mygroup \
--environment myenvironment \
--image <yourregistry>.azurecr.io/<mymcpserver>:1.0.0 \
--target-port 8080 \
--ingress external \
--min-replicas 0 \
--max-replicas 10 \
--secrets api-key=my-actual-api-key \
--env-vars API_KEY=secretref:api-keyAzure App Service(传统Web托管):
bash
az webapp create \
--name mymcpserver \
--resource-group mygroup \
--plan myplan \
--deployment-container-image-name <yourregistry>.azurecr.io/<mymcpserver>:1.0.0如需了解详细的Azure部署方法,请查看references/docker-azure.md。
Step 4: Publish to MCP Registry (optional)
步骤4:发布到MCP Registry(可选)
List your server in the official MCP Registry for discoverability.
- Install :
mcp-publisher
bash
undefined将你的服务器上架到官方MCP Registry,方便用户检索发现。
- 安装:
mcp-publisher
bash
undefinedmacOS/Linux
macOS/Linux
brew install mcp-publisher
brew install mcp-publisher
Or download from https://github.com/modelcontextprotocol/registry/releases
2. **Create `.mcp/server.json`** (or run `mcp-publisher init` to generate interactively):
```json
{
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.username/servername",
"description": "Your server description",
"version": "1.0.0",
"packages": [{
"registryType": "nuget",
"registryBaseUrl": "https://api.nuget.org",
"identifier": "YourUsername.MyMcpServer",
"version": "1.0.0",
"transport": { "type": "stdio" }
}],
"repository": {
"url": "https://github.com/username/repo",
"source": "github"
}
}Version consistency (critical): The root,version, andpackages[].versionin<Version>must all match. A mismatch causes registry validation failures or users downloading the wrong version..csproj
- Authenticate and publish:
bash
mcp-publisher login github # name must be io.github.<username>/... for GitHub auth
mcp-publisher publish- Verify:
bash
curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.<username>/<servername>"For Registry details (namespace conventions, environment variables, CI/CD automation), see references/mcp-registry.md.
2. **创建`.mcp/server.json`**(也可运行`mcp-publisher init`交互式生成):
```json
{
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.username/servername",
"description": "Your server description",
"version": "1.0.0",
"packages": [{
"registryType": "nuget",
"registryBaseUrl": "https://api.nuget.org",
"identifier": "YourUsername.MyMcpServer",
"version": "1.0.0",
"transport": { "type": "stdio" }
}],
"repository": {
"url": "https://github.com/username/repo",
"source": "github"
}
}版本一致性(非常重要): 根节点的、version和packages[].version中的.csproj必须完全一致。版本不匹配会导致Registry校验失败,或者用户下载到错误的版本。<Version>
- 认证并发布:
bash
mcp-publisher login github # 如果使用GitHub认证,名称必须符合io.github.<username>/...的格式
mcp-publisher publish- 验证:
bash
curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.<username>/<servername>"如需了解Registry的详细信息(命名空间规范、环境变量、CI/CD自动化),请查看references/mcp-registry.md。
Step 5: Security checklist
步骤5:安全检查清单
- No hardcoded secrets — use environment variables or Key Vault
- HTTPS enabled for HTTP transport in production
- Health check endpoint implemented
- Input validation on all tool parameters
- Rate limiting considered for HTTP servers
- 无硬编码密钥 — 使用环境变量或Key Vault
- 生产环境的HTTP传输已启用HTTPS
- 已实现健康检查端点
- 所有工具参数都已做输入校验
- HTTP服务器已考虑限流配置
Validation
校验项
- NuGet: Package installs and runs via
dnx PackageId@version - Docker: Container starts and health check passes
- Azure: Server is reachable and tools respond
- MCP Registry: Server appears at
registry.modelcontextprotocol.io - MCP client can connect and call tools on the deployed server
- NuGet: 可通过安装并运行包
dnx PackageId@version - Docker: 容器可正常启动,健康检查通过
- Azure: 服务器可正常访问,工具可响应请求
- MCP Registry: 服务器可在上检索到
registry.modelcontextprotocol.io - MCP客户端可连接到部署后的服务器并调用工具
Common Pitfalls
常见问题
| Pitfall | Solution |
|---|---|
| NuGet package doesn't run as a tool | Missing |
Version mismatch between | Keep |
| Docker container exits immediately | Check entrypoint DLL name matches project output. Run |
| Azure Container App returns 502 | Target port mismatch. Ensure |
| MCP Registry rejects publish | Name must follow namespace convention: |
| API keys leaked in Docker image | Use multi-stage builds. Never |
| 问题 | 解决方案 |
|---|---|
| NuGet包无法作为工具运行 | |
| 保持 |
| Docker容器立即退出 | 检查入口点DLL名称是否与项目输出匹配,运行 |
| Azure Container App返回502错误 | 目标端口不匹配,确保 |
| MCP Registry拒绝发布请求 | 名称必须符合命名空间规范:使用GitHub认证时格式为 |
| API密钥泄露在Docker镜像中 | 使用多阶段构建,永远不要 |
Related Skills
相关技能
- — Create a new MCP server project
mcp-csharp-create - — Running and interactive debugging
mcp-csharp-debug - — Automated tests and evaluations
mcp-csharp-test
- — 创建新的MCP服务器项目
mcp-csharp-create - — 运行和交互式调试
mcp-csharp-debug - — 自动化测试和评估
mcp-csharp-test
Reference Files
参考文件
- references/nuget-packaging.md — Complete NuGet configuration,
.csprojfor MCP, NuGet.org push, testing withserver.json, version management. Load when: publishing a stdio server to NuGet.dnx - references/docker-azure.md — Production Dockerfile patterns, ACR setup, Azure Container Apps full configuration, App Service with Key Vault, secrets management. Load when: deploying an HTTP server to Docker or Azure.
- references/mcp-registry.md — CLI installation,
mcp-publisherschema, namespace conventions (GitHub vs DNS auth), CI/CD automation. Load when: publishing to the official MCP Registry.server.json
- references/nuget-packaging.md — 完整的NuGet 配置、MCP用的
.csproj配置、NuGet.org推送、server.json测试、版本管理。加载时机: 发布stdio服务器到NuGet时。dnx - references/docker-azure.md — 生产级Dockerfile模板、ACR设置、Azure Container Apps完整配置、集成Key Vault的App Service、密钥管理。加载时机: 部署HTTP服务器到Docker或Azure时。
- references/mcp-registry.md — CLI安装、
mcp-publisherschema、命名空间规范(GitHub vs DNS认证)、CI/CD自动化。加载时机: 发布到官方MCP Registry时。server.json
More Info
更多信息
- NuGet publishing — NuGet.org publishing guide
- Azure Container Apps — Serverless container hosting
- MCP Registry — Official MCP server registry
- NuGet发布 — NuGet.org发布指南
- Azure Container Apps — 无服务器容器托管服务
- MCP Registry — 官方MCP服务器Registry