Skip to content

Commit eb9ce8b

Browse files
committed
Enhance XML documentation across various tools
1 parent aa8194f commit eb9ce8b

8 files changed

Lines changed: 145 additions & 33 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NetContextServer.Models;
2+
3+
/// <summary>
4+
/// Response model for ignore pattern operations containing default, user-defined, and combined patterns.
5+
/// </summary>
6+
public class IgnorePatternsResponse
7+
{
8+
/// <summary>
9+
/// Gets or sets the default ignore patterns that are always active.
10+
/// </summary>
11+
public string[] DefaultPatterns { get; set; } = [];
12+
13+
/// <summary>
14+
/// Gets or sets the user-defined ignore patterns.
15+
/// </summary>
16+
public string[] UserPatterns { get; set; } = [];
17+
18+
/// <summary>
19+
/// Gets or sets all active ignore patterns (both default and user-defined).
20+
/// </summary>
21+
public string[] AllPatterns { get; set; } = [];
22+
}

src/NetContextServer/Services/IgnorePatternService.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -241,25 +241,4 @@ public static bool ShouldIgnoreFile(string filePath)
241241
return Path.GetFileName(filePath).Equals(pattern, StringComparison.OrdinalIgnoreCase);
242242
});
243243
}
244-
245-
/// <summary>
246-
/// Response model for ignore pattern operations containing default, user-defined, and combined patterns.
247-
/// </summary>
248-
private class IgnorePatternsResponse
249-
{
250-
/// <summary>
251-
/// Gets or sets the default ignore patterns that are always active.
252-
/// </summary>
253-
public string[] DefaultPatterns { get; set; } = [];
254-
255-
/// <summary>
256-
/// Gets or sets the user-defined ignore patterns.
257-
/// </summary>
258-
public string[] UserPatterns { get; set; } = [];
259-
260-
/// <summary>
261-
/// Gets or sets all active ignore patterns (both default and user-defined).
262-
/// </summary>
263-
public string[] AllPatterns { get; set; } = [];
264-
}
265244
}

src/NetContextServer/Tools/FileTools.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,96 @@
55

66
namespace NetContextServer.Tools;
77

