Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ title: "cloud-storage-create-bucket"
type: docs
weight: 2
description: >
A "cloud-storage-create-bucket" tool creates a Cloud Storage bucket in the configured source project.
A "cloud-storage-create-bucket" tool creates a Cloud Storage bucket in a configured or runtime-selected project.
---

## About

A `cloud-storage-create-bucket` tool creates a new Cloud Storage bucket in the
project configured on the Cloud Storage source. Use it when an agent needs to
provision a bucket before writing objects or building a data workflow.
A `cloud-storage-create-bucket` tool creates a new Cloud Storage bucket. By
default, it creates the bucket in the project configured on the Cloud Storage
source. You can pass the optional `project` parameter to create buckets in a
different project that the same credentials can access.

You can also set `project`, `location`, or `uniform_bucket_level_access` in the
tool configuration. When set, that field is removed from the runtime parameter
schema and the configured value is always used. Set `project` to an empty string
to hide the parameter while using the source's configured project.

[gcs-buckets]: https://cloud.google.com/storage/docs/buckets

Expand All @@ -20,7 +26,7 @@ provision a bucket before writing objects or building a data workflow.

## Requirements

The Cloud Storage credentials must be able to create buckets in the configured
The Cloud Storage credentials must be able to create buckets in the target
project. Bucket names are globally unique and must satisfy Cloud Storage bucket
naming rules.

Expand All @@ -29,6 +35,7 @@ naming rules.
| **parameter** | **type** | **required** | **description** |
|---------------|:--------:|:------------:|-----------------|
| bucket | string | true | Name of the Cloud Storage bucket to create. |
| project | string | false | Project ID to create the bucket in. When empty, the source's configured project is used. |
| location | string | false | Location for the bucket, e.g. "US", "EU", or "us-central1". Omit to use the Cloud Storage service default. |
| uniform_bucket_level_access | boolean | false | Whether to enable uniform bucket-level access on the bucket. Defaults to false. |

Expand All @@ -42,6 +49,17 @@ source: my-gcs-source
description: Use this tool to create Cloud Storage buckets.
```

```yaml
kind: tool
name: create_us_bucket
type: cloud-storage-create-bucket
source: my-gcs-source
description: Use this tool to create Cloud Storage buckets in the US location.
project: ""
location: US
uniform_bucket_level_access: true
```

## Output Format

The tool returns a JSON object with:
Expand All @@ -59,3 +77,6 @@ The tool returns a JSON object with:
| type | string | true | Must be "cloud-storage-create-bucket". |
| source | string | true | Name of the Cloud Storage source to create buckets from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| project | string | false | Project ID to always use. When set, the runtime `project` parameter is hidden. An empty string uses the source's configured project. |
| location | string | false | Bucket location to always use. When set, the runtime `location` parameter is hidden. |
| uniform_bucket_level_access | boolean | false | Uniform bucket-level access setting to always use. When set, the runtime `uniform_bucket_level_access` parameter is hidden. |
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ A `cloud-storage-get-bucket-iam-policy` tool returns the IAM policy bindings for
a Cloud Storage bucket. Use it to inspect which principals have roles on a
bucket without modifying access.

You can set `bucket` in the tool configuration. When set, `bucket` is removed
from the runtime parameter schema and the configured bucket is always used. A
configured `bucket` must be a non-empty string.

## Compatible Sources

{{< compatible-sources >}}
Expand All @@ -37,6 +41,15 @@ source: my-gcs-source
description: Use this tool to inspect IAM bindings for a Cloud Storage bucket.
```

```yaml
kind: tool
name: get_app_bucket_iam_policy
type: cloud-storage-get-bucket-iam-policy
source: my-gcs-source
description: Use this tool to inspect IAM bindings for the application bucket.
bucket: my-app-bucket
```

## Output Format

The tool returns a JSON object with:
Expand All @@ -53,3 +66,4 @@ The tool returns a JSON object with:
| type | string | true | Must be "cloud-storage-get-bucket-iam-policy". |
| source | string | true | Name of the Cloud Storage source to get bucket IAM policies from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| bucket | string | false | Bucket whose IAM policy is always returned. When set, the runtime `bucket` parameter is hidden. Must not be empty. |
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class, labels, lifecycle configuration, or uniform bucket-level access status.

