test(source/bigquery): add MCP integration tests - #4046
arijitbakshi15-stack wants to merge 1 commit into
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 updates the integration tests to support executing tool invocation tests over the Model Context Protocol (MCP) in addition to the legacy HTTP /api endpoint. Specifically, it introduces ToolExecOption to RunSemanticSearchToolInvokeTest and RunSearchCatalogToolTest to allow conditional execution over MCP, refactors RunSearchCatalogToolTest to handle both MCP and HTTP request/response formats, and updates expected MCP status codes to 401 Unauthorized for unauthorized client tool invocations. There are no review comments, and the changes look solid, so I have no feedback to provide.
|
Hi @arijitbakshi15-stack, could you update the PR and other migrations to have the migrated Additionally, here are some guidelines we've been given regarding the migration:
|
Add BigQuery integration tests for the /mcp endpoint in a new file and refactor the BigQuery test helpers to run against both endpoints, following the convention in googleapis#2922. - tests/bigquery/bigquery_mcp_test.go adds TestBigQueryMCPListTools and TestBigQueryMCPCallTool, plus MCP counterparts for the dataset restriction, write mode and read-only scenarios. All start the server without --enable-api. - List tools verifies the full tools/list manifest for all 48 tools, built from GetBaseMCPExpectedTools, GetExecuteSQLMCPExpectedTools and GetTemplateParamMCPExpectedTools plus the BigQuery specific tools. - The BigQuery helpers now take tests.ToolExecOption and describe each case with toolName and args map[string]any, so the same cases run over /api by default and over /mcp with WithMCPExec(). - RunSearchCatalogToolTest and RunSemanticSearchToolInvokeTest take the same option; defaults are unchanged for other sources. - RunToolInvokeTest expects HTTP 401 over MCP for client auth calls with a missing or invalid token, matching the server behaviour that RunMCPToolCallMethod already asserts. The legacy /api tests keep running with --enable-api. Part of googleapis#3706
3796687 to
1a12ad4
Compare
Description
Adds BigQuery integration tests for the
/mcpendpoint in a new file, and refactors the BigQuery test helpers to run against both endpoints, following the convention in #2922 and the guidelines from the review. Part of #3706.New file
tests/bigquery/bigquery_mcp_test.go, all starting the server without--enable-api:TestBigQueryMCPListToolsverifies the completetools/listmanifest for all 48 tools, built fromGetBaseMCPExpectedTools(),GetExecuteSQLMCPExpectedTools()andGetTemplateParamMCPExpectedTools()plus the BigQuery-specific entries (data-type, client-auth, semantic search and the 27 prebuilt tools).TestBigQueryMCPCallToolruns the shared helpers withWithMCP(),WithMCPTemplate()andWithMCPExec(), andRunMCPToolCallMethod, which already ran over/mcp.TestBigQueryMCPToolWithDatasetRestriction,TestBigQueryMCPWriteModeAllowed,TestBigQueryMCPWriteModeBlocked,TestBigQueryMCPWriteModeProtectedandTestBigQueryMCPReadOnlyVulnerabilityBlockcover the remaining scenarios over MCP, so no case is exercised on one endpoint only.Options method
Per the review, the BigQuery-specific helpers now take
...tests.ToolExecOptionand describe each case in an endpoint-neutral way (toolName string,args map[string]any), evaluated by one runner with a singleif config.IsMCP() { ... } else { ...legacy... }. The legacy tests call them unchanged and keep running over/api.Shared harness:
RunSearchCatalogToolTestandRunSemanticSearchToolInvokeTestaccept the same option. Defaults are unchanged, so Spanner, Postgres, Cloud SQL Postgres, ClickHouse, Neo4j, Elasticsearch and SingleStore are unaffected.ToolExecConfiggets an exportedIsMCP()so source-specific helpers can select the endpoint the same way the shared helpers do.RunToolInvokeTest: over MCP, a client-OAuth tool called without a token, or with an invalid one, is rejected with a JSON-RPC error and HTTP 401 (internal/server/mcp/v20251125/method.go).RunMCPToolCallMethodalready asserts this in BigQuery CI; the two cases previously expected HTTP 200. BigQuery is the only caller ofEnableClientAuthTest.Validation
tools/listoutput. I started the Toolbox with this exact config, a placeholderauthorized_userADC file and a placeholder Gemini key, so no Google calls were made, and the strict check passed. A deliberately altered description failed.authRequiredwithout a token, client-OAuth without a token) pass through the new runner on both endpoints: once with--enable-apion/api, once over/mcp. Negative controls with wrong expected text failed on both paths.mainwas checked helper by helper; the/apicase tables are unchanged in content.go build ./...,go vet ./tests/...,gofmtandgolangci-lint run ./tests/bigquery/... ./tests/are clean.Not yet verified
Every case that reaches BigQuery, Dataplex, Gemini or Google token verification needs real credentials and a project, which I don't have locally. Those need a maintainer CI run.
Notes for reviewers
tests/bigquery/bigquery_integration_test.gosignificantly and will likely conflict.main,RunToolInvokeWithTemplateParameterssends only the select-fields case, because the others lackenabled: true. test(source/sqlite): migrate to MCP and restore template test coverage #4006 fixes that in the shared harness; the MCP expectations here are already in the right shape for it.cloud_sql_mysql_mcp_test.godoes. Happy to drop them from this PR if the extra CI time is a concern.PR Checklist
!if this involves a breaking changePart of #3706 🦕