You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description("Retrieve the prose content of a specific book section identified by its slug/key (e.g., 'hello-world', 'creating-editing-compiling-and-running-c-source-code'). Returns the section text with code examples preserved. Use GetChapterSections to discover available slugs.")]
37
-
publicstringGetSectionContent(
38
+
publicasyncTask<string>GetSectionContent(
38
39
[Description("The section slug/key (e.g., 'hello-world'). Use GetChapterSections to get valid slugs.")]stringsectionKey,
39
-
[Description("Maximum number of characters to return (500–8000, default 4000). Long sections are truncated.")]intmaxChars=4000)
40
+
[Description("Maximum number of characters to return (500–8000, default 4000). Long sections are truncated.")]intmaxChars=4000,
41
+
CancellationTokencancellationToken=default)
40
42
{
41
43
maxChars=Math.Clamp(maxChars,500,8000);
42
44
45
+
if(string.IsNullOrWhiteSpace(sectionKey))
46
+
{
47
+
return"Section key must not be empty. Use GetChapterSections to discover valid section slugs.";
@@ -91,19 +133,19 @@ public string GetSectionContent(
91
133
break;
92
134
}
93
135
94
-
ExtractNodeContent(child,sb);
136
+
ExtractNodeContent(child,body);
95
137
96
-
if(sb.Length>=maxChars)
138
+
if(body.Length>=maxChars)
97
139
{
98
-
sb.Append("\n\n[Content truncated — use a larger maxChars value to see more.]");
140
+
body.Append("\n\n[Content truncated — use a larger maxChars value to see more.]");
99
141
break;
100
142
}
101
143
}
102
144
103
-
returnsb.Length==0?$"No content found after section heading '{mapping.RawHeading}'.":sb.ToString();
145
+
returnbody.Length==0?$"No content found after section heading '{mapping.RawHeading}'.":header.Append(body).ToString();
104
146
}
105
147
106
-
[McpServerTool(Title="Get Listing With Context",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false),
148
+
[McpServerTool(Title="Get Listing With Context",ReadOnly=true,Idempotent=true,OpenWorld=false),
107
149
Description("Retrieve a specific book listing's source code together with the semantic book content that explains it. Combines code from GetListingSourceCode with related explanatory text found via search. Ideal for understanding what a listing demonstrates.")]
108
150
publicasyncTask<string>GetListingWithContext(
109
151
[Description("The chapter number of the listing.")]intchapter,
@@ -116,7 +158,7 @@ public async Task<string> GetListingWithContext(
116
158
return$"Listing {chapter}.{listing} not found. Verify the chapter and listing numbers.";
Description("Get the navigation context for a book section: its breadcrumb path, the previous and next sections, its parent section, and its sibling sections. Useful for understanding where a section sits in the book's structure.")]
154
196
publicstringGetNavigationContext(
155
197
[Description("The section slug/key (e.g., 'hello-world'). Use GetChapterSections to get valid slugs.")]stringsectionKey)
156
198
{
199
+
if(string.IsNullOrWhiteSpace(sectionKey))
200
+
{
201
+
return"Section key must not be empty. Use GetChapterSections to discover valid section slugs.";
Description("Get a structural overview of a book chapter: its top-level section headings in reading order, and the coding guidelines associated with that chapter. Useful for understanding what a chapter covers before diving in.")]
283
330
publicstringGetChapterSummary(
284
331
[Description("The chapter number (e.g., 5 for Chapter 5).")]intchapter)
@@ -304,7 +351,7 @@ public string GetChapterSummary(
Description("Retrieve C# coding guidelines from the Essential C# book. Optionally filter by keyword, chapter number, or guideline type (do/consider/avoid/donot). The book contains guidelines covering naming conventions, error handling, LINQ, async/await, generics, and many other topics. Each guideline includes its chapter and subsection context.")]
21
21
publicstringGetCSharpGuidelines(
22
22
[Description("Optional keyword to filter guidelines by (searched in guideline text and subsection name).")]string?keyword=null,
@@ -27,6 +27,11 @@ public string GetCSharpGuidelines(
@@ -62,7 +67,7 @@ public string GetCSharpGuidelines(
62
67
returnsb.ToString();
63
68
}
64
69
65
-
[McpServerTool(Title="Get Guidelines By Topic",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false),
70
+
[McpServerTool(Title="Get Guidelines By Topic",ReadOnly=true,Idempotent=true,OpenWorld=false),
66
71
Description("Search C# coding guidelines from the Essential C# book by topic or concept. More discoverable than filtering by chapter — finds all guidelines related to exceptions, naming, async, LINQ, generics, interfaces, and more. Results are ordered by relevance to the topic.")]
67
72
publicstringGetGuidelinesByTopic(
68
73
[Description("The topic or concept to search guidelines for (e.g., 'exception handling', 'naming', 'async', 'LINQ', 'generics', 'interface').")]stringtopic,
@@ -112,7 +117,7 @@ public string GetGuidelinesByTopic(
Description("Retrieve the complete source code for a specific numbered listing from the Essential C# book. Example: chapter=5, listing=3 retrieves Listing 5.3. Returns the code and its file type.")]
23
23
publicasyncTask<string>GetListingSourceCode(
24
24
[Description("The chapter number containing the listing (e.g., 5 for Chapter 5).")]intchapter,
@@ -31,11 +31,11 @@ public async Task<string> GetListingSourceCode(
31
31
return$"Listing {chapter}.{listing} not found. Verify that both the chapter and listing numbers are correct.";
[McpServerTool(Title="Search Listings By Code",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false),
38
+
[McpServerTool(Title="Search Listings By Code",ReadOnly=true,Idempotent=true,OpenWorld=false),
39
39
Description("Search all code listings in the Essential C# book for a specific code pattern, keyword, or identifier. Searches actual C# source code (not prose). Useful for finding examples of Task.WhenAll, yield return, IDisposable, pattern matching, and similar code constructs.")]
40
40
publicasyncTask<string>SearchListingsByCode(
41
41
[Description("The code pattern or keyword to search for in listing source code (case-insensitive substring match).")]stringpattern,
@@ -68,7 +68,7 @@ public async Task<string> SearchListingsByCode(
0 commit comments