-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(spanner-admin): spanner admin source + create instance tool #2209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gRedHeadphone
wants to merge
23
commits into
main
Choose a base branch
from
spanner-create-instance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
302b564
feat(spanner-admin): spanner admin source + create instance tool
gRedHeadphone 5b7f5a3
chore: update parameter description & format docs table spanner creat…
gRedHeadphone e6de217
Update internal/sources/spanneradmin/spanneradmin.go
gRedHeadphone 4f62db4
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone e831f71
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 330dd84
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 7d79f49
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 09c979d
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone a9edd5e
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 4170fe3
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone f9f34b1
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 62095fe
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 511c465
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone c67b0cf
Update internal/tools/spanneradmin/spannercreateinstance/spannercreat…
gRedHeadphone 1475b4d
Merge branch 'main' into spanner-create-instance
gRedHeadphone af62ddf
chore: minor fixes
gRedHeadphone 3a317a3
Merge branch 'main' into spanner-create-instance
gRedHeadphone 6d43488
Merge branch 'main' into spanner-create-instance
gRedHeadphone 589059e
Merge branch 'main' into spanner-create-instance
gRedHeadphone de7c65e
chore: header update + main merge fixes
gRedHeadphone a7d0f19
Merge branch 'main' into spanner-create-instance
gRedHeadphone 668ca5d
Merge branch 'main' into spanner-create-instance
gRedHeadphone caa33d4
chore: fix for configuration file changes
gRedHeadphone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Cloud Spanner Admin MCP Server | ||
|
|
||
| The Cloud Spanner Admin Model Context Protocol (MCP) Server gives AI-powered development tools the ability to manage your Google Cloud Spanner infrastructure. It supports creating instances. | ||
|
|
||
| ## Features | ||
|
|
||
| An editor configured to use the Cloud Spanner Admin MCP server can use its AI capabilities to help you: | ||
|
|
||
| - **Provision & Manage Infrastructure** - Create Cloud Spanner instances | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| * [Node.js](https://nodejs.org/) installed. | ||
| * A Google Cloud project with the **Cloud Spanner Admin API** enabled. | ||
| * Ensure [Application Default Credentials](https://cloud.google.com/docs/authentication/gcloud) are available in your environment. | ||
| * IAM Permissions: | ||
| * Cloud Spanner Admin (`roles/spanner.admin`) | ||
|
|
||
| ## Install & Configuration | ||
|
|
||
| In the Antigravity MCP Store, click the "Install" button. | ||
|
|
||
| You'll now be able to see all enabled tools in the "Tools" tab. | ||
|
|
||
| > [!NOTE] | ||
| > If you encounter issues with Windows Defender blocking the execution, you may need to configure an allowlist. See [Configure exclusions for Microsoft Defender Antivirus](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/configure-exclusions-microsoft-defender-antivirus?view=o365-worldwide) for more details. | ||
|
|
||
| ## Usage | ||
|
|
||
| Once configured, the MCP server will automatically provide Cloud Spanner Admin capabilities to your AI assistant. You can: | ||
|
|
||
| * "Create a new Spanner instance named 'my-spanner-instance' in the 'my-gcp-project' project with config 'regional-us-central1', edition 'ENTERPRISE', and 1 node." | ||
|
|
||
| ## Server Capabilities | ||
|
|
||
| The Cloud Spanner Admin MCP server provides the following tools: | ||
|
|
||
| | Tool Name | Description | | ||
| |:------------------|:---------------------------------| | ||
| | `create_instance` | Create a Cloud Spanner instance. | | ||
|
|
||
| ## Custom MCP Server Configuration | ||
|
|
||
| Add the following configuration to your MCP client (e.g., `settings.json` for Gemini CLI, `mcp_config.json` for Antigravity): | ||
|
|
||
| ```json | ||
| { | ||
| "mcpServers": { | ||
| "spanner-admin": { | ||
| "command": "npx", | ||
| "args": ["-y", "@toolbox-sdk/server", "--prebuilt", "spanner-admin", "--stdio"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| For more information, visit the [Cloud Spanner Admin API documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| title: Spanner Admin | ||
| type: docs | ||
| weight: 1 | ||
| description: "A \"spanner-admin\" source provides a client for the Cloud Spanner Admin API.\n" | ||
| alias: [/resources/sources/spanner-admin] | ||
| --- | ||
|
|
||
| ## About | ||
|
|
||
| The `spanner-admin` source provides a client to interact with the [Google | ||
| Cloud Spanner Admin API](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1). This | ||
| allows tools to perform administrative tasks on Spanner instances, such as | ||
| creating instances. | ||
|
|
||
| Authentication can be handled in two ways: | ||
|
|
||
| 1. **Application Default Credentials (ADC):** By default, the source uses ADC | ||
| to authenticate with the API. | ||
| 2. **Client-side OAuth:** If `useClientOAuth` is set to `true`, the source will | ||
| expect an OAuth 2.0 access token to be provided by the client (e.g., a web | ||
| browser) for each request. | ||
|
|
||
| ## Example | ||
|
|
||
| ```yaml | ||
| sources: | ||
| my-spanner-admin: | ||
| kind: spanner-admin | ||
|
|
||
| my-oauth-spanner-admin: | ||
| kind: spanner-admin | ||
| useClientOAuth: true | ||
| ``` | ||
|
|
||
| ## Reference | ||
|
|
||
| | **field** | **type** | **required** | **description** | | ||
| | -------------- | :------: | :----------: | ---------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | kind | string | true | Must be "spanner-admin". | | ||
| | defaultProject | string | false | The Google Cloud project ID to use for Spanner infrastructure tools. | | ||
| | useClientOAuth | boolean | false | If true, the source will use client-side OAuth for authorization. Otherwise, it will use Application Default Credentials. Defaults to `false`. | |
52 changes: 52 additions & 0 deletions
52
docs/en/resources/tools/spanneradmin/spanner-create-instance.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| title: spanner-create-instance | ||
| type: docs | ||
| weight: 2 | ||
| description: "Create a Cloud Spanner instance." | ||
| --- | ||
|
|
||
| The `spanner-create-instance` tool creates a new Cloud Spanner instance in a | ||
| specified Google Cloud project. | ||
|
|
||
| {{< notice info >}} | ||
| This tool uses the `spanner-admin` source. | ||
| {{< /notice >}} | ||
|
|
||
| ## Configuration | ||
|
|
||
| Here is an example of how to configure the `spanner-create-instance` tool in | ||
| your `tools.yaml` file: | ||
|
|
||
| ```yaml | ||
| sources: | ||
| my-spanner-admin-source: | ||
| kind: spanner-admin | ||
|
|
||
| tools: | ||
| create_my_spanner_instance: | ||
| kind: spanner-create-instance | ||
| source: my-spanner-admin-source | ||
| description: "Creates a Spanner instance." | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| The `spanner-create-instance` tool has the following parameters: | ||
|
|
||
| | **field** | **type** | **required** | **description** | | ||
| | --------------- | :------: | :----------: | ------------------------------------------------------------------------------------ | | ||
| | project | string | true | The Google Cloud project ID. | | ||
| | instanceId | string | true | The ID of the instance to create. | | ||
| | displayName | string | true | The display name of the instance. | | ||
| | config | string | true | The instance configuration (e.g., `regional-us-central1`). | | ||
| | nodeCount | integer | true | The number of nodes. Mutually exclusive with `processingUnits` (one must be 0). | | ||
| | processingUnits | integer | true | The number of processing units. Mutually exclusive with `nodeCount` (one must be 0). | | ||
| | edition | string | false | The edition of the instance (`STANDARD`, `ENTERPRISE`, `ENTERPRISE_PLUS`). | | ||
|
|
||
| ## Reference | ||
|
|
||
| | **field** | **type** | **required** | **description** | | ||
| | ----------- | :------: | :----------: | ------------------------------------------------------------ | | ||
| | kind | string | true | Must be `spanner-create-instance`. | | ||
| | source | string | true | The name of the `spanner-admin` source to use for this tool. | | ||
| | description | string | false | A description of the tool that is passed to the agent. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| sources: | ||
| spanner-admin-source: | ||
| kind: spanner-admin | ||
| defaultProject: ${SPANNER_PROJECT:} | ||
|
|
||
| tools: | ||
| create_instance: | ||
| kind: spanner-create-instance | ||
| source: spanner-admin-source | ||
|
|
||
| toolsets: | ||
| spanner_admin_tools: | ||
| - create_instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package spanneradmin | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| instance "cloud.google.com/go/spanner/admin/instance/apiv1" | ||
| "github.com/goccy/go-yaml" | ||
| "github.com/googleapis/genai-toolbox/internal/sources" | ||
| "github.com/googleapis/genai-toolbox/internal/util" | ||
| "go.opentelemetry.io/otel/trace" | ||
| "golang.org/x/oauth2" | ||
| "google.golang.org/api/option" | ||
| ) | ||
|
|
||
| const SourceKind string = "spanner-admin" | ||
|
|
||
| // validate interface | ||
| var _ sources.SourceConfig = Config{} | ||
|
|
||
| func init() { | ||
| if !sources.Register(SourceKind, newConfig) { | ||
| panic(fmt.Sprintf("source kind %q already registered", SourceKind)) | ||
| } | ||
| } | ||
|
|
||
| func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources.SourceConfig, error) { | ||
| actual := Config{Name: name} | ||
| if err := decoder.DecodeContext(ctx, &actual); err != nil { | ||
| return nil, err | ||
| } | ||
| return actual, nil | ||
| } | ||
|
|
||
| type Config struct { | ||
| Name string `yaml:"name" validate:"required"` | ||
| Kind string `yaml:"kind" validate:"required"` | ||
| DefaultProject string `yaml:"defaultProject"` | ||
| UseClientOAuth bool `yaml:"useClientOAuth"` | ||
| } | ||
|
|
||
| func (r Config) SourceConfigKind() string { | ||
| return SourceKind | ||
| } | ||
|
|
||
| // Initialize initializes a Spanner Admin Source instance. | ||
| func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) { | ||
| var client *instance.InstanceAdminClient | ||
|
|
||
| if !r.UseClientOAuth { | ||
| ua, err := util.UserAgentFromContext(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error in User Agent retrieval: %s", err) | ||
| } | ||
| // Use Application Default Credentials | ||
| client, err = instance.NewInstanceAdminClient(ctx, option.WithUserAgent(ua)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating new spanner instance admin client: %w", err) | ||
| } | ||
| } | ||
|
|
||
| s := &Source{ | ||
| Config: r, | ||
| Client: client, | ||
| } | ||
| return s, nil | ||
| } | ||
|
|
||
| var _ sources.Source = &Source{} | ||
|
|
||
| type Source struct { | ||
| Config | ||
| Client *instance.InstanceAdminClient | ||
| } | ||
|
|
||
| func (s *Source) SourceKind() string { | ||
| return SourceKind | ||
| } | ||
|
|
||
| func (s *Source) ToConfig() sources.SourceConfig { | ||
| return s.Config | ||
| } | ||
|
|
||
| func (s *Source) GetClient(ctx context.Context, accessToken string) (*instance.InstanceAdminClient, error) { | ||
| if s.UseClientOAuth { | ||
| token := &oauth2.Token{AccessToken: accessToken} | ||
| ua, err := util.UserAgentFromContext(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| client, err := instance.NewInstanceAdminClient(ctx, option.WithTokenSource(oauth2.StaticTokenSource(token)), option.WithUserAgent(ua)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating new spanner instance admin client: %w", err) | ||
| } | ||
| return client, nil | ||
| } | ||
| return s.Client, nil | ||
| } | ||
|
|
||
| func (s *Source) UseClientAuthorization() bool { | ||
| return s.UseClientOAuth | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.