8+
/// <summary>
9+
/// Provides MCP tools for file system operations, including file listing, project discovery, and file access.
10+
/// </summary>
811
[McpToolType]
912
public static class FileTools
1013
{
11-
// Shared JsonSerializerOptions instance to improve performance
14+
/// <summary>
15+
/// Default JSON serializer options used across all file tools.
16+
/// </summary>
1217
private static readonly JsonSerializerOptions DefaultJsonOptions = new()
1318
{
1419
WriteIndented = true
1520
};
1621

22+
/// <summary>
23+
/// Standard error message for directory not found scenarios.
24+
/// </summary>
1725
private static readonly string[] ErrorDirectoryNotFound = ["Error: Directory not found"];
1826

27+
/// <summary>
28+
/// Lists all .NET source files in the specified project directory.
29+
/// </summary>
30+
/// <param name="projectPath">Absolute path to the project directory containing the .cs files.</param>
31+
/// <returns>A JSON string containing an array of file paths.</returns>
1932
[McpTool("list_files")]
2033
[Description("Lists all .NET source files in the specified project directory.")]
2134
public static string ListFiles(
2235
[Description("Absolute path to the project directory containing the .cs files")]
2336
string projectPath) =>
2437
JsonSerializer.Serialize(FileService.ListFiles(projectPath), DefaultJsonOptions);
2538

39+
/// <summary>
40+
/// Scans the current solution and returns all .csproj files found.
41+
/// </summary>
42+
/// <returns>A JSON string containing an array of project file paths.</returns>
2643
[McpTool("list_projects")]
2744
[Description("Scans the current solution and returns all .csproj files found.")]
2845
public static string ListProjects() =>
2946
JsonSerializer.Serialize(FileService.ListProjects(), DefaultJsonOptions);
3047

48+
/// <summary>
49+
/// Searches a specific directory for .csproj files.
50+
/// </summary>
51+
/// <param name="directory">Absolute path to the directory to search for .csproj files.</param>
52+
/// <returns>A JSON string containing an array of project file paths.</returns>
3153
[McpTool("list_projects_in_dir")]
3254
[Description("Searches a specific directory for .csproj files.")]
3355
public static string ListProjectsInDirectory(
3456
[Description("Absolute path to the directory to search for .csproj files")]
3557
string directory) =>
3658
JsonSerializer.Serialize(FileService.ListProjectsInDirectory(directory), DefaultJsonOptions);
3759

60+
/// <summary>
61+
/// Returns all .sln files found in the base directory.
62+
/// </summary>
63+
/// <returns>A JSON string containing an array of solution file paths.</returns>
3864
[McpTool("list_solutions")]
3965
[Description("Returns all .sln files found in the base directory.")]
4066
public static string ListSolutions() =>
4167
JsonSerializer.Serialize(FileService.ListSolutions(), DefaultJsonOptions);
4268

69+
/// <summary>
70+
/// Lists all source files in a project directory.
71+
/// </summary>
72+
/// <param name="projectDir">Absolute path to the project directory to scan for source files.</param>
73+
/// <returns>A JSON string containing an array of source file paths.</returns>
4374
[McpTool("list_source_files")]
4475
[Description("Lists all source files in a project directory.")]
4576
public static string ListSourceFiles(
4677
[Description("Absolute path to the project directory to scan for source files")]
4778
string projectDir) =>
4879
JsonSerializer.Serialize(FileService.ListSourceFiles(projectDir), DefaultJsonOptions);
4980

81+
/// <summary>
82+
/// Reads and returns the contents of a specified file.
83+
/// </summary>
84+
/// <param name="filePath">Absolute path to the file to read.</param>
85+
/// <returns>The contents of the file, or an error message if the file cannot be read.</returns>
5086
[McpTool("open_file")]
5187
[Description("Reads and returns the contents of a specified file.")]
5288
public static string OpenFile(
5389
[Description("Absolute path to the file to read")]
5490
string filePath) =>
5591
FileService.OpenFile(filePath);
5692

93+
/// <summary>
94+
/// Sets the base directory for all file operations.
95+
/// </summary>
96+
/// <param name="directory">Absolute path to set as the new base directory. Must be a valid, existing directory.</param>
97+
/// <returns>A JSON string containing a confirmation message or an error message.</returns>
5798
[McpTool("set_base_directory")]
5899
[Description("Sets the base directory for all file operations.")]
59100
public static string SetBaseDirectory(
@@ -70,6 +111,10 @@ public static string SetBaseDirectory(
70111
return JsonSerializer.Serialize(new[] { $"Base directory set to: {directory}" }, DefaultJsonOptions);
71112
}
72113

114+
/// <summary>
115+
/// Returns the current base directory used for all file operations.
116+
/// </summary>
117+
/// <returns>A JSON string containing the current base directory and whether it exists.</returns>
73118
[McpTool("get_base_directory")]
74119
[Description("Returns the current base directory used for all file operations.")]
75120
public static string GetBaseDirectory()
@@ -90,4 +135,4 @@ public static string GetBaseDirectory()
90135
return JsonSerializer.Serialize(new { Error = ex.Message }, DefaultJsonOptions);
91136
}
92137
}
93-
}
138+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
using ModelContextProtocol;
21
using ModelContextProtocol.Server;
32
using System.ComponentModel;
43

54
namespace NetContextServer.Tools;
65

6+
/// <summary>
7+
/// Provides general utility tools for the MCP server.
8+
/// </summary>
79
[McpToolType]
810
public static class GeneralTools
911
{
12+
/// <summary>
13+
/// Simple health check endpoint that returns a greeting message.
14+
/// </summary>
15+
/// <returns>A greeting message indicating the server is operational.</returns>
1016
[McpTool("hello")]
1117
[Description("Simple health check endpoint that returns a greeting message.")]
1218
public static string Hello() => "hello, claude.";
13-
}
19+
}

