Skip to main content
Glama
jcucci

dotnet-sherlock-mcp

Sherlock MCP for .NET

Sherlock MCP for .NET 是一个全面的模型上下文协议 (MCP) 服务器,为 .NET 程序集提供深度内省能力。它使大语言模型 (LLM) 能够精确地分析和理解您的 .NET 代码,从而为复杂的开发场景提供准确且具备上下文感知的响应。

对于希望利用 LLM 能力进行以下工作的开发者来说,此工具至关重要:

  • 深度代码库分析 - 理解复杂的 .NET 架构和依赖关系

  • 精确的类型信息 - 获取有关类型、成员及其签名的详细元数据

  • 自动化文档 - 提取并利用 XML 文档和特性

  • 自定义工具 - 构建与 .NET 程序集交互的复杂工具

  • 代码生成 - 基于现有类型结构创建准确的代码

主要功能

  • 全面的 MCP 服务器:提供 31+ 个用于 .NET 程序集分析的专用工具

  • 高级程序集内省:基于反射的类型、成员和元数据深度分析

  • 丰富的成员分析:详细检查方法、属性、字段、事件和构造函数

  • 智能过滤与分页:按名称/特性进行高级过滤,并为大数据集提供高效分页

  • XML 文档集成:自动提取摘要、参数、返回值和备注

  • 性能优化:缓存、流式处理和内存高效处理

  • 稳定的 JSON API:具有版本控制和结构化错误代码的一致性封装

  • .NET 9.0 原生:基于最新的 .NET 平台,具备现代 C# 特性

  • 项目集成:具有依赖解析功能的解决方案和项目文件分析

安装

从 NuGet 安装全局工具(将 sherlock-mcp 添加到您的 PATH):

dotnet tool install -g Sherlock.MCP.Server

或者,在开发过程中,您可以在本地运行服务器:

dotnet run --project src/server/Sherlock.MCP.Server.csproj

配置您的 MCP 客户端

Sherlock 作为标准 MCP 服务器运行,通过 stdio 进行通信。

  • Cursor:设置 → MCP / 自定义工具 → 添加工具 → 命令:sherlock-mcp

  • Claude Desktop / 其他 MCP 客户端:添加一个指向 sherlock-mcp 命令的服务器条目。示例 JSON 条目(请参阅您的客户端文档以获取确切的文件位置/格式):

{
  "servers": {
    "sherlock": {
      "command": "sherlock-mcp"
    }
  }
}

无需参数。服务器在启动时会自动注册所有工具。

.NET 项目自动配置

要在处理 .NET 代码时自动使用 Sherlock,请添加以下配置:

Claude Code (CLAUDE.md)

将其添加到您项目的 CLAUDE.md 文件中:

## .NET Assembly Analysis

This project uses Sherlock MCP for .NET assembly analysis. When analyzing .NET types, methods, or assemblies:

1. Use sherlock-mcp tools instead of guessing about .NET APIs
2. For type analysis: `GetTypeInfo`, `GetTypeMethods`, `GetTypeProperties`
3. For assembly overview: `AnalyzeAssembly` or `GetTypesFromAssembly`
4. For project structure: `AnalyzeProject`, `AnalyzeSolution`
5. Assembly paths are typically: `./bin/Debug/net9.0/ProjectName.dll`

Always include assembly path, prefer full type names, and use pagination for large results.

Cursor (.cursorrules)

将其添加到您项目的 .cursorrules 文件中:

