Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request refactors the MongoDB integration tests by extracting setup and seeding logic into helper functions, utilizing t.Cleanup for resource management, and consolidating test cases into a shared suite. It also introduces a new test file mongodb_mcp_test.go to run these shared test cases over the Model Context Protocol (MCP). The review feedback suggests improving the teardown process by using context.WithoutCancel(ctx) instead of context.Background() to preserve context values during client disconnection and collection dropping. Additionally, it recommends using InsertMany instead of looping over InsertOne to seed the test database more efficiently.
|
/gcbrun |
54a8a23 to
855a8d4
Compare
Description
This PR migrates the MongoDB integration tests to use the /mcp endpoint on the MCP Toolbox Server.
Key Changes
mongodb_mcp_test.go: Migrated legacy/apitests to/mcpTestMongoDBMCPListToolsvalidates the fulltools/listmanifest for the 18 MongoDB tools in the test config (find, find-one, delete, insert, update and aggregate tools).my-secure-toolis intentionally absent, since tools with secure parameters are excluded fromtools/listin this protocol version.TestMongoDBMCPInvokeToolruns the twelve delete, insert, update, aggregate and runtime-collection cases over MCP JSON-RPC. The two rejected invocations (read-only aggregate with$out, and a missing runtimecollection) must come back as MCP error results, asserted viaAssertMCPError.TestMongoDBMCPCallToolruns the shared fixtures over MCP:RunToolInvokeTestwithWithMCP()andRunMCPToolCallMethod. These require a Google ID token, so they are kept separate from the token-free tests above.[]anyresults, so the test flattens the content blocks and compares parsed JSON against the REST result (a scalar is compared as a one-element array).mongodb_integration_test.go: Extracted shared helpers so the legacy and MCP tests use the same setup, cases and expected values (no change to the legacy test's assertions):setupMongoDBInstancestarts the ephemeralmongo:6container.seedMongoDBconnects and seeds the test collection.getMongoDBInvokeTestCasesholds the shared cases (toolName+args map[string]any), andrunMongoDBRESTInvokeTestsruns them over REST. These replace five near-identicalrunTool*InvokeTesthelpers.t.Cleanupinstead ofdeferfor thelose`), container and collection.context.Background(), since the test context is already cancelled when they run.No shared test helpers (
tests/tool.go,teon.go) are modified. The legacy/apiMongoDB test is kept.Testing
Verified locally against the
mongo:6testcontainer (Docker only, no Google credentials):TestMongoDBMCPListToolspasses: the manimy-secure-toolis excluded.TestMongoDBMCPInvokeToolpasses: all 12 MCP invocations, including both error cases.runMongoDBRESTInvokeTests) passes all 12 cases against a server started with--enable-api. - The non-auth tools used byRunToolInvokeTestandRunMCPToolCallMethod(my-simple-tool,my-tool,my-tool-by-id,my-tool-by-name, `my-arrarn MCP output matching the shared expectedvalues.Not run locally:
TestMongoDBMCPCallToolanEndpoints. They use the shared fixtures thatrequire a Google ID token (gcloud auth print-identity-token`), so they will first run in CI.PR Checklist
CONTRIBUTING.md
bug/issue
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
review
!if this involve a breaking change🛠️ Fixes #<issue_number_goes_here>