src/NetContextServer/Tools/IgnorePatternTools.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
1-
using ModelContextProtocol;
21
using ModelContextProtocol.Server;
32
using NetContextServer.Services;
43
using System.ComponentModel;
54

65
namespace NetContextServer.Tools;
76

7+
/// <summary>
8+
/// Provides MCP tools for managing file ignore patterns used during file operations.
9+
/// </summary>
810
[McpToolType]
911
public static class IgnorePatternTools
1012
{
13+
/// <summary>
14+
/// Adds new patterns to the ignore list for file scanning operations.
15+
/// </summary>
16+
/// <param name="patterns">Array of glob patterns to ignore (e.g. ['*.generated.cs', 'bin/*']).</param>
17+
/// <returns>A JSON string containing the results of the operation, including any invalid patterns.</returns>
1118
[McpTool("add_ignore_patterns")]
1219
[Description("Adds new patterns to the ignore list for file scanning operations.")]
1320
public static string AddIgnorePatterns(
1421
[Description("Array of glob patterns to ignore (e.g. ['*.generated.cs', 'bin/*'])")]
1522
string[] patterns) =>
1623
IgnorePatternService.AddIgnorePatterns(patterns);
1724

25+
/// <summary>
26+
/// Removes all user-defined ignore patterns from both memory and the persistent state file.
27+
/// </summary>
28+
/// <returns>A JSON string containing the updated pattern lists after clearing.</returns>
1829
[McpTool("clear_ignore_patterns")]
1930
[Description("Removes all user-defined ignore patterns from both memory and the persistent state file.")]
2031
public static string ClearIgnorePatterns() =>
2132
IgnorePatternService.ClearIgnorePatterns();
2233

34+
/// <summary>
35+
/// Retrieves the current list of active ignore patterns from memory.
36+
/// </summary>
37+
/// <returns>A JSON string containing all active ignore patterns, including both default and user-defined patterns.</returns>
2338
[McpTool("get_ignore_patterns")]
2439
[Description("Retrieves the current list of active ignore patterns from memory.")]
2540
public static string GetIgnorePatterns() =>
2641
IgnorePatternService.GetIgnorePatterns();
2742

43+
/// <summary>
44+
/// Returns the absolute path to the ignore_patterns.json state file.
45+
/// </summary>
46+
/// <returns>A JSON string containing the path to the state file.</returns>
2847
[McpTool("get_state_file_location")]
2948
[Description("Returns the absolute path to the ignore_patterns.json state file.")]
3049
public static string GetStateFileLocation() =>
3150
IgnorePatternService.GetStateFileLocation();
3251

52+
/// <summary>
53+
/// Removes specific patterns from the ignore list.
54+
/// </summary>
55+
/// <param name="patterns">Array of glob patterns to remove from the ignore list.</param>
56+
/// <returns>A JSON string containing the results of the operation and updated pattern lists.</returns>
3357
[McpTool("remove_ignore_patterns")]
3458
[Description("Removes specific patterns from the ignore list.")]
3559
public static string RemoveIgnorePatterns(

src/NetContextServer/Tools/PackageTools.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ModelContextProtocol;
21
using ModelContextProtocol.Server;
32
using NetContextServer.Models;
43
using NetContextServer.Services;
@@ -7,14 +6,33 @@
76

87
namespace NetContextServer.Tools;
98

9+
/// <summary>
10+
/// Provides MCP tools for analyzing NuGet packages in .NET projects.
11+
/// </summary>
1012
[McpToolType]
1113
public static class PackageTools
1214
{
15+
/// <summary>
16+
/// Default JSON serializer options used for package analysis output.
17+
/// </summary>
1318
private static readonly JsonSerializerOptions DefaultJsonOptions = new()
1419
{
1520
WriteIndented = true
1621
};
1722

23+
/// <summary>
24+
/// Analyzes NuGet packages in all projects found in the base directory.
25+
/// </summary>
26+
/// <returns>
27+
/// A JSON string containing analysis results for each project, including:
28+
/// - Package versions and available updates
29+
/// - Usage analysis
30+
/// - Recommendations for updates or removal
31+
/// </returns>
32+
/// <remarks>
33+
/// This operation requires the base directory to be set and contain valid .NET projects.
34+
/// The analysis includes checking for updates, detecting package usage, and providing recommendations.
35+
/// </remarks>
1836
[McpTool("analyze_packages")]
1937
[Description("Analyzes NuGet packages in all projects found in the base directory.")]
2038
public static async Task<string> AnalyzePackagesAsync()
@@ -60,4 +78,4 @@ public static async Task<string> AnalyzePackagesAsync()
6078
return JsonSerializer.Serialize(new { Error = ex.Message }, DefaultJsonOptions);
6179
}
6280
}
63-
}
81+
}

