Skip to content

Feat/enhance mcp#86

Merged
foxminchan merged 1 commit into
mainfrom
feat/enhance-mcp
Jul 24, 2025
Merged

Feat/enhance mcp#86
foxminchan merged 1 commit into
mainfrom
feat/enhance-mcp

Conversation

@foxminchan

@foxminchan foxminchan commented Jul 23, 2025

Copy link
Copy Markdown
Owner

Pull Request Description

Checklist

  • My code follows the DDD principles
  • I've used the latest C# features and idioms
  • I've added/updated unit tests for business logic
  • Service boundaries are maintained (no cross-service direct dependencies)
  • Repository pattern is used for data access
  • Domain Events are used for cross-service communication
  • I've registered new services in AppHost project (if applicable)
  • I've updated both entities and DTOs (if applicable)

Summary by CodeRabbit

  • New Features

    • Added dynamic OpenAPI documentation for MCP endpoints, including a new POST operation at /mcp with detailed schema and response descriptions.
    • OpenAPI support is now enabled for the MCP project alongside other APIs.
    • MCP Tools server now displays a descriptive title and purpose in its configuration.
  • Improvements

    • MCP server version is now set dynamically based on API version descriptions.
    • OpenAPI document generation enhanced with custom transformers and versioning.
    • Endpoint routing for MCP endpoints updated for improved clarity and consistency.
    • User-facing tool and prompt titles are now more descriptive in the MCP Tools interface.
  • Bug Fixes

    • Corrected the SSE client endpoint to use the /mcp path.
  • Chores

    • Added "jsonrpc" to the user dictionary for improved spell checking.
    • Updated global using directives for better code maintainability.

@coderabbitai

coderabbitai Bot commented Jul 23, 2025

Copy link
Copy Markdown

Walkthrough

This update introduces OpenAPI support for the MCP project, adds a custom OpenAPI document transformer, and refines MCP endpoint routing and configuration. It adjusts versioning and metadata handling, updates attributes for clarity, and expands global usings for OpenAPI-related functionality. Minor dictionary and configuration enhancements are also included.

Changes

File(s) Change Summary
BookWorm.sln.DotSettings Added "jsonrpc" to the user dictionary.
src/Aspire/BookWorm.AppHost/AppHost.cs Registered MCP project with OpenAPI in run mode.
src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs Changed OpenApiOptionsExtensions class from internal to public.
src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs Used API version for server info; added AddMcpOpenApi method for OpenAPI document registration and transformation.
src/Integrations/BookWorm.McpTools/GlobalUsings.cs Added global usings for OpenAPI and extension namespaces.
src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs Introduced McpDocumentTransformer to customize OpenAPI docs, add /mcp POST operation, and set server URL dynamically.
src/Integrations/BookWorm.McpTools/Program.cs Changed MCP route to "/mcp", added OpenAPI middleware, and removed an unused using directive.
src/Integrations/BookWorm.McpTools/Prompts/Instruction.cs Added Title property to McpServerPrompt attribute.
src/Integrations/BookWorm.McpTools/Tools/Product.cs Added Title property to McpServerTool attribute.
src/Integrations/BookWorm.McpTools/appsettings.Development.json Added "Document" section with "Description" and "Title".
src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs Updated client version string and changed SSE endpoint to use /mcp path.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MCP API
    participant OpenAPI Middleware
    participant McpDocumentTransformer

    Client->>MCP API: POST /mcp (with JSON-RPC payload)
    MCP API->>OpenAPI Middleware: Generate OpenAPI docs
    OpenAPI Middleware->>McpDocumentTransformer: Transform OpenAPI document
    McpDocumentTransformer-->>OpenAPI Middleware: Add /mcp POST operation, set server URL
    OpenAPI Middleware-->>Client: Serve OpenAPI spec with custom /mcp operation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

  • Fix/outbox problem #75: Also modifies the user dictionary in the DotSettings file by adding a new word, similar to the addition of "jsonrpc" here.

Poem