The response is the bucket metadata structure returned by the Cloud Storage API.

You can set `bucket` in the tool configuration. When set, `bucket` is removed
from the runtime parameter schema and the configured bucket is always used. A
configured `bucket` must be a non-empty string.

## Compatible Sources

{{< compatible-sources >}}
Expand All @@ -39,6 +43,15 @@ source: my-gcs-source
description: Use this tool to inspect metadata for a Cloud Storage bucket.
```

```yaml
kind: tool
name: get_app_bucket_metadata
type: cloud-storage-get-bucket-metadata
source: my-gcs-source
description: Use this tool to inspect metadata for the application bucket.
bucket: my-app-bucket
```

## Output Format

The tool returns bucket metadata from the Cloud Storage API, including fields
Expand All @@ -52,3 +65,4 @@ such as `Name`, `Location`, `StorageClass`, `Created`, `Labels`,
| type | string | true | Must be "cloud-storage-get-bucket-metadata". |
| source | string | true | Name of the Cloud Storage source to get bucket metadata from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| bucket | string | false | Bucket to always inspect. When set, the runtime `bucket` parameter is hidden. Must not be empty. |
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ or custom metadata without reading the object's content.

The response is the object metadata structure returned by the Cloud Storage API.

You can set `bucket` in the tool configuration. When set, `bucket` is removed
from the runtime parameter schema and the configured bucket is always used. A
configured `bucket` must be a non-empty string.

[gcs-objects]: https://cloud.google.com/storage/docs/objects

## Compatible Sources
Expand All @@ -38,6 +42,15 @@ source: my-gcs-source
description: Use this tool to inspect metadata for a Cloud Storage object.
```

```yaml
kind: tool
name: get_app_object_metadata
type: cloud-storage-get-object-metadata
source: my-gcs-source
description: Use this tool to inspect metadata for objects in the application bucket.
bucket: my-app-bucket
```

## Output Format

The tool returns object metadata from the Cloud Storage API, including fields
Expand All @@ -51,3 +64,4 @@ such as `Name`, `Bucket`, `Size`, `ContentType`, `Updated`, `StorageClass`,
| type | string | true | Must be "cloud-storage-get-object-metadata". |
| source | string | true | Name of the Cloud Storage source to get object metadata from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| bucket | string | false | Bucket to always inspect objects from. When set, the runtime `bucket` parameter is hidden. Must not be empty. |
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ project. By default, it uses the project configured on the source. You can pass
the optional `project` parameter to list buckets in a different project that
the same credentials can access.

You can also set `project` or `prefix` in the tool configuration. When set,
that field is removed from the runtime parameter schema and the configured value
is always used. Set `project` to an empty string to hide the parameter while
using the source's configured project.

The response is a JSON object with `buckets` (bucket metadata returned by the
Cloud Storage API) and `nextPageToken` (empty when there are no more pages).

Expand Down Expand Up @@ -41,6 +46,16 @@ source: my-gcs-source
description: Use this tool to list Cloud Storage buckets in the project.
```

```yaml
kind: tool
name: list_log_buckets
type: cloud-storage-list-buckets
source: my-gcs-source
description: Use this tool to list log buckets in the configured project.
project: ""
prefix: logs-
```

## Output Format

The tool returns a JSON object with:
Expand All @@ -57,3 +72,5 @@ The tool returns a JSON object with:
| type | string | true | Must be "cloud-storage-list-buckets". |
| source | string | true | Name of the Cloud Storage source to list buckets from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| project | string | false | Project ID to always use. When set, the runtime `project` parameter is hidden. An empty string uses the source's configured project. |
| prefix | string | false | Bucket name prefix to always use. When set, the runtime `prefix` parameter is hidden. |
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ returned by the Cloud Storage API — fields such as `Name`, `Size`, `ContentTyp
`Updated`, `StorageClass`, `MD5`, etc.), `prefixes` (the common prefixes when
`delimiter` is set), and `nextPageToken` (empty when there are no more pages).

You can set `bucket`, `prefix`, or `delimiter` in the tool configuration. When
set, that field is removed from the runtime parameter schema and the configured
value is always used. A configured `bucket` must be a non-empty string.

