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
chat: use structured outputs for SearchBookContent MCP tool
- Convert SearchBookContent from Task<string> to Task<CallToolResult> with
UseStructuredContent = true and OutputSchemaType = typeof(SearchBookContentResult),
matching the pattern established by FindBookHelpForDiagnostic and SearchListingsByCode
- Add SearchBookContentMatchResult and SearchBookContentResult records to McpToolResults.cs
- Fix no-results path to return CreateHybridResult with empty Matches list instead of
CreateError — zero search results is a valid outcome, not a tool failure
- Add explicit OutputSchemaType to GetChapterList, GetChapterSections, GetDirectContentUrl,
GetNavigationContext, and GetChapterSummary for documentation clarity (MCP SDK already
infers the output schema from the concrete return type, but explicit annotation makes
the intended schema contract visible at the declaration site)
- Add search_book_content to McpToolContractTests outputSchema presence assertions
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.")]
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.")]
147
147
publicChapterSummaryToolResultGetChapterSummary(
148
148
[Description("The chapter number (e.g., 5 for Chapter 5).")]intchapter)=>
Copy file name to clipboardExpand all lines: EssentialCSharp.Web/Tools/BookSearchTool.cs
+32-17Lines changed: 32 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -29,57 +29,72 @@ public BookSearchTool(
29
29
_bookToolQueryService=bookToolQueryService;
30
30
}
31
31
32
-
[McpServerTool(Title="Search Book Content",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false),
32
+
[McpServerTool(Title="Search Book Content",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false,UseStructuredContent=true,OutputSchemaType=typeof(SearchBookContentResult)),
33
33
Description("Search the Essential C# book content using semantic vector search. Returns relevant text chunks with chapter and heading context. Use this to find information about C# programming concepts covered in the book.")]
34
-
publicasyncTask<string>SearchBookContent(
34
+
publicasyncTask<CallToolResult>SearchBookContent(
35
35
[Description("The search query describing the C# concept or topic to find in the book.")]stringquery,
36
36
[Description("Number of results to return (1–10). Use a higher value for broad topics or comprehensive research; lower for quick lookups.")]intmaxResults=AISearchService.DefaultSearchTop,
37
37
CancellationTokencancellationToken=default)
38
38
{
39
39
if(string.IsNullOrWhiteSpace(query))
40
40
{
41
-
return"Query must not be empty.";
41
+
returnMcpToolResultFactory.CreateError("Query must not be empty.");
42
42
}
43
43
if(query.Length>500)
44
44
{
45
-
return"Query is too long (maximum 500 characters).";
45
+
returnMcpToolResultFactory.CreateError("Query is too long (maximum 500 characters).");
46
46
}
47
47
48
48
if(_SearchServiceisnull)
49
49
{
50
-
return"Book search is not available in this environment (AI services are not configured).";
50
+
returnMcpToolResultFactory.CreateError("Book search is not available in this environment (AI services are not configured).");
Description("Get all sections and subsections in a specific chapter of the Essential C# book, in reading order. Returns each section's heading, slug, anchor link, and indent level. Use the returned slugs with other tools like GetSectionContent or GetNavigationContext.")]
[McpServerTool(Title="Get Direct Content URL",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false,UseStructuredContent=true),
97
+
[McpServerTool(Title="Get Direct Content URL",ReadOnly=true,Destructive=false,Idempotent=true,OpenWorld=false,UseStructuredContent=true,OutputSchemaType=typeof(BookSectionReferenceResult)),
83
98
Description("Get the canonical deep-link URL and section metadata for a specific book section or subsection. Use this to include precise references in responses.")]
0 commit comments