In BookWorm’s code, the APIs bloom,
OpenAPI lights up every room.
MCP now struts with a custom path,
And transformers shape docs with gentle math.
Versioning’s neat, attributes shine—
This update’s a treat for the code review line!
📚✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdf424f and 1a4a0c3.

📒 Files selected for processing (11)
  • BookWorm.sln.DotSettings (1 hunks)
  • src/Aspire/BookWorm.AppHost/AppHost.cs (1 hunks)
  • src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs (3 hunks)
  • src/Integrations/BookWorm.McpTools/GlobalUsings.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Program.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Prompts/Instruction.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Tools/Product.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/appsettings.Development.json (1 hunks)
  • src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Integrations/BookWorm.McpTools/Prompts/Instruction.cs
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/Integrations/BookWorm.McpTools/appsettings.Development.json
  • src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs
  • BookWorm.sln.DotSettings
  • src/Integrations/BookWorm.McpTools/Program.cs
  • src/Integrations/BookWorm.McpTools/Tools/Product.cs
  • src/Aspire/BookWorm.AppHost/AppHost.cs
  • src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs
  • src/Integrations/BookWorm.McpTools/GlobalUsings.cs
  • src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs
  • src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyzers
  • GitHub Check: Style
  • GitHub Check: Security Scan
  • GitHub Check: Build and analyze
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/enhance-mcp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify

netlify Bot commented Jul 23, 2025

Copy link
Copy Markdown

Deploy Preview for bookwormdev canceled.

Name Link
🔨 Latest commit 1a4a0c3
🔍 Latest deploy log https://app.netlify.com/projects/bookwormdev/deploys/6881db0a709d14000842b961

@github-actions

github-actions Bot commented Jul 23, 2025

Copy link
Copy Markdown

Test Results

1 033 tests  ±0   1 033 ✅ ±0   8m 31s ⏱️ + 1m 0s
    8 suites ±0       0 💤 ±0 
    8 files   ±0       0 ❌ ±0 

Results for commit 1a4a0c3. ± Comparison against base commit 5cf0ac8.

♻️ This comment has been updated with latest results.

@foxminchan
foxminchan force-pushed the feat/enhance-mcp branch 2 times, most recently from 3ab48e4 to bdf424f Compare July 24, 2025 06:53
@foxminchan
foxminchan marked this pull request as ready for review July 24, 2025 06:53
Copilot AI review requested due to automatic review settings July 24, 2025 06:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the MCP (Model Context Protocol) integration by improving configuration, documentation, and API specification. The changes focus on better version handling, endpoint configuration, and OpenAPI documentation for the MCP tools server.

Key changes include:

  • Updated MCP client endpoint configuration and version handling
  • Added OpenAPI documentation and transformation for MCP endpoints
  • Enhanced tool and prompt definitions with titles and descriptions

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Extensions.cs (Chat) Updates MCP client version and endpoint configuration
appsettings.Development.json Adds document metadata for MCP tools server
Product.cs Adds title to SearchCatalog tool definition
Instruction.cs Adds title to SystemPrompt definition
Program.cs Updates MCP endpoint mapping and adds OpenAPI support
McpDocumentTransformer.cs New OpenAPI document transformer for MCP protocol
GlobalUsings.cs Adds necessary using statements for OpenAPI functionality
Extensions.cs (McpTools) Implements OpenAPI configuration for MCP server
OpenApiOptionsExtensions.cs Changes visibility from internal to public
AppHost.cs Adds MCP service to OpenAPI configuration
BookWorm.sln.DotSettings Adds "jsonrpc" to dictionary

Comment thread src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs (2)

29-91: Consider extracting schema definitions for maintainability.

The OpenAPI operation definition is comprehensive, but the inline schema creation makes it verbose. Consider extracting schema definitions to improve maintainability and reusability.

Create a separate schema factory:

