-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
56 lines (51 loc) · 2.6 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
56 lines (51 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace SharpTools.Tools.Extensions;
/// <summary>
/// Extension methods for IServiceCollection to register SharpTools services.
/// </summary>
public static class ServiceCollectionExtensions {
/// <summary>
/// Adds all SharpTools services to the service collection.
/// </summary>
/// <param name="services">The service collection to add services to.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection WithSharpToolsServices(this IServiceCollection services, bool enableGit = true, string? buildConfiguration = null) {
services.AddSingleton<IFuzzyFqnLookupService, FuzzyFqnLookupService>();
services.AddSingleton<ISolutionManager>(sp =>
new SolutionManager(
sp.GetRequiredService<ILogger<SolutionManager>>(),
sp.GetRequiredService<IFuzzyFqnLookupService>(),
buildConfiguration
)
);
services.AddSingleton<ICodeAnalysisService, CodeAnalysisService>();
if (enableGit) {
services.AddSingleton<IGitService, GitService>();
} else {
services.AddSingleton<IGitService, NoOpGitService>();
}
services.AddSingleton<ICodeModificationService, CodeModificationService>();
services.AddSingleton<IEditorConfigProvider, EditorConfigProvider>();
services.AddSingleton<IDocumentOperationsService, DocumentOperationsService>();
services.AddSingleton<IComplexityAnalysisService, ComplexityAnalysisService>();
services.AddSingleton<ISemanticSimilarityService, SemanticSimilarityService>();
services.AddSingleton<ISourceResolutionService, SourceResolutionService>();
return services;
}
/// <summary>
/// Adds all SharpTools services and tools to the MCP service builder.
/// </summary>
/// <param name="builder">The MCP service builder.</param>
/// <param name="exclude">Tool assembly type names to exclude (e.g. AnalysisTools).</param>
/// <returns>The MCP service builder for chaining.</returns>
public static IMcpServerBuilder WithSharpTools(this IMcpServerBuilder builder, List<string> exclude) {
var toolAssembly = Assembly.Load("SharpTools.Tools");
var excludedSet = new HashSet<string>(exclude);
var tools = from t in toolAssembly.GetTypes()
where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
&& !excludedSet.Contains(t.Name)
select t;
return builder
.WithTools(tools)
.WithPromptsFromAssembly(toolAssembly);
}
}