[gcs-buckets]: https://cloud.google.com/storage/docs/buckets

## Compatible Sources
Expand All @@ -47,10 +51,24 @@ source: my-gcs-source
description: Use this tool to list objects in a Cloud Storage bucket.
```

```yaml
kind: tool
name: list_log_objects
type: cloud-storage-list-objects
source: my-gcs-source
description: Use this tool to list log objects in a Cloud Storage bucket.
bucket: my-log-bucket
prefix: logs/
delimiter: /
```

## Reference

| **field** | **type** | **required** | **description** |
|-------------|:--------:|:------------:|---------------------------------------------------------|
| type | string | true | Must be "cloud-storage-list-objects". |
| source | string | true | Name of the Cloud Storage source to list objects from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| bucket | string | false | Bucket to always list from. When set, the runtime `bucket` parameter is hidden. Must not be empty. |
| prefix | string | false | Object prefix to always use. When set, the runtime `prefix` parameter is hidden. |
| delimiter | string | false | Delimiter to always use. When set, the runtime `delimiter` parameter is hidden. |
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ This tool is intended for small-to-medium textual content an LLM can process
directly. For bulk downloads of large files to the local filesystem, use
`cloud-storage-download-object`.

You can set `bucket` in the tool configuration. When set, `bucket` is removed
from the runtime parameter schema and the configured bucket is always used. A
configured `bucket` must be a non-empty string.

[gcs-objects]: https://cloud.google.com/storage/docs/objects

## Compatible Sources
Expand All @@ -49,10 +53,20 @@ source: my-gcs-source
description: Use this tool to read the content of a Cloud Storage object.
```

```yaml
kind: tool
name: read_app_object
type: cloud-storage-read-object
source: my-gcs-source
description: Use this tool to read text objects from the application bucket.
bucket: my-app-bucket
```

## Reference

| **field** | **type** | **required** | **description** |
|-------------|:--------:|:------------:|---------------------------------------------------------|
| type | string | true | Must be "cloud-storage-read-object". |
| source | string | true | Name of the Cloud Storage source to read the object from. |
| description | string | true | Description of the tool that is passed to the LLM. |
| bucket | string | false | Bucket to always read from. When set, the runtime `bucket` parameter is hidden. Must not be empty. |
15 changes: 9 additions & 6 deletions internal/sources/cloudstorage/cloudstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,24 @@ func (s *Source) ListBuckets(ctx context.Context, project, prefix string, maxRes
}, nil
}