public static class McpSchemaFactory
{
    public static OpenApiSchema CreateMcpRequestSchema() => new()
    {
        Type = "object",
        Properties = new Dictionary<string, OpenApiSchema>
        {
            [McpConstants.Method] = new() { Type = "string" },
            [McpConstants.Params] = CreateParamsSchema(),
            [McpConstants.JsonRpc] = CreateJsonRpcSchema(),
            [McpConstants.Id] = new() { Type = "integer" }
        },
        Required = new HashSet<string> { McpConstants.Method, McpConstants.Params, McpConstants.JsonRpc, McpConstants.Id }
    };
    
    // Additional helper methods...
}

This approach aligns with DDD principles by creating a dedicated schema domain.


10-98: Consider implementing enterprise patterns for better maintainability.

While the implementation follows Clean Architecture principles, consider these enterprise-level improvements:

  1. Domain-Driven Design: Extract MCP schema definitions into a dedicated domain service
  2. Configuration Pattern: Use IOptions for configuration management instead of hardcoded values
  3. Observability: Add structured logging for transformation operations
  4. Error Handling: Implement comprehensive error handling with custom exceptions

Example domain service extraction:

public interface IMcpSchemaService
{
    OpenApiSchema CreateRequestSchema();
    OpenApiOperation CreateInvokeOperation();
}

public sealed class McpDocumentTransformer(
    IHttpContextAccessor accessor,
    IMcpSchemaService schemaService,
    ILogger<McpDocumentTransformer> logger) : IOpenApiDocumentTransformer
{
    // Implementation using injected services
}

This aligns with SOLID principles and improves testability and maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cf0ac8 and bdf424f.

📒 Files selected for processing (11)
  • BookWorm.sln.DotSettings (1 hunks)
  • src/Aspire/BookWorm.AppHost/AppHost.cs (1 hunks)
  • src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs (3 hunks)
  • src/Integrations/BookWorm.McpTools/GlobalUsings.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Program.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Prompts/Instruction.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/Tools/Product.cs (1 hunks)
  • src/Integrations/BookWorm.McpTools/appsettings.Development.json (1 hunks)
  • src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/Aspire/**

⚙️ CodeRabbit Configuration File

src/Aspire/**: .NET Aspire orchestration review:

  • Service discovery and configuration
  • Health checks and observability
  • Resource allocation and scaling
  • Development environment setup

Files:

  • src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs
  • src/Aspire/BookWorm.AppHost/AppHost.cs
src/Services/**/Infrastructure/**

⚙️ CodeRabbit Configuration File

src/Services/**/Infrastructure/**: Examine infrastructure implementations:

  • Repository pattern adherence
  • Database migrations and EF Core configurations
  • External service integrations
  • Caching strategies and performance

Files:

  • src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs
🧠 Learnings (1)
src/Integrations/BookWorm.McpTools/GlobalUsings.cs (3)

Learnt from: CR
PR: foxminchan/BookWorm#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-02T07:45:53.434Z
Learning: Applies to **/*.cs : Prefer file-scoped namespace declarations and single-line using directives.

Learnt from: CR
PR: foxminchan/BookWorm#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-23T18:48:45.052Z
Learning: Prefer file-scoped namespace declarations and single-line using directives in C# for cleaner and more concise code.

Learnt from: CR
PR: foxminchan/BookWorm#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-23T18:48:43.455Z
Learning: For C# code, prefer file-scoped namespace declarations and single-line using directives to improve readability and reduce nesting.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyzers
  • GitHub Check: Style
  • GitHub Check: Security Scan
  • GitHub Check: Build and analyze
🔇 Additional comments (13)
BookWorm.sln.DotSettings (1)

25-25: LGTM - Proper dictionary addition for MCP integration

The addition of "jsonrpc" to the user dictionary is appropriate given the MCP integration's use of JSON-RPC protocol. The format is consistent with existing entries.

src/Aspire/BookWorm.ServiceDefaults/ApiSpecification/OpenApi/OpenApiOptionsExtensions.cs (1)

8-8: LGTM - Appropriate visibility change for MCP integration

Making OpenApiOptionsExtensions public is a reasonable change to support the MCP integration's OpenAPI configuration needs. The class is well-designed with proper separation of concerns and follows .NET extension method patterns correctly.

