Skip to content

test(source/bigquery): add MCP integration tests - #4046

Open
arijitbakshi15-stack wants to merge 1 commit into
googleapis:mainfrom
arijitbakshi15-stack:chore/bigquery-mcp-migration
Open

arijitbakshi15-stack wants to merge 1 commit into
googleapis:mainfrom
arijitbakshi15-stack:chore/bigquery-mcp-migration

Conversation

@arijitbakshi15-stack

@arijitbakshi15-stack arijitbakshi15-stack commented Sep 15, 2026

Copy link
Copy Markdown

Description

Adds BigQuery integration tests for the /mcp endpoint 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:

  • TestBigQueryMCPListTools verifies the complete tools/list manifest for all 48 tools, built from GetBaseMCPExpectedTools(), GetExecuteSQLMCPExpectedTools() and GetTemplateParamMCPExpectedTools() plus the BigQuery-specific entries (data-type, client-auth, semantic search and the 27 prebuilt tools).
  • TestBigQueryMCPCallTool runs the shared helpers with WithMCP(), WithMCPTemplate() and WithMCPExec(), and RunMCPToolCallMethod, which already ran over /mcp.
  • TestBigQueryMCPToolWithDatasetRestriction, TestBigQueryMCPWriteModeAllowed, TestBigQueryMCPWriteModeBlocked, TestBigQueryMCPWriteModeProtected and TestBigQueryMCPReadOnlyVulnerabilityBlock cover 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.ToolExecOption and describe each case in an endpoint-neutral way (toolName string, args map[string]any), evaluated by one runner with a single if config.IsMCP() { ... } else { ...legacy... }. The legacy tests call them unchanged and keep running over /api.

Shared harness:

  • RunSearchCatalogToolTest and RunSemanticSearchToolInvokeTest accept the same option. Defaults are unchanged, so Spanner, Postgres, Cloud SQL Postgres, ClickHouse, Neo4j, Elasticsearch and SingleStore are unaffected.
  • ToolExecConfig gets an exported IsMCP() 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). RunMCPToolCallMethod already asserts this in BigQuery CI; the two cases previously expected HTTP 200. BigQuery is the only caller of EnableClientAuthTest.

Validation

  • The expected manifests come from real tools/list output. I started the Toolbox with this exact config, a placeholder authorized_user ADC file and a placeholder Gemini key, so no Google calls were made, and the strict check passed. A deliberately altered description failed.
  • The error cases that never reach Google (missing parameter, authRequired without a token, client-OAuth without a token) pass through the new runner on both endpoints: once with --enable-api on /api, once over /mcp. Negative controls with wrong expected text failed on both paths.
  • Case parity with main was checked helper by helper; the /api case tables are unchanged in content.
  • go build ./..., go vet ./tests/..., gofmt and golangci-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

PR Checklist

  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure you have manually reviewed the entire diff before requesting a review
  • Ensure the tests and linter pass (linter passes; integration tests need CI)
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involves a breaking change

Part of #3706 🦕

@google-cla

google-cla Bot commented Sep 15, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@AlexTalreja

AlexTalreja commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Hi @arijitbakshi15-stack, could you update the PR and other migrations to have the migrated /mcp tests in a new file similar to the convention in #2922?

Additionally, here are some guidelines we've been given regarding the migration:

  1. Every integration test should have this 2 test functions: Test<>ListTools and Test<>CallTools
  2. Let's use the options method (ref: test(source/cloud-sql-mysql): create MCP integration tests #2922) to refactor existing test functions to take both the /api and /mcp endpoint. With this, we won't have to worry if there are test cases where it was tested in the api but not the mcp endpoint. If needed, we can update the following:
    update api string or url string to toolName string so that it could be used for both api and mcp endpoint.
    update args string to be args map[string]any so that it could be used for both api and mcp endpoint.
    add contentError bool as needed if we want to check the content[0].IsError value.
  3. utilize the GetBaseMCPExpectedTools(), GetExecuteSQLMCPExpectedTools(), and GetTemplateParamMCPExpectedTools() to retrieve common tools' []MCPToolManifest. Every source should have the same items for these if they are tested fully. We can add source-specific ones as needed.

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
@arijitbakshi15-stack arijitbakshi15-stack changed the title test(source/bigquery): migrate integration tests to MCP endpoint test(source/bigquery): add MCP integration tests Sep 17, 2026
@arijitbakshi15-stack
arijitbakshi15-stack force-pushed the chore/bigquery-mcp-migration branch from 3796687 to 1a12ad4 Compare September 17, 2026 19:07
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