// CreateBucket creates a Cloud Storage bucket in the source project and returns
// its freshly-read metadata. When location is empty, Cloud Storage applies its
// service default.
func (s *Source) CreateBucket(ctx context.Context, bucket, location string, uniformBucketLevelAccess bool) (map[string]any, error) {
// CreateBucket creates a Cloud Storage bucket and returns its freshly-read
// metadata. When project is empty, the source's configured project is used.
// When location is empty, Cloud Storage applies its service default.
func (s *Source) CreateBucket(ctx context.Context, bucket, project, location string, uniformBucketLevelAccess bool) (map[string]any, error) {
if err := s.validateBucket(bucket); err != nil {
return nil, err
}
if project == "" {
project = s.Project
}
attrs := &storage.BucketAttrs{Location: location}
if uniformBucketLevelAccess {
attrs.UniformBucketLevelAccess = storage.UniformBucketLevelAccess{Enabled: true}
}

bkt := s.client.Bucket(bucket)
if err := bkt.Create(ctx, s.Project, attrs); err != nil {
return nil, fmt.Errorf("failed to create bucket %q in project %q: %w", bucket, s.Project, err)
if err := bkt.Create(ctx, project, attrs); err != nil {
return nil, fmt.Errorf("failed to create bucket %q in project %q: %w", bucket, project, err)
}

createdAttrs, err := bkt.Attrs(ctx)
Expand Down
31 changes: 31 additions & 0 deletions internal/tools/cloudstorage/cloudstoragecommon/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2026 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 cloudstoragecommon

func ResolveString(cfgVal *string, params map[string]any, key string) string {
if cfgVal != nil {
return *cfgVal
}
val, _ := params[key].(string)
return val
}

func ResolveBool(cfgVal *bool, params map[string]any, key string) bool {
if cfgVal != nil {
return *cfgVal
}
val, _ := params[key].(bool)
return val
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
const resourceType string = "cloud-storage-create-bucket"

const (
projectKey = "project"
bucketKey = "bucket"
locationKey = "location"
uniformBucketLevelAccessKey = "uniform_bucket_level_access"
Expand All @@ -49,14 +50,17 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T
}

type compatibleSource interface {
CreateBucket(ctx context.Context, bucket, location string, uniformBucketLevelAccess bool) (map[string]any, error)
CreateBucket(ctx context.Context, bucket, project, location string, uniformBucketLevelAccess bool) (map[string]any, error)
}

type Config struct {
tools.ConfigBase `yaml:",inline"`
Type string `yaml:"type" validate:"required"`
Source string `yaml:"source" validate:"required"`
Annotations *tools.ToolAnnotations `yaml:"annotations,omitempty"`
tools.ConfigBase `yaml:",inline"`
Type string `yaml:"type" validate:"required"`
Source string `yaml:"source" validate:"required"`
Annotations *tools.ToolAnnotations `yaml:"annotations,omitempty"`
Project *string `yaml:"project,omitempty"`
Location *string `yaml:"location,omitempty"`
UniformBucketLevelAccess *bool `yaml:"uniform_bucket_level_access,omitempty"`
}

var _ tools.ToolConfig = Config{}
Expand All @@ -71,9 +75,16 @@ func (cfg Config) Initialize(context.Context) (tools.Tool, error) {
}

bucketParam := parameters.NewStringParameter(bucketKey, "Name of the Cloud Storage bucket to create.")
locationParam := parameters.NewStringParameter(locationKey, "Location for the bucket, e.g. 'US', 'EU', or 'us-central1'. Omit to use the Cloud Storage service default.", parameters.WithStringRequired(false))
uniformAccessParam := parameters.NewBooleanParameter(uniformBucketLevelAccessKey, "Whether to enable uniform bucket-level access on the bucket.", parameters.WithBooleanDefault(false))
allParameters := parameters.Parameters{bucketParam, locationParam, uniformAccessParam}
allParameters := parameters.Parameters{bucketParam}
if cfg.Project == nil {
allParameters = append(allParameters, parameters.NewStringParameter(projectKey, "Project ID to create the bucket in. When empty, the source's configured project is used.", parameters.WithStringDefault("")))
}
if cfg.Location == nil {
allParameters = append(allParameters, parameters.NewStringParameter(locationKey, "Location for the bucket, e.g. 'US', 'EU', or 'us-central1'. Omit to use the Cloud Storage service default.", parameters.WithStringRequired(false)))
}
if cfg.UniformBucketLevelAccess == nil {
allParameters = append(allParameters, parameters.NewBooleanParameter(uniformBucketLevelAccessKey, "Whether to enable uniform bucket-level access on the bucket.", parameters.WithBooleanDefault(false)))
}

return Tool{
BaseTool: tools.NewBaseTool(
Expand Down Expand Up @@ -106,10 +117,11 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
if !ok || bucket == "" {
return nil, util.NewAgentError(fmt.Sprintf("invalid or missing '%s' parameter; expected a non-empty string", bucketKey), nil)
}
location, _ := mapParams[locationKey].(string)
uniformBucketLevelAccess, _ := mapParams[uniformBucketLevelAccessKey].(bool)
project := cloudstoragecommon.ResolveString(t.Cfg.Project, mapParams, projectKey)
location := cloudstoragecommon.ResolveString(t.Cfg.Location, mapParams, locationKey)
uniformBucketLevelAccess := cloudstoragecommon.ResolveBool(t.Cfg.UniformBucketLevelAccess, mapParams, uniformBucketLevelAccessKey)

resp, err := source.CreateBucket(ctx, bucket, location, uniformBucketLevelAccess)
resp, err := source.CreateBucket(ctx, bucket, project, location, uniformBucketLevelAccess)
if err != nil {
return nil, cloudstoragecommon.ProcessGCSError(err)
}
Expand Down
Loading
Loading