test(source/alloydbainl): create MCP integration tests#2921
test(source/alloydbainl): create MCP integration tests#2921anubhav756 wants to merge 4 commits intoanubhav-feat-native-mcp-alloydbfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the AlloyDB AI NL integration tests by moving shared configuration and environment variable logic into a new file, alloydb_ai_nl_mcp_test.go, which focuses on testing tool functionality via the Model Context Protocol (MCP). The new tests cover tool listing and various invocation scenarios, including authenticated and unauthenticated requests. Feedback includes a recommendation to add safety checks for slice indexing to prevent runtime panics and a requirement to update tool names to snake_case to comply with the project's style guide.
| if mcpResp.Result.IsError { | ||
| t.Fatalf("expected success result, got error: %v", mcpResp.Result) | ||
| } | ||
| got := mcpResp.Result.Content[0].Text |
There was a problem hiding this comment.
Accessing mcpResp.Result.Content[0] without checking the length of the Content slice could lead to a runtime panic if the tool returns an empty result. It is safer to verify that at least one content item is present before accessing it.
| got := mcpResp.Result.Content[0].Text | |
| if len(mcpResp.Result.Content) == 0 { | |
| t.Fatalf("expected at least one content item, got none") | |
| } | |
| got := mcpResp.Result.Content[0].Text |
| }, | ||
| }, | ||
| "tools": map[string]any{ | ||
| "my-simple-tool": map[string]any{ |
There was a problem hiding this comment.
The tool name my-simple-tool uses kebab-case, which violates the repository style guide. According to the guide, tool names should use snake_case (e.g., my_simple_tool). This also applies to my-auth-tool and my-auth-required-tool defined in this configuration, as well as their usage in the test cases and other test files in this package. Additionally, since these are MCP configuration values, please ensure the code includes a comment citing and linking to the MCP semantic conventions to avoid confusion, as per repository rules.
References
- Tool names must use snake_case and should not include the product name. (link)
- When using configuration values that adhere to a specific standard like MCP, include a comment citing and linking to that standard to avoid confusion.
69bb59b to
d81edf8
Compare
fa85277 to
023e098
Compare
d81edf8 to
4c21e3f
Compare
This PR adds the mapped integration tests for AlloyDB AINL tools using the native MCP harness.