src/NetContextServer/Tools/SearchTools.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
using ModelContextProtocol;
21
using ModelContextProtocol.Server;
32
using NetContextServer.Services;
43
using System.ComponentModel;
54
using System.Text.Json;
65

76
namespace NetContextServer.Tools;
87

8+
/// <summary>
9+
/// Provides MCP tools for searching code within the codebase using both text-based and semantic search capabilities.
10+
/// </summary>
911
[McpToolType]
1012
public static class SearchTools
1113
{
14+
/// <summary>
15+
/// Default JSON serializer options used for search results output.
16+
/// </summary>
1217
private static readonly JsonSerializerOptions DefaultJsonOptions = new()
1318
{
1419
WriteIndented = true
1520
};
1621

22+
/// <summary>
23+
/// Performs a text-based search across all code files for the specified text.
24+
/// </summary>
25+
/// <param name="searchText">The exact text string to search for in the codebase.</param>
26+
/// <returns>A JSON string containing an array of matches with file paths and line numbers.</returns>
1727
[McpTool("search_code")]
1828
[Description("Performs a text-based search across all code files for the specified text.")]
1929
public static string SearchCode(
2030
[Description("The exact text string to search for in the codebase")]
2131
string searchText) =>
2232
JsonSerializer.Serialize(CodeSearchService.SearchCode(searchText), DefaultJsonOptions);
2333

34+
/// <summary>
35+
/// Performs a semantic similarity search across the codebase using AI.
36+
/// </summary>
37+
/// <param name="query">Natural language description of the code you're looking for.</param>
38+
/// <param name="topK">Optional: Number of results to return (default: 5).</param>
39+
/// <returns>A JSON string containing semantically relevant code snippets ranked by relevance.</returns>
40+
/// <remarks>
41+
/// This method uses AI embeddings to understand the semantic meaning of the query and find relevant code,
42+
/// even if it doesn't contain the exact words used in the query.
43+
/// </remarks>
2444
[McpTool("semantic_search")]
2545
[Description("Performs a semantic similarity search across the codebase using AI.")]
2646
public static async Task<string> SemanticSearchAsync(
@@ -39,4 +59,4 @@ public static async Task<string> SemanticSearchAsync(
3959
return JsonSerializer.Serialize(new { Error = ex.Message }, DefaultJsonOptions);
4060
}
4161
}
42-
}
62+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Xunit;
2-
31
namespace NetContextServer.Tests;
42

53
[CollectionDefinition("NetContextServer Tests", DisableParallelization = true)]
@@ -8,4 +6,4 @@ public class NetContextServerTestCollection : ICollectionFixture<NetContextServe
86
// This class has no code, and is never created. Its purpose is simply
97
// to be the place to apply [CollectionDefinition] and all the
108
// ICollectionFixture<> interfaces.
11-
}
9+
}

0 commit comments

Comments
 (0)