# .NET Analysis Rules
When working with .NET code, assemblies, or types:
- Use sherlock-mcp tools for accurate type/member information
- Assembly paths: ./bin/Debug/net9.0/*.dll or ./bin/Release/net9.0/*.dll
- For unknown types: GetTypesFromAssembly -> GetTypeInfo -> GetTypeMethods/Properties
- For code analysis: AnalyzeAssembly for overview, GetTypeInfo for details
- Use pagination (maxItems=50) for large results to avoid token limits

全局配置

对于系统范围的使用,请添加到您的全局 Claude Code 设置或 Cursor 配置中:

For .NET development: Use sherlock-mcp tools when analyzing assemblies, types, methods, or project structure. Prefer these over guessing .NET API details.

如何提示它

以下是紧凑的提示片段,您可以将其粘贴到聊天中以快速提高工作效率。请根据您的本地 DLL 调整路径。

常规设置

You have access to an MCP server named "sherlock" that can analyze .NET assemblies. Prefer these tools for .NET questions and include short reasoning for which tool you chose. Ask me for the assembly path if missing.

枚举类型的成员

Analyze: /absolute/path/to/MyLib/bin/Debug/net9.0/MyLib.dll
Type: MyNamespace.MyType
List methods, including non-public, filter name contains "Async", include attributes, return JSON.

获取成员的 XML 文档

Use GetXmlDocsForMember on /abs/path/MyLib.dll, type MyNamespace.MyType, member TryParse. Summarize the summary + params.

查找类型并深入分析

List types from /abs/path/MyLib.dll; then get type info for the first result and list its nested types.

调整分页和过滤器

Use GetTypeMethods on /abs/path/MyLib.dll, type MyNamespace.MyType, sortBy name, sortOrder asc, skip 0, take 25, hasAttributeContains Obsolete.

工具概览

程序集发现与分析

  • AnalyzeAssembly:包含公共类型和元数据的完整程序集概览

  • FindAssemblyByClassName:定位包含特定类名的程序集

  • FindAssemblyByFileName:在常见构建路径中按文件名查找程序集

类型内省

  • GetTypesFromAssembly:列出所有带有元数据的公共类型(分页)

  • AnalyzeType:包含所有成员的全面类型分析

  • GetTypeInfo:详细的类型元数据(可访问性、泛型、嵌套类型)

  • GetTypeHierarchy:继承链和接口实现

  • GetGenericTypeInfo:泛型参数、实参和变体信息

  • GetTypeAttributes:在类型上声明的自定义特性

  • GetNestedTypes:嵌套类型声明

成员分析(可过滤且分页)

  • GetAllTypeMembers:所有类别中的所有成员

  • GetTypeMethods:方法签名、重载和元数据

  • GetTypeProperties:属性详情,包括 getter/setter 和索引器

  • GetTypeFields:字段信息,包括常量和只读字段

  • GetTypeEvents:带有处理程序类型的事件声明

  • GetTypeConstructors:构造函数签名和参数

  • AnalyzeMethod:带有重载和特性的深度方法分析

反向查找

  • FindImplementationsOf:实现接口或派生自基类的类型

  • FindMethodsReturning:返回类型与给定类型匹配的方法(支持开放泛型匹配)

  • FindReferencesTo:跨参数、字段、属性、事件和泛型参数的更广泛扫描

特性与元数据

  • GetMemberAttributes:特定成员的特性

  • GetParameterAttributes:参数级特性信息

XML 文档

  • GetXmlDocsForType:提取类型级 XML 文档

  • GetXmlDocsForMember:成员特定文档(摘要/参数/返回值/备注)

项目与解决方案分析

  • AnalyzeSolution:解析 .sln 文件并枚举项目

  • AnalyzeProject:项目元数据、引用和构建配置

  • GetProjectOutputPaths:解析不同配置的输出目录

  • ResolvePackageReferences:将 NuGet 包映射到缓存的程序集

  • FindDepsJsonDependencies:解析 deps.json 以获取运行时依赖项

配置与运行时

  • GetRuntimeOptions:当前服务器配置和默认值

  • UpdateRuntimeOptions:修改分页、缓存和搜索行为

高级过滤与分页

所有成员分析工具都支持全面的过滤和分页:

过滤选项:

  • caseSensitive (bool):区分大小写的类型/成员匹配

  • nameContains (string):按成员名称子字符串过滤

  • hasAttributeContains (string):按特性类型子字符串过滤

  • includePublic / includeNonPublic (bool):可见性过滤

  • includeStatic / includeInstance (bool):成员类型过滤

分页:

  • skip / take (int):标准偏移分页

  • maxItems (int):每个请求的最大结果数

  • continuationToken (string):用于大数据集的基于令牌的分页

  • sortBy / sortOrder (string):按名称/访问权限以升序/降序排序

类型解析:

  • 支持全名 (Namespace.Type)、简单名称 (Type) 和嵌套类型 (Outer+Inner)

  • 大小写敏感度由 caseSensitive 参数控制

  • 针对歧义类型名称的自动回退解析

响应模式

所有工具都返回一个稳定的 JSON 封装:

{ "kind": "type.list|member.methods|...", "version": "1.0.0", "data": { /* result */ } }

错误使用一致的形状:

{ "kind": "error", "version": "1.0.0", "code": "AssemblyNotFound|TypeNotFound|InvalidArgument|InternalError", "message": "...", "details": { } }

Common error codes include `AssemblyNotFound`, `TypeNotFound`, `MemberNotFound`, `InvalidArgument`, and `InternalError`.

贡献

欢迎贡献。此仓库包含一个带有现代 C# 首选项(文件范围命名空间、表达式体成员、4 空格缩进)的 .editorconfig

提交消息格式

本项目使用 Conventional Commits 进行自动变更日志生成。所有提交必须遵循此格式:

type(scope): description

有效类型:

  • feat - 新功能

  • fix - 错误修复

  • docs - 仅文档更改

  • style - 代码样式更改(格式化、分号等)

  • refactor - 既不修复错误也不添加功能的代码更改

  • perf - 性能改进

  • test - 添加或更正测试

  • build - 构建系统或依赖项的更改

  • ci - CI 配置的更改

  • chore - 不修改 src 或测试文件的其他更改

  • revert - 还原先前的提交

示例:

git commit -m "feat(tools): add new assembly analysis tool"
git commit -m "fix: resolve null reference in type loader"
git commit -m "docs(readme): update installation instructions"

开发设置

# Restore .NET tools (versionize, husky)
dotnet tool restore

# Install git hooks for commit validation
dotnet husky install

指南

  • 保持更改小而集中;为新行为添加单元测试。

  • 添加工具时,请遵循响应封装和错误代码约定。

  • 在打开 PR 之前,请在本地运行 dotnet builddotnet test

创建发布

维护者可以使用以下方式创建发布:

# Restore tools if not already done
dotnet tool restore

# Preview what will change
dotnet versionize --dry-run

# Create release (bumps version, updates changelog, creates git tag)
dotnet versionize

# Push changes and tag to trigger release workflow
git push --follow-tags

发布工作流将自动:

  1. 构建并测试项目

  2. 创建带有变更日志说明的 GitHub Release

  3. 发布 NuGet 包

  4. 使用新版本更新 server.json

MCP 注册表

mcp-name: io.github.jcucci/dotnet-sherlock-mcp

许可证

Sherlock MCP for .NET 在 MIT 许可证 下授权。

A
license - permissive license
-
quality - not tested
C
maintenance

Maintenance

Maintainers
7dResponse time
8wRelease cycle
3Releases (12mo)
Issues opened vs closed

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jcucci/dotnet-sherlock-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server