使用说明
ILSpy MCP服务器
一种模型上下文协议(MCP)服务器,提供。NET程序集反编译功能使用ILSpy。
特性
- 分解程序集:转换。NET程序集返回可读的C#源代码
- 列表类型:枚举程序集中的类、接口、结构、委托和枚举
- 生成图表:创建程序集结构的交互式HTML可视化
- 程序集信息:获取有关的元数据。NET程序集
先决条件
-
ILSpy命令行工具:安装全局.NET工具:
dotnet tool install --global ilspycmd -
Python 3.8+:运行MCP服务器所需
安装
从PyPI安装:
pip install ilspy-mcp-server
或用于开发:
git clone https://github.com/Borealin/ilspy-mcp-server.git
cd ilspy-mcp-server
pip install -e .
用法
MCP客户端配置
配置您的MCP客户端(例如Claude Desktop)以使用服务器:
{
"mcpServers": {
"ilspy": {
"command": "python",
"args": ["-m", "ilspy_mcp_server.server"]
}
}
}
可用工具
1. decompile_assembly
分解a。NET程序集转换为C#源代码。
参数:
assembly_path(必填):路径。NET程序集文件output_dir(可选):反编译文件的输出目录type_name(可选):要反编译的特定类型language_version(可选):C#语言版本(默认:“最新”)create_project(可选):创建可编译的项目结构show_il_code(可选):显示IL代码而不是C#remove_dead_code(可选):在反编译过程中删除死代码nested_directories(可选):对命名空间使用嵌套目录
例子:
{
"name": "decompile_assembly",
"arguments": {
"assembly_path": "/path/to/MyAssembly.dll",
"type_name": "MyNamespace.MyClass",
"language_version": "CSharp10_0"
}
}
2. list_types
在中列出类型。NET程序集。
参数:
assembly_path(必填):路径。NET程序集文件entity_types(可选):要列出的实体类型数组(“c”、“i”、“s”、“d”、“e”)
例子:
{
"name": "list_types",
"arguments": {
"assembly_path": "/path/to/MyAssembly.dll",
"entity_types": ["c", "i"]
}
}
3. generate_diagrammer
生成交互式HTML图表。
参数:
assembly_path(必填):路径。NET程序集文件output_dir(可选):图表绘制器的输出目录include_pattern(可选):要包含的类型的正则表达式模式exclude_pattern(可选):用于排除类型的正则表达式模式
4. get_assembly_info
获取程序集的基本信息。
参数:
assembly_path(必填):路径。NET程序集文件
可用提示
1. analyze_assembly
分析a。NET程序集,并提供有关其结构的见解。
2. decompile_and_explain
分解特定类型并解释其功能。
支持的装配类型
- .NET Framework程序集(.dll、.exe)
- .NET核心/。NET 5+程序集
- 带的可移植可执行文件(PE)。NET元数据
支持的C#语言版本
- CSharp1至CSharp12_0
- 预览
- 最新(默认)
快速开始
-
安装软件包:
pip install ilspy-mcp-server -
配置您的MCP客户端 (克劳德桌面示例):
{ "mcpServers": { "ilspy": { "command": "python", "args": ["-m", "ilspy_mcp_server.server"] } } } -
使用工具 在您的MCP客户端中:
- 要求反编译。NET程序集
- 列出程序集中的类型
- 生成交互式图表
- 获取装配信息
错误处理
服务器为常见问题提供详细的错误消息:
- 找不到程序集文件
- 程序集格式无效
- ILSpyCmd未安装或未在PATH中
- 权限问题
- 反编译失败
配置
环境变量
LOGLEVEL:设置日志记录级别(调试、信息、警告、错误)。默认值:信息
MCP客户端示例
克劳德桌面 (config.json):
{
"mcpServers": {
"ilspy": {
"command": "python",
"args": ["-m", "ilspy_mcp_server.server"],
"env": {
"LOGLEVEL": "INFO"
}
}
}
}
开发/测试:
{
"mcpServers": {
"ilspy": {
"command": "python",
"args": ["-m", "ilspy_mcp_server.server"],
"env": {
"LOGLEVEL": "DEBUG"
}
}
}
}
故障排除
常见问题
-
“找不到ILSpyCmd”:
dotnet tool install --global ilspycmd -
“找不到程序集文件”:
- 检查文件路径是否正确
- 确保文件的扩展名为.dll或.exe
-
权限错误:
- 确保对程序集文件的读取权限
- 检查输出目录权限
调试模式
启用调试日志记录以查看详细的操作信息:
{
"env": {
"LOGLEVEL": "DEBUG"
}
}
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