src/Aspire/BookWorm.AppHost/AppHost.cs (1)

240-241: LGTM - Consistent OpenAPI integration pattern

The addition of .WithOpenAPI(mcp) follows the established pattern for other API projects and properly integrates the MCP service into the application's OpenAPI infrastructure. The conditional execution within IsRunMode is appropriate for development scenarios.

src/Integrations/BookWorm.McpTools/Tools/Product.cs (1)

11-11: LGTM - Enhanced MCP tool metadata

The addition of the Title parameter improves API documentation and tooling discoverability. The title "Search BookWorm Catalog" is descriptive and accurately reflects the method's functionality.

src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs (1)

35-35: Verify MCP version format consistency

  • The only Version reference found is in Extensions.cs (ClientInfo.Version = "1.0"); no other MCP-related CS files use the previous “1.0.0” format.
  • Please confirm that switching from full SemVer to the simplified “1.0” aligns with your API versioning strategy and that all MCP components (NuGet metadata, docs, other services) follow the same convention.
  • If full semantic versioning is still required, consider reverting to “1.0.0” throughout.
src/Integrations/BookWorm.McpTools/Prompts/Instruction.cs (1)

9-9: Excellent enhancement for OpenAPI documentation.

Adding the Title property to the McpServerPrompt attribute improves the generated OpenAPI documentation by providing clearer identification of the system prompt. This aligns well with the overall OpenAPI enhancement goals of this PR.

src/Integrations/BookWorm.McpTools/GlobalUsings.cs (1)

4-5: Good adherence to coding standards and supports new OpenAPI functionality.

The added global using directives follow the preferred single-line format from the coding guidelines and appropriately support the new OpenAPI and extension functionality introduced in this PR. The namespaces are logically grouped and necessary for the enhanced MCP integration.

Also applies to: 8-9

src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs (1)

44-62: OpenAPI configuration approach is architecturally sound.

The AddMcpOpenApi method demonstrates good separation of concerns and proper OpenAPI configuration patterns. The approach of iterating through API versions and applying consistent configuration is excellent for enterprise applications.

However, consider the BuildServiceProvider issue flagged above for a more robust implementation.

src/Integrations/BookWorm.McpTools/OpenApi/McpDocumentTransformer.cs (5)

1-8: LGTM! Clean namespace organization and appropriate using statements.

The using statements are well-organized and the namespace follows the expected pattern for the integration layer.


10-12: Excellent use of modern C# features and Clean Architecture principles.

The sealed class with primary constructor and dependency on IHttpContextAccessor abstraction demonstrates proper enterprise patterns and performance optimization.


13-17: Proper interface implementation with async pattern.

The method signature correctly implements IOpenApiDocumentTransformer and maintains the async pattern for future extensibility.


93-94: Proper defensive programming with null-coalescing initialization.

The null-coalescing assignment (??= []) and path addition are correctly implemented, following defensive programming practices.


96-97: Correct async pattern implementation.

Returning Task.CompletedTask is the appropriate pattern for synchronous implementations of async interfaces.

Comment thread src/Integrations/BookWorm.McpTools/appsettings.Development.json
Comment thread src/Integrations/BookWorm.McpTools/Extensions/Extensions.cs Outdated
Comment thread src/Integrations/BookWorm.McpTools/Program.cs Outdated
Comment thread src/Services/Chat/BookWorm.Chat/Infrastructure/ChatStreaming/Extensions.cs Outdated
@sonarqubecloud

Copy link
Copy Markdown

@foxminchan foxminchan self-assigned this Jul 24, 2025
@foxminchan
foxminchan merged commit 5174f64 into main Jul 24, 2025
17 checks passed
@foxminchan
foxminchan deleted the feat/enhance-mcp branch July 24, 2025 07:14
@coderabbitai coderabbitai Bot mentioned this pull request Aug 31, 2025
8 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Sep 27, 2025
8 tasks
This was referenced Oct 17, 2025
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.

2 participants