DotNet MCP
英语| 中文
v0.0.3 -纯C#架构、统一MCP服务器和后端
A.NET程序集逆向工程和基于MCP(模型上下文协议)的修改工具。
文档
概述
DotNet MCP是一个提供。NET程序集分析和AI助手(如Claude)的修改功能。通过MCP协议,AI可以:
- 加载并分析。NET程序集(DLL/EXE)
- 将类型和方法分解为C#源代码或IL
- 搜索类型、方法和字符串(支持正则表达式/高级语法)
- 分析调用图、控制流图和依赖关系图
- 检查继承链、接口实现和方法重写
- 检测设计模式(Singleton、Factory、Observer等)
- 检测混淆并识别所使用的混淆器
- 自动检测Unity游戏组装路径
- 注入代码并修改程序集
建筑
flowchart TB
subgraph Client["Claude / IDE"]
end
Client -->|"MCP Protocol (stdio/HTTP)"| Server
subgraph Server["DotNetMcp.Server"]
Tools["MCP Tools (41)
Assembly | Search | Analysis | Modification | Instance"]
Registry["Backend Registry
(Local / Remote)"]
Tools --> Registry
end
Server --> Backend
subgraph Backend["DotNetMcp.Backend"]
Analysis["Core Analysis
Decompiler | CallGraph | CFG | XRef | Search"]
Modification["Core Modification
ILBuilder | CodeInjector | TypeFactory | Rewriter"]
end安全
API密钥验证
后端服务支持HTTP终结点的API密钥身份验证。
快速设置:
export API_KEYS="your-secret-key"支持的标头:
X-API-Key: your-api-keyAuthorization: Bearer your-api-key
排除的路径: /, /health, /openapi (无需身份验证)
备注:在生产中,始终配置API密钥。如果在没有配置API密钥的情况下在生产中运行,系统将记录严重警告。
多后端架构
flowchart TB
Client["Claude / IDE"] -->|"MCP Protocol"| Server
subgraph Server["DotNetMcp.Server"]
Registry["Backend Registry"]
end
Registry --> Local["Local Backend
(In-Process)"]
Registry -->|"HTTP + API Key"| Remote1["Remote Backend 1"]
Registry -->|"HTTP + API Key"| Remote2["Remote Backend 2"]通过AI进行后端管理
# Register backend with API Key authentication
User: Register remote backend http://server:5000 with API key "secret123"
AI: [Call register_remote_backend
id="analysis-1"
name="Analysis Server"
endpoint="http://server:5000"
apiKey="secret123"]
Successfully registered remote backend "Analysis Server"
# List all backends
User: List all backends
AI: [Call list_backends]
Available backends:
- local (default) - Local, Healthy
- analysis-1 - Remote, Healthy
# Set default backend
User: Use analysis-1 as default
AI: [Call set_default_backend id="analysis-1"]
Default backend set to "analysis-1"参数 register_remote_backend:
| 参数 | 必填 | 说明 |
|---|---|---|
id | 是 | 唯一后端ID |
name | 是 | 显示名称 |
endpoint | 是 | HTTP URL |
apiKey | 没有用于身份验证的 | API密钥 |
timeoutSeconds | 否 | 超时(默认值:30) |
快速开始
选项A:下载预构建二进制文件(不需要.NET SDK)
- 首选 并下载适用于您平台的zip:
| 平台 | 文件 |
|---|---|
| Windows x64 | DotNetMcp-win-x64.zip |
| Linux x64 | DotNetMcp-linux-x64.zip |
| Linux ARM64 | DotNetMcp-linux-arm64.zip |
| macOS x64 | DotNetMcp-osx-x64.zip |
| macOS ARM64(苹果硅) | DotNetMcp-osx-arm64.zip |
- 拉开拉链。您将找到一个可执行文件:
DotNetMcp.Server(或DotNetMcp.Server.exe在Windows上)。
- 仅限macOS/Linux --使其可执行:
chmod +x /path/to/DotNetMcp.Server- 配置Claude桌面--添加到
claude_desktop_config.json:
- 视窗: %APPDATA%\Claude\claude_desktop_config.json - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"dotnet-mcp": {
"command": "/path/to/DotNetMcp.Server",
"args": ["--stdio"]
}
}
}替换 /path/to/DotNetMcp.Server 以及提取的可执行文件的实际路径。
- 重新启动克劳德桌面。工具现在可用。
选项B:从源代码构建(需要.NET 10.0 SDK)
git clone https://github.com/xjoker/DotNetMCP.git
cd DotNetMCP
dotnet build在stdio模式下运行(适用于Claude Desktop):
dotnet run --project src/DotNetMcp.Server -- --stdio配置Claude Desktop(源代码构建):
{
"mcpServers": {
"dotnet-mcp": {
"command": "dotnet",
"args": [
"run",
"--project",
"/path/to/DotNetMCP/src/DotNetMcp.Server",
"--",
"--stdio"
]
}
}
}克劳德代码/其他MCP客户端
# Stdio mode — using the pre-built binary
claude mcp add dotnet-mcp -- /path/to/DotNetMcp.Server --stdio
# HTTP mode — start server first, then register
dotnet run --project src/DotNetMcp.Server &
claude mcp add dotnet-mcp --transport http --url http://localhost:5000/mcpMCP工具
装配管理(4)
| 工具 | 说明 |
|---|---|
load_assembly | 加载a。NET程序集 |
list_assemblies | 列出已加载的程序集 |
unload_assembly | 卸载组件 |
detect_unity_assembly | 自动检测Unity游戏目录中的Assembly-CSharp.dll |
搜索工具(2)
| 工具 | 说明 |
|---|---|
search_types | 按关键字搜索类型 |
search_strings | 搜索字符串文字 |
分析工具(20)
| 工具 | 说明 |
|---|---|
decompile_type | 将类型分解为C#/IL(支持PDB原始源代码) |
decompile_method | 精确分解单个方法 |
find_type_references | 查找类型引用 |
find_method_calls | 查找方法调用 |
get_call_graph | 构建调用图 |
get_control_flow_graph | 构建控制流图(Mermaid) |
get_type_outline | 获取基于元数据的类型大纲(无需反编译) |
plan_chunking | 计划LLM友好的源代码块 |
compare_assemblies | 比较两个组件的结构差异 |
batch_decompile | 在一次调用中分解多个成员 |
get_dependency_graph | 构建程序集/命名空间/类型依赖关系图(Mermaid) |
detect_design_patterns | 检测Singleton、Factory、Observer和其他设计模式 |
find_base_types | 查找类型的基类链和接口 |
find_derived_types | 查找从给定类型继承的所有类型 |
get_implementations | 查找接口的所有实现 |
get_overrides | 查找虚拟/抽象方法的所有重写 |
get_overloads | 查找类型中方法的所有重载 |
enhanced_search | 具有高级语法的统一搜索(正则表达式/+/-/精确/模糊/令牌) |
detect_obfuscation | 检测混淆,识别混淆者,评分0-100 |
warm_index | 预构建类型和成员索引,以实现更快的后续查询 |
修改工具(6)
| 工具 | 说明 |
|---|---|
inject_at_entry | 在方法入口注入代码 |
replace_method_body | 用原始IL指令替换方法体 |
replace_method_body_with_csharp | 使用C#源代码替换方法体(Roslyn编译+Cecil合并) |
add_type | 添加新类型 |
save_assembly | 保存修改后的组件 |
generate_patch_skeleton | 生成Harmony补丁骨架代码 |
实例管理
后端管理(5)
| 工具 | 说明 |
|---|---|
list_backends | 列出所有后端 |
register_remote_backend | 注册远程后端 |
unregister_backend | 注销后端 |
set_default_backend | 设置默认后端 |
check_backend_health | 检查后端运行状况 |
装配别名管理(4)
| 工具 | 说明 |
|---|---|
register_assembly_alias | 为加载的程序集MVID注册一个短别名 |
unregister_assembly_alias | 删除以前注册的别名 |
list_assembly_aliases | 列出所有已注册的别名(alias→ MVID映射) |
instance_restore_persisted | 从上一个会话中保存的持久别名重新加载程序集 |
使用示例
加载和分析组件
User: Load /path/to/MyApp.dll and tell me what types it contains
AI: [Call load_assembly]
[Call search_types keyword=""]
Loaded assembly MyApp.dll, containing the following types:
- MyApp.Program (class, 5 methods)
- MyApp.Services.UserService (class, 10 methods)
...分解和分析
User: Decompile the UserService class
AI: [Call decompile_type typeName="MyApp.Services.UserService"]
public class UserService
{
private readonly IDatabase _db;
public User GetUser(int id)
{
return _db.Query().FirstOrDefault(u => u.Id == id);
}
...
}注入代码
User: Add logging at GetUser method entry
AI: [Call inject_at_entry
methodFullName="MyApp.Services.UserService.GetUser"
instructions=[
{"opCode": "ldstr", "stringValue": "GetUser called"},
{"opCode": "call", "stringValue": "System.Console::WriteLine"}
]]
Logging code injected at GetUser method entry.测试
# Run all tests
dotnet test
# Run Server tests only
dotnet test tests/DotNetMcp.Server.Tests
# Run Backend tests only
dotnet test tests/DotNetMcp.Backend.Tests当前测试状态:
- 后端测试:135通过
- 服务器测试:96通过
项目结构
DotNetMCP/
├── src/
│ ├── DotNetMcp.Server/ # MCP Server
│ │ ├── Tools/ # MCP Tool implementations
│ │ ├── Backend/ # Backend registration & management
│ │ └── Configuration/ # Configuration
│ └── DotNetMcp.Backend/ # Core Backend
│ ├── Core/
│ │ ├── Analysis/ # Analysis services
│ │ ├── Modification/ # Modification services
│ │ ├── Context/ # Assembly context
│ │ └── Identity/ # ID system
│ ├── Services/ # Business services
│ └── Controllers/ # HTTP API
├── tests/
│ ├── DotNetMcp.Server.Tests/ # Server unit tests
│ └── DotNetMcp.Backend.Tests/ # Backend unit tests
└── docs/
├── zh/ # Chinese docs
└── en/ # English docs技术栈
- .NET 10.0 -运行时间
- 模型上下文协议 -MCP-SDK
- 单声道。塞西尔 -装配操作
- ICSharpCode。反编译器 -反编译
- 微软。代码分析 -罗斯林汇编
Docker 部署
没有发布预构建的Docker镜像。从源构建映像:
塑造形象
git clone https://github.com/xjoker/DotNetMCP.git
cd DotNetMCP
docker build -t dotnet-mcp .运行(HTTP模式)
服务器在Docker中以HTTP模式运行。装载包含要分析的DLL/EXE文件的目录:
docker run -p 5000:5000 \
-v /path/to/your/assemblies:/data \
dotnet-mcp服务器将在以下时间可用 http://localhost:5000. 健康检查端点: http://localhost:5000/health
在Claude内部加载组件时,使用容器路径(例如。 /data/MyApp.dll).
使用API密钥运行
docker run -p 5000:5000 \
-v /path/to/your/assemblies:/data \
-e API_KEYS="your-secret-key" \
dotnet-mcp将Claude连接到Docker容器
容器运行后,将其注册为MCP服务器:
claude mcp add dotnet-mcp --transport http --url http://localhost:5000/mcp或添加到 claude_desktop_config.json 手动(Claude Desktop的内置MCP不支持HTTP传输,请使用stdio二进制文件进行桌面使用)。
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
ASPNETCORE_URLS | http://+:5000 | 收听地址 |
API_KEYS | *(无)* | 用于身份验证的逗号分隔API密钥 |
TZ | UTC | 时区 |
备注:标准模式(--stdio)不适用于Docker。使用HTTP模式并通过以下方式连接Claudehttp://localhost:5000/mcp.
