-
Notifications
You must be signed in to change notification settings - Fork 471
Add tool capabilities to serverCapabilities #36
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
Conversation
Signed-off-by: edmondfrank <[email protected]>
WalkthroughThe changes introduce a new structure to manage tool-related capabilities. A Changes
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🔇 Additional comments (14)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Thanks for this! Can you please add a simple test for this? |
…esources Signed-off-by: edmondfrank <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/server_test.go (1)
57-58
: Add a test to verify integrated tool capabilities behavior.Consider enhancing the tests to verify that the
WithToolCapabilities(false)
option correctly disables tool capabilities in the server behavior, not just in the initialization response. This would provide more complete coverage of the new feature.{ name: "Specific capabilities", options: []ServerOption{ WithResourceCapabilities(true, false), WithPromptCapabilities(true), WithToolCapabilities(false), WithLogging(), }, validate: func(t *testing.T, response mcp.JSONRPCMessage) { + // Verify initialization response resp, ok := response.(mcp.JSONRPCResponse) assert.True(t, ok) initResult, ok := resp.Result.(mcp.InitializeResult) assert.True(t, ok) // ... existing assertions ... assert.NotNil(t, initResult.Capabilities.Tools) assert.False(t, initResult.Capabilities.Tools.ListChanged) assert.NotNil(t, initResult.Capabilities.Logging) + + // Also verify that the server will reject tool calls + toolCallMessage := `{ + "jsonrpc": "2.0", + "id": 2, + "method": "tools/call", + "params": { + "name": "test-tool" + } + }` + + server := response.(*mcp.JSONRPCResponse).Result.(*mcp.InitializeResult).server + toolResponse := server.HandleMessage(context.Background(), []byte(toolCallMessage)) + errorResp, ok := toolResponse.(mcp.JSONRPCError) + assert.True(t, ok) + assert.Equal(t, mcp.METHOD_NOT_FOUND, errorResp.Error.Code) }, },Also applies to: 94-96
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
server/server.go
(8 hunks)server/server_test.go
(7 hunks)
🔇 Additional comments (13)
server/server.go (7)
141-141
: Implementation of tool capabilities in serverCapabilities structure.The addition of the
tools
field to theserverCapabilities
structure properly integrates tool capabilities into the server's capability management system.
158-161
: Well-designed capability structure for tools.The
toolCapabilities
structure follows the established pattern used for other capabilities (resourceCapabilities, promptCapabilities) with thelistChanged
boolean field that indicates whether the list of tools can change during the server's lifetime.
182-189
: Consistent implementation of tool capabilities configuration function.The
WithToolCapabilities
function follows the same pattern as other capability configuration functions, making the API consistent and intuitive.
214-217
: Proper default initialization of capabilities.The default initialization of capabilities now includes tools with
listChanged
set to true by default, which maintains backward compatibility while enabling the new feature.
328-329
: Consistent capability checking for resources and prompts.The code now checks the
listChanged
boolean field instead of checking for nil pointers, which is more consistent with how capabilities are structured.Also applies to: 362-363
396-397
: Enhanced conditional check for tool capability.The condition now checks both
!s.capabilities.tools.listChanged
andlen(s.tools) == 0
before rejecting tool call requests, ensuring that tools are only available when both conditions are satisfied. This is more robust than the previous implementation.
545-546
: Proper integration with server capability reporting.The tool capabilities are correctly exposed in the initialize response, allowing clients to discover what tool capabilities are supported by the server.
server/server_test.go (6)
58-59
: Added test coverage for tool capabilities.The test now includes validation for the tool capabilities, ensuring that the new feature is properly tested.
91-124
: Comprehensive test case for specific capability combinations.This new test case ensures that various combinations of capabilities are correctly initialized and reported, which improves test coverage significantly.
644-645
: Enhanced test structure for capability configuration.The test now accepts capability configuration options, allowing for more targeted testing of how the server handles different capability configurations.
Also applies to: 657-659
672-674
: Consistent capability configuration across test cases.Each test case now specifies its required capabilities explicitly, which makes the tests more self-contained and clearer about their prerequisites.
Also applies to: 687-689
696-697
: Updated server initialization with capability options.The server initialization now uses the capability options specified in each test case, ensuring that the server is properly configured for the test scenario.
77-78
:❓ Verification inconclusive
Changed resource subscription behavior assertion.
This change from
assert.False
toassert.True
represents a change in expected behavior for resource subscription capabilities. Make sure this change is intentional and consistent with the actual implementation.
🏁 Script executed:
#!/bin/bash # Verify that the resource subscription behavior in the code matches the updated test expectation # Check the default initialization in server.go echo "Checking default initialization in server.go:" rg -A 5 -n "capabilities: serverCapabilities" server/server.go # Check the WithResourceCapabilities function echo "Checking WithResourceCapabilities function:" rg -A 10 -n "WithResourceCapabilities" server/server.goLength of output: 1062
Action Required: Verify Resource Subscription Configuration Override
The test now asserts that the resource subscription capability is enabled (true), which deviates from the default initialization in
server/server.go
wheresubscribe
is set to false. We verified that theWithResourceCapabilities
function correctly accepts a parameter to override this default. Please confirm that the server instance in the test is intentionally constructed with this override (e.g., by usingWithResourceCapabilities(true, ...)
) and that no unintentional behavior occurs in pathways that rely on the default initialization.
@ezynda3 Hi, I have added the tests according to your suggestions and optimized and adjusted the relevant code. Here are the go test results from my local machine. Looking forward to your feedback. |
@EdmondFrank added a comment |
Signed-off-by: edmondfrank <[email protected]>
The addition of tool capabilities in a structured manner enhances the modularity and flexibility of the server's capabilities management.
Summary by CodeRabbit
New Features
Bug Fixes
Tests