.NET构建服务器

一个使用MCP协议和TOON格式输出优化LLM消费的.NET项目构建服务器。

  • by manueljmv
  • C#
  • 本地部署
  • 更新于
在 GitHub 查看 manueljmv/mcp-dotnet

使用说明

MCP。NET构建服务器

用于构建的模型上下文协议(MCP)服务器。NET项目使用 dotnet build TOON格式的输出针对LLM消费进行了优化。

特性

  • 建造。NET项目和MCP协议解决方案
  • 紧凑的TOON格式输出,针对LLM令牌效率进行了优化
  • 自动错误重复数据删除和聚合
  • 简洁输出的相对文件路径
  • 同一文件中多个错误的表格格式
  • 支持所有人 dotnet build 参数

安装

需求

  • .NET 9.0或更高版本
  • NuGet包:
    • ModelContextProtocol 0.2.0-复习。1
    • Microsoft.Extensions.Hosting 9.0.0
    • Microsoft.Extensions.Http 9.0.0
    • System.Text.Json 10.0.1
    • Toon.DotNet 1.6.1

构建

dotnet build

作为MCP服务器运行

dotnet run

服务器使用stdio传输进行MCP通信。

工具: Build

构建一个。NET项目或解决方案,并以TOON格式返回结果。

参数

参数 类型 默认值 说明
projectPath 弦? null 项目或解决方案文件的路径。如果为null,则使用当前目录。
configuration 弦? null 构建配置(例如“调试”、“发布”)
framework 弦? null 要构建的目标框架
outputDir 弦? null 生成工件的输出目录
noRestore bool false 在构建之前跳过项目还原
verbosity 弦? null MSBuild详细级别:安静、最小、正常、详细、诊断
noDependencies bool false 不生成项目到项目的引用
errorsOnly bool的。 真 仅返回错误,不返回警告或其他信息

输出格式

仅错误模式(默认)

返回一个仅包含错误信息的紧凑结果:

buildResult:
  success: false
  errors[1	]{code,count,files,message}:
    CS0246	2	"Member.cs:4,7;Program.cs:3,4;Utils.cs:4,7,10"	The type or namespace name 'UndefinedType' could not be found (are you missing a using directive or an assembly reference?)

完整模式(errorsOnly=false)

包括错误、警告和编译统计信息:

buildResult:
  success: false
  configuration: Release
  errors[1	]{code,count,files,message}:
    CS0246	2	"Member.cs:4,7;Program.cs:3,4"	The type or namespace name 'UndefinedType' could not be found (are you missing a using directive or an assembly reference?)
  warnings[2	]{code,count,files,message}:
    CS0167	3	"Utils.cs:5,10,15"	The private field 'unusedField' is never used
    CS0219	1	"Member.cs:20"	The variable 'x' is assigned but its value is never used
  compileStats:
    files: 15
    errors: 2
    warnings: 3

文件格式规范

这 files 字段使用紧凑的格式按文件对错误进行分组:

<filename>:<line1>,<line2>,<line3>;<filename2>:<line1>,<line2>
  • : 将文件名与行号分开
  • , 分隔同一文件的行号
  • ; 分隔不同的文件

示例

"Member.cs:4,7,23;Program.cs:3,10;Utils.cs:5,8,12"

这代表:

  • Member.cs:第4、7、23行
  • Program.cs:第3、10行
  • Utils.cs:第5、8、12行

项目结构

mcp-dotnet/
├── Models/
│   └── BuildResult.cs          # Data models for build results
├── Helpers/
│   └── DotNetBuildParser.cs    # Parser and TOON serializer
├── Tools/
│   └── DotNetBuildTool.cs      # MCP tool implementation
├── Program.cs                   # Server initialization
└── mcp-dotnet.csproj           # Project configuration

使用示例

构建当前目录(仅错误-默认)

{
  "name": "build",
  "arguments": {}
}

构建具有完整输出的特定项目

{
  "name": "build",
  "arguments": {
    "projectPath": "/path/to/project.csproj",
    "configuration": "Release",
    "errorsOnly": false
  }
}

使用自定义详细信息构建

{
  "name": "build",
  "arguments": {
    "projectPath": "/path/to/solution.sln",
    "verbosity": "detailed"
  }
}

TOON格式的优点

TOON(面向令牌的对象表示法)提供:

  • 代币减少约60% 与统一数据结构的JSON相比
  • 表格格式 对于具有相同字段的对象数组
  • 人类可读 语法类似于YAML,但更紧凑
  • LLM优化 具有显式的数组长度和字段头

重复数据删除错误

服务器会自动消除重复错误消息:

  1. 相同的错误,不同的位置:按错误代码分组,显示一次消息
  2. 相同的错误,相同的文件,多行:聚合每个文件的行号
  3. 相对路径:所有路径都是相对于项目根的

重复数据删除示例:

Before: Program.cs:3,Program.cs:5,Member.cs:4,Member.cs:7
After:  "Member.cs:4,7;Program.cs:3,5"

许可证

MIT许可证