Skip to content

feat: Add MCP server#876

Draft
BenjaminMichaelis wants to merge 11 commits intomainfrom
bmichaelis/MCPServer
Draft

feat: Add MCP server#876
BenjaminMichaelis wants to merge 11 commits intomainfrom
bmichaelis/MCPServer

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

@BenjaminMichaelis BenjaminMichaelis commented Feb 25, 2026

Fixes #761

Comment thread EssentialCSharp.Web.Tests/McpTests.cs Fixed
Comment thread EssentialCSharp.Web.Tests/McpTests.cs Fixed
Comment thread EssentialCSharp.Chat.Shared/Services/AIChatService.cs Fixed
Comment thread EssentialCSharp.Web.Tests/McpTests.cs Fixed
Comment thread EssentialCSharp.Web/Controllers/McpTokenController.cs Fixed
Comment thread EssentialCSharp.Web/Controllers/McpTokenController.cs Fixed
Comment thread EssentialCSharp.Chat.Shared/Services/AIChatService.cs Fixed
@BenjaminMichaelis BenjaminMichaelis self-assigned this Apr 25, 2026
Comment thread EssentialCSharp.Web/Tools/BookSearchTool.cs Fixed
Comment thread EssentialCSharp.Web/Tools/BookGuidelinesTool.cs Fixed
Comment thread EssentialCSharp.Web/Tools/BookGuidelinesTool.cs Fixed
Comment thread EssentialCSharp.Web/Tools/BookGuidelinesTool.cs Fixed
Comment thread EssentialCSharp.Web/Tools/BookGuidelinesTool.cs Fixed
Comment thread EssentialCSharp.Web/Tools/BookContentTool.cs Fixed
BenjaminMichaelis added a commit that referenced this pull request Apr 25, 2026
- BookSearchTool: collapse else-if(!semanticAvailable)+else into single
  else with ternary to remove constant-condition CodeQL finding
- BookGuidelinesTool: use pattern match (is int / is GuidelineType) to
  extract nullable locals before lambda capture, removing nullable
  dereference warnings at lines 38 and 41

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@BenjaminMichaelis BenjaminMichaelis changed the title feat: Add MCP server with JWT authentication feat: Add MCP server Apr 25, 2026
BenjaminMichaelis added a commit that referenced this pull request Apr 26, 2026
…elect

- Remove GetBookMetadata() MCP tool and trim BookMetadata class to SiteUrl only
- Fix PR #876 feedback: refactor foreach+clone into codeLines.Select(line => line.CloneNode(deep:true))

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
BenjaminMichaelis and others added 10 commits April 25, 2026 21:46
- Add McpTokenService with JWT token generation/validation
- Add McpTokenController for token management UI
- Add MCP Access page to account management
- Configure MCP server with BookSearchTool
- Update ModelContextProtocol packages to 0.9.0-preview.2
- Add Microsoft.AspNetCore.Authentication.JwtBearer
- Fix MCP client API: use concrete McpClient type
- Add toolCallDepth guard to prevent infinite recursion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add IGuidelinesService + GuidelinesService (singleton) for guidelines.json
- Add BookListingTool: GetListingSourceCode, SearchListingsByCode
- Add BookGuidelinesTool: GetCSharpGuidelines, GetGuidelinesByTopic
- Add BookContentTool: GetSectionContent, GetListingWithContext,
  GetNavigationContext, GetChapterSummary
- Extend BookSearchTool: GetChapterSections, GetDirectContentUrl,
  GetBookMetadata, LookupConcept, CheckTopicCoverage,
  FindBookHelpForDiagnostic, FindRelatedSections
- Register all new tools in Program.cs MCP block

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove Destructive = false from all 17 MCP tool annotations (default per spec)
- Fix FindBookHelpForDiagnostic description to accurately reflect guidelines output
- Add 500-char max length validation to SearchBookContent, LookupConcept, CheckTopicCoverage, FindBookHelpForDiagnostic
- Add missing empty check to SearchBookContent
- Make GetSectionContent async (File.ReadAllTextAsync + doc.LoadHtml, removes TOCTOU File.Exists)
- Add path canonicalization via Path.GetRelativePath (robust cross-platform, handles drive-root edge case)
- Add .html file extension allowlist check on resolved path
- Add AnchorId validation via [GeneratedRegex] before XPath interpolation
- Separate IOException catches: FileNotFoundException/DirectoryNotFoundException show 'not generated yet', UnauthorizedAccessException and IOException show generic messages (no ex.Message leak)
- Make BookContentTool a partial class for GeneratedRegex support

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The MCP spec (and C# SDK) default destructiveHint to true.
Explicitly setting Destructive = false is required so clients
know these read-only book search tools are non-destructive.

Note: per spec, destructiveHint is 'only meaningful when
readOnlyHint == false', but the SDK still emits the value
on the wire so explicit false is the safe, correct choice.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- BookSearchTool: collapse else-if(!semanticAvailable)+else into single
  else with ternary to remove constant-condition CodeQL finding
- BookGuidelinesTool: use pattern match (is int / is GuidelineType) to
  extract nullable locals before lambda capture, removing nullable
  dereference warnings at lines 38 and 41

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…all sites

The helper class only had one method (NormalizeExtension) used in 3 places.
The VB.NET/F# cases were dead code — all 1,396 real book listings are .cs.
Simplified to a ternary inline at each call site; non-cs extensions pass through unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…elect

- Remove GetBookMetadata() MCP tool and trim BookMetadata class to SiteUrl only
- Fix PR #876 feedback: refactor foreach+clone into codeLines.Select(line => line.CloneNode(deep:true))

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…h tools

- AISearchService.ExecuteVectorSearch gains optional top param (default 5, clamped to 1-10)
- SearchBookContent, LookupConcept, FindRelatedSections expose maxResults to MCP clients
- Raises default from 3→5 for better coverage of broad C# concepts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create MCP server for EC# information and guidelines?

1 participant