Skip to content

Commit 2bb790e

Browse files
feat: Add Firestore as Source (#786)
Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. It's a fully managed, serverless database that supports mobile, web, and server development. This change adds Firestore as a source in toolbox
1 parent 2083ba5 commit 2bb790e

30 files changed

Lines changed: 4414 additions & 0 deletions

‎.ci/integration.cloudbuild.yaml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,26 @@ steps:
425425
"Valkey" \
426426
valkey \
427427
valkey
428+
429+
- id: "firestore"
430+
name: golang:1
431+
waitFor: ["compile-test-binary"]
432+
entrypoint: /bin/bash
433+
env:
434+
- "GOPATH=/gopath"
435+
- "FIRESTORE_PROJECT=$PROJECT_ID"
436+
- "SERVICE_ACCOUNT_EMAIL=$SERVICE_ACCOUNT_EMAIL"
437+
secretEnv: ["CLIENT_ID"]
438+
volumes:
439+
- name: "go"
440+
path: "/gopath"
441+
args:
442+
- -c
443+
- |
444+
.ci/test_with_coverage.sh \
445+
"Firestore" \
446+
firestore \
447+
firestore
428448
429449

430450
availableSecrets:

‎cmd/root.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ import (
5252
_ "github.com/googleapis/genai-toolbox/internal/tools/bigtable"
5353
_ "github.com/googleapis/genai-toolbox/internal/tools/couchbase"
5454
_ "github.com/googleapis/genai-toolbox/internal/tools/dgraph"
55+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestoredeletedocuments"
56+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestoregetdocuments"
57+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestoregetrules"
58+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestorelistcollections"
59+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestorequerycollection"
60+
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestorevalidaterules"
5561
_ "github.com/googleapis/genai-toolbox/internal/tools/http"
5662
_ "github.com/googleapis/genai-toolbox/internal/tools/mssql/mssqlexecutesql"
5763
_ "github.com/googleapis/genai-toolbox/internal/tools/mssql/mssqlsql"
@@ -77,6 +83,7 @@ import (
7783
_ "github.com/googleapis/genai-toolbox/internal/sources/cloudsqlpg"
7884
_ "github.com/googleapis/genai-toolbox/internal/sources/couchbase"
7985
_ "github.com/googleapis/genai-toolbox/internal/sources/dgraph"
86+
_ "github.com/googleapis/genai-toolbox/internal/sources/firestore"
8087
_ "github.com/googleapis/genai-toolbox/internal/sources/http"
8188
_ "github.com/googleapis/genai-toolbox/internal/sources/mssql"
8289
_ "github.com/googleapis/genai-toolbox/internal/sources/mysql"

‎cmd/root_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ func TestPrebuiltTools(t *testing.T) {
11661166
cloudsqlpg_config, _ := prebuiltconfigs.Get("cloud-sql-postgres")
11671167
cloudsqlmysql_config, _ := prebuiltconfigs.Get("cloud-sql-mysql")
11681168
cloudsqlmssql_config, _ := prebuiltconfigs.Get("cloud-sql-mssql")
1169+
firestoreconfig, _ := prebuiltconfigs.Get("firestore")
11691170
postgresconfig, _ := prebuiltconfigs.Get("postgres")
11701171
spanner_config, _ := prebuiltconfigs.Get("spanner")
11711172
spannerpg_config, _ := prebuiltconfigs.Get("spanner-postgres")
@@ -1228,6 +1229,16 @@ func TestPrebuiltTools(t *testing.T) {
12281229
},
12291230
},
12301231
},
1232+
{
1233+
name: "firestore prebuilt tools",
1234+
in: firestoreconfig,
1235+
wantToolset: server.ToolsetConfigs{
1236+
"firestore-database-tools": tools.ToolsetConfig{
1237+
Name: "firestore-database-tools",
1238+
ToolNames: []string{"firestore-get-documents", "firestore-list-collections", "firestore-delete-documents", "firestore-query-collection", "firestore-get-rules", "firestore-validate-rules"},
1239+
},
1240+
},
1241+
},
12311242
{
12321243
name: "postgres prebuilt tools",
12331244
in: postgresconfig,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: "Firestore"
3+
type: docs
4+
weight: 1
5+
description: >
6+
Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. It's a fully managed, serverless database that supports mobile, web, and server development.
7+
8+
---
9+
10+
# Firestore Source
11+
12+
[Firestore][firestore-docs] is a NoSQL document database built for automatic
13+
scaling, high performance, and ease of application development. While the
14+
Firestore interface has many of the same features as traditional databases,
15+
as a NoSQL database it differs from them in the way it describes relationships
16+
between data objects.
17+
18+
If you are new to Firestore, you can [create a database and learn the
19+
basics][firestore-quickstart].
20+
21+
[firestore-docs]: https://cloud.google.com/firestore/docs
22+
[firestore-quickstart]: https://cloud.google.com/firestore/docs/quickstart-servers
23+
24+
## Requirements
25+
26+
### IAM Permissions
27+
28+
Firestore uses [Identity and Access Management (IAM)][iam-overview] to control
29+
user and group access to Firestore resources. Toolbox will use your [Application
30+
Default Credentials (ADC)][adc] to authorize and authenticate when interacting
31+
with [Firestore][firestore-docs].
32+
33+
In addition to [setting the ADC for your server][set-adc], you need to ensure
34+
the IAM identity has been given the correct IAM permissions for accessing
35+
Firestore. Common roles include:
36+
- `roles/datastore.user` - Read and write access to Firestore
37+
- `roles/datastore.viewer` - Read-only access to Firestore
38+
39+
See [Firestore access control][firestore-iam] for more information on
40+
applying IAM permissions and roles to an identity.
41+
42+
[iam-overview]: https://cloud.google.com/firestore/docs/security/iam
43+
[adc]: https://cloud.google.com/docs/authentication#adc
44+
[set-adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc
45+
[firestore-iam]: https://cloud.google.com/firestore/docs/security/iam
46+
47+
### Database Selection
48+
49+
Firestore allows you to create multiple databases within a single project. Each
50+
database is isolated from the others and has its own set of documents and
51+
collections. If you don't specify a database in your configuration, the default
52+
database named `(default)` will be used.
53+
54+
## Example
55+
56+
```yaml
57+
sources:
58+
my-firestore-source:
59+
kind: "firestore"
60+
project: "my-project-id"
61+
# database: "my-database" # Optional, defaults to "(default)"
62+
```
63+
64+
## Reference
65+
66+
| **field** | **type** | **required** | **description** |
67+
|-----------|:--------:|:------------:|----------------------------------------------------------------------------------------------------------|
68+
| kind | string | true | Must be "firestore". |
69+
| project | string | true | Id of the GCP project that contains the Firestore database (e.g. "my-project-id"). |
70+
| database | string | false | Name of the Firestore database to connect to. Defaults to "(default)" if not specified. |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Firestore"
3+
type: docs
4+
weight: 1
5+
description: >
6+
Tools that work with Firestore Sources.
7+
---
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "firestore-delete-documents"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "firestore-delete-documents" tool deletes multiple documents from Firestore by their paths.
7+
aliases:
8+
- /resources/tools/firestore-delete-documents
9+
---
10+
11+
## About
12+
13+
A `firestore-delete-documents` tool deletes multiple documents from Firestore by their paths.
14+
It's compatible with the following sources:
15+
16+
- [firestore](../sources/firestore.md)
17+
18+
`firestore-delete-documents` takes one input parameter `documentPaths` which is an array of
19+
document paths to delete. The tool uses Firestore's BulkWriter for efficient batch deletion
20+
and returns the success status for each document.
21+
22+
## Example
23+
24+
```yaml
25+
tools:
26+
delete_user_documents:
27+
kind: firestore-delete-documents
28+
source: my-firestore-source
29+
description: Use this tool to delete multiple documents from Firestore.
30+
```
31+
32+
## Reference
33+
34+
| **field** | **type** | **required** | **description** |
35+
|-------------|:------------------------------------------:|:------------:|--------------------------------------------------------------------------------------------------|
36+
| kind | string | true | Must be "firestore-delete-documents". |
37+
| source | string | true | Name of the Firestore source to delete documents from. |
38+
| description | string | true | Description of the tool that is passed to the LLM. |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "firestore-get-documents"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "firestore-get-documents" tool retrieves multiple documents from Firestore by their paths.
7+
aliases:
8+
- /resources/tools/firestore-get-documents
9+
---
10+
11+
## About
12+
13+
A `firestore-get-documents` tool retrieves multiple documents from Firestore by their paths.
14+
It's compatible with the following sources:
15+
16+
- [firestore](../sources/firestore.md)
17+
18+
`firestore-get-documents` takes one input parameter `documentPaths` which is an array of
19+
document paths, and returns the documents' data along with metadata such as existence status,
20+
creation time, update time, and read time.
21+
22+
## Example
23+
24+
```yaml
25+
tools:
26+
get_user_documents:
27+
kind: firestore-get-documents
28+
source: my-firestore-source
29+
description: Use this tool to retrieve multiple documents from Firestore.
30+
```
31+
32+
## Reference
33+
34+
| **field** | **type** | **required** | **description** |
35+
|-------------|:------------------------------------------:|:------------:|--------------------------------------------------------------------------------------------------|
36+
| kind | string | true | Must be "firestore-get-documents". |
37+
| source | string | true | Name of the Firestore source to retrieve documents from. |
38+
| description | string | true | Description of the tool that is passed to the LLM. |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: "firestore-get-rules"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "firestore-get-rules" tool retrieves the active Firestore security rules for the current project.
7+
aliases:
8+
- /resources/tools/firestore-get-rules
9+
---
10+
11+
## About
12+
13+
A `firestore-get-rules` tool retrieves the active [Firestore security rules](https://firebase.google.com/docs/firestore/security/get-started) for the current project.
14+
It's compatible with the following sources:
15+
16+
- [firestore](../sources/firestore.md)
17+
18+
`firestore-get-rules` takes no input parameters and returns the security rules content along with metadata
19+
such as the ruleset name, and timestamps.
20+
21+
## Example
22+
23+
```yaml
24+
tools:
25+
get_firestore_rules:
26+
kind: firestore-get-rules
27+
source: my-firestore-source
28+
description: Use this tool to retrieve the active Firestore security rules.
29+
```
30+
31+
## Reference
32+
33+
| **field** | **type** | **required** | **description** |
34+
|-------------|:------------------------------------------:|:------------:|--------------------------------------------------------------------------------------------------|
35+
| kind | string | true | Must be "firestore-get-rules". |
36+
| source | string | true | Name of the Firestore source to retrieve rules from. |
37+
| description | string | true | Description of the tool that is passed to the LLM. |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "firestore-list-collections"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "firestore-list-collections" tool lists collections in Firestore, either at the root level or as subcollections of a document.
7+
aliases:
8+
- /resources/tools/firestore-list-collections
9+
---
10+
11+
## About
12+
13+
A `firestore-list-collections` tool lists [collections](https://firebase.google.com/docs/firestore/data-model#collections) in Firestore, either at the root level or as [subcollections](https://firebase.google.com/docs/firestore/data-model#subcollections) of a specific document.
14+
It's compatible with the following sources:
15+
16+
- [firestore](../sources/firestore.md)
17+
18+
`firestore-list-collections` takes an optional `parentPath` parameter to specify a document
19+
path. If provided, it lists all subcollections of that document. If not provided, it lists
20+
all root-level collections in the database.
21+
22+
## Example
23+
24+
```yaml
25+
tools:
26+
list_firestore_collections:
27+
kind: firestore-list-collections
28+
source: my-firestore-source
29+
description: Use this tool to list collections in Firestore.
30+
```
31+
32+
## Reference
33+
34+
| **field** | **type** | **required** | **description** |
35+
|-------------|:------------------------------------------:|:------------:|--------------------------------------------------------------------------------------------------|
36+
| kind | string | true | Must be "firestore-list-collections". |
37+
| source | string | true | Name of the Firestore source to list collections from. |
38+
| description | string | true | Description of the tool that is passed to the LLM. |

0 commit comments

Comments
 (0)