Skip to content

feat(mcptest): extend test server with prompt and resource support #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025

Conversation

vasayxtx
Copy link
Contributor

@vasayxtx vasayxtx commented May 28, 2025

Description

This PR enhances the mcptest.Server by adding comprehensive support for prompts and resources alongside the existing tools functionality.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • MCP spec compatibility implementation
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Tests only (no functional changes)
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly

Summary by CodeRabbit

  • New Features

    • Added support for registering prompts and resources on the server, enabling interaction with custom prompts and access to resources.
  • Bug Fixes

    • Enhanced initialization logic for server capabilities related to resources and prompts to ensure thread-safe setup.
  • Tests

    • Added tests validating server behavior with prompts and resources, confirming accurate handling and responses.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

"""

Walkthrough

The changes introduce support for registering prompts and resources in both the MCP server and its test server. New methods and struct types are added to manage prompts and resources, including batch registration. Tests are updated and expanded to verify the new prompt and resource handling capabilities in the test server.

Changes

Files / Areas Change Summary
mcptest/mcptest.go Added prompt/resource slices to Server struct; added methods for adding prompts/resources; integrated into server startup.
mcptest/mcptest_test.go Renamed existing test; added new tests for prompt and resource registration and retrieval.
server/server.go Introduced ServerPrompt/ServerResource structs; added batch and single add methods; centralized capability registration with lazy init.

Possibly related PRs

Suggested reviewers

  • ezynda3
  • robert-jackson-glean
    """

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de0304a and d36a6f5.

📒 Files selected for processing (3)
  • mcptest/mcptest.go (3 hunks)
  • mcptest/mcptest_test.go (2 hunks)
  • server/server.go (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • mcptest/mcptest_test.go
  • mcptest/mcptest.go
  • server/server.go
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
mcptest/mcptest_test.go (1)

133-136: Add type assertion safety check.

The type assertion getResult.Messages[0].Content.(mcp.TextContent) could panic if the content is not of the expected type.

-	content := getResult.Messages[0].Content.(mcp.TextContent)
-	if content.Text != "Hello, John!" {
-		t.Errorf("Expected message content 'Hello, John!', got %q", content.Text)
-	}
+	content, ok := getResult.Messages[0].Content.(mcp.TextContent)
+	if !ok {
+		t.Fatalf("Expected TextContent, got %T", getResult.Messages[0].Content)
+	}
+	if content.Text != "Hello, John!" {
+		t.Errorf("Expected message content 'Hello, John!', got %q", content.Text)
+	}
server/server.go (1)

384-411: Consider extracting capability initialization helper.

The capability initialization logic for prompts (lines 386-397) duplicates the pattern used in implicitlyRegisterResourceCapabilities(). Consider extracting this into a similar helper method for consistency.

+func (s *MCPServer) implicitlyRegisterPromptCapabilities() {
+	s.capabilitiesMu.RLock()
+	if s.capabilities.prompts == nil {
+		s.capabilitiesMu.RUnlock()
+
+		s.capabilitiesMu.Lock()
+		if s.capabilities.prompts == nil {
+			s.capabilities.prompts = &promptCapabilities{}
+		}
+		s.capabilitiesMu.Unlock()
+	} else {
+		s.capabilitiesMu.RUnlock()
+	}
+}

 // AddPrompts registers multiple prompts at once
 func (s *MCPServer) AddPrompts(prompts ...ServerPrompt) {
-	s.capabilitiesMu.RLock()
-	if s.capabilities.prompts == nil {
-		s.capabilitiesMu.RUnlock()
-
-		s.capabilitiesMu.Lock()
-		if s.capabilities.prompts == nil {
-			s.capabilities.prompts = &promptCapabilities{}
-		}
-		s.capabilitiesMu.Unlock()
-	} else {
-		s.capabilitiesMu.RUnlock()
-	}
+	s.implicitlyRegisterPromptCapabilities()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7c0e13 and 93daddb.

📒 Files selected for processing (3)
  • mcptest/mcptest.go (3 hunks)
  • mcptest/mcptest_test.go (2 hunks)
  • server/server.go (8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
mcptest/mcptest_test.go (4)
mcptest/mcptest.go (1)
  • NewUnstartedServer (57-74)
mcp/prompts.go (7)
  • Prompt (43-51)
  • PromptArgument (61-69)
  • GetPromptRequest (20-28)
  • GetPromptResult (32-37)
  • PromptMessage (84-87)
  • Role (73-73)
  • RoleUser (76-76)
mcp/types.go (5)
  • Content (804-806)
  • Params (160-160)
  • Resource (619-634)
  • ReadResourceRequest (558-567)
  • ResourceContents (669-671)
mcp/utils.go (1)
  • NewTextContent (199-204)
mcptest/mcptest.go (3)
server/server.go (5)
  • ServerTool (50-53)
  • ServerPrompt (56-59)
  • ServerResource (62-65)
  • PromptHandlerFunc (38-38)
  • ResourceHandlerFunc (32-32)
mcp/prompts.go (1)
  • Prompt (43-51)
mcp/types.go (1)
  • Resource (619-634)
server/server.go (3)
mcp/prompts.go (1)
  • Prompt (43-51)
mcp/types.go (1)
  • Resource (619-634)
examples/custom_context/main.go (1)
  • MCPServer (100-102)
🔇 Additional comments (10)
mcptest/mcptest_test.go (3)

14-14: Good rename for clarity.

Renaming TestServer to TestServerWithTool improves clarity and follows the pattern of the new test functions.


81-137: Well-structured prompt test.

The test comprehensively validates prompt functionality including registration, handler execution, and response verification. The test structure follows good practices with proper setup, execution, and teardown.


139-186: Comprehensive resource test.

The test thoroughly validates resource functionality including registration, handler execution, and content verification. Good use of type assertions with proper error handling.

mcptest/mcptest.go (3)

24-25: Good structural extension.

Adding prompts and resources slices to the Server struct follows the established pattern and maintains consistency with the existing tools slice.


89-113: Well-implemented batch and single methods.

The prompt and resource methods follow the same excellent pattern as the existing tool methods:

  • Batch methods (AddPrompts, AddResources) for multiple additions
  • Single methods (AddPrompt, AddResource) as convenient wrappers
  • Consistent parameter patterns and struct creation

127-128: Proper integration in startup sequence.

The addition of AddPrompts and AddResources calls in the Start method correctly integrates the new functionality into the server startup process, maintaining consistency with the existing AddTools call.

server/server.go (4)

55-65: Excellent structural consistency.

The new ServerPrompt and ServerResource structs follow the same pattern as ServerTool, maintaining consistency across the codebase and providing a clean way to pair resources/prompts with their handlers.


320-346: Well-refactored resource registration.

The refactoring to support batch operations while maintaining single-item convenience methods is well-executed. The use of implicitlyRegisterResourceCapabilities() and proper mutex handling ensures thread safety.


413-416: Clean single-item wrapper method.

The refactored AddPrompt method correctly delegates to the batch method, maintaining the convenience API while leveraging the batch implementation.


463-476: Excellent capability initialization helper.

The implicitlyRegisterResourceCapabilities() method provides a clean, thread-safe way to handle lazy capability initialization using the double-checked locking pattern. This improves code reusability and consistency.

@vasayxtx vasayxtx force-pushed the extend-mcptest-server branch from 93daddb to de0304a Compare May 28, 2025 11:14
Copy link
Collaborator

@pottekkat pottekkat left a comment

Choose a reason for hiding this comment

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

@vasayxtx Thank you for the PR. Can you check the comments left by coderabbit about deduplication using the implicitlyRegisterResourceCapabilities function and about the type assertion? They are valid concerns. Since you have already made the implicitlyRegisterResourceCapabilities function, using it everywhere where it is appropriate would be helpful. Otherwise, this PR is good to go.

Add support for prompts and resources to the mcptest server, including:
- New methods to add prompts and resources to test servers
- Batch methods for adding multiple prompts/resources at once
- Test cases demonstrating prompt and resource functionality
- Helper methods for resource capabilities registration
@vasayxtx vasayxtx force-pushed the extend-mcptest-server branch from de0304a to d36a6f5 Compare May 29, 2025 20:49
@vasayxtx
Copy link
Contributor Author

@pottekkat coderabbit's comments are processed. Could you pls check the PR again? Thanks!

@ezynda3 ezynda3 merged commit ca9be6e into mark3labs:main Jun 1, 2025
4 checks passed
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.

3 participants