Skip to content

feat(spanner): add spanner-get-database-ddl tool - #3818

Open
anubhav756 wants to merge 1 commit into
anubhav-readonly-spannerfrom
anubhav-spanner-get-ddl
Open

feat(spanner): add spanner-get-database-ddl tool#3818
anubhav756 wants to merge 1 commit into
anubhav-readonly-spannerfrom
anubhav-spanner-get-ddl

Conversation

@anubhav756

@anubhav756 anubhav756 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces the spanner-get-database-ddl tool, allowing MCP agents to retrieve the complete schema definition (DDL statements) of a Cloud Spanner database.

Changes:

  • Added DatabaseAdminClient lifecycle management and lazy on-demand initialization to Spanner Source.
  • Implemented GetDatabaseDdl(ctx, tokenString) on Spanner Source using the Cloud Spanner Database Admin API.
  • Created spanner-get-database-ddl with ReadOnlyAnnotations (readOnlyHint: true, destructiveHint: false).
  • Registered the tool in imports.go and added reference documentation in spanner-get-database-ddl.md.

@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 introduces a new Spanner tool, spanner-get-database-ddl, which retrieves the DDL statements defining the schema of a Cloud Spanner database. This includes adding the tool implementation, updating the Spanner source to support fetching the database DDL via a Spanner admin client, adding unit tests, and providing documentation. The reviewer noted an issue in the tool's Invoke method where authentication errors from ParseBearerToken are incorrectly wrapped and returned as internal server errors (500) instead of unauthorized errors (401), and suggested propagating the original error.

Comment on lines +120 to +125
if source.UseClientAuthorization() {
tokenStr, err = accessToken.ParseBearerToken()
if err != nil {
return nil, util.NewClientServerError("failed to parse access token", http.StatusInternalServerError, err)
}
}

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.

medium

When accessToken.ParseBearerToken() fails, it already returns a util.ToolboxError with a 401 Unauthorized status code. Wrapping it in a new util.NewClientServerError with http.StatusInternalServerError overrides this and returns a 500 Internal Server Error to the client, which is misleading for authentication failures. We should propagate the original util.ToolboxError if present, or default to http.StatusUnauthorized.

	if source.UseClientAuthorization() {
		tokenStr, err = accessToken.ParseBearerToken()
		if err != nil {
			if toolboxErr, ok := err.(util.ToolboxError); ok {
				return nil, toolboxErr
			}
			return nil, util.NewClientServerError("failed to parse access token", http.StatusUnauthorized, err)
		}
	}

@anubhav756
anubhav756 requested review from a team as code owners August 13, 2026 13:17
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from b4d2439 to dd2ddfd Compare August 13, 2026 13:17
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from dd2ddfd to ec197d2 Compare August 13, 2026 15:49
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from ec197d2 to 975ad26 Compare August 13, 2026 15:50
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from 975ad26 to 85a31a7 Compare August 14, 2026 06:05
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from 85a31a7 to 2957746 Compare August 14, 2026 15:11
@anubhav756
anubhav756 force-pushed the anubhav-spanner-get-ddl branch from 2957746 to 11cea03 Compare August 17, 2026 05:45
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.

2 participants