Skip to content

Commit 6428b76

Browse files
feat(tools/looker): tools to list/create/delete directories
within a LookML project. These tools only work on 26.2 and later.
1 parent 417806d commit 6428b76

File tree

15 files changed

+1152
-2
lines changed

15 files changed

+1152
-2
lines changed

cmd/internal/imports.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ import (
105105
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookeradddashboardelement"
106106
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookeradddashboardfilter"
107107
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookerconversationalanalytics"
108+
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookercreateprojectdirectory"
108109
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookercreateprojectfile"
110+
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookerdeleteprojectdirectory"
109111
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookerdeleteprojectfile"
110112
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookerdevmode"
111113
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergenerateembedurl"
@@ -122,6 +124,7 @@ import (
122124
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetmeasures"
123125
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetmodels"
124126
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetparameters"
127+
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetprojectdirectories"
125128
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetprojectfile"
126129
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetprojectfiles"
127130
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetprojects"

cmd/internal/tools_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ func TestPrebuiltTools(t *testing.T) {
17781778
wantToolset: server.ToolsetConfigs{
17791779
"looker_tools": tools.ToolsetConfig{
17801780
Name: "looker_tools",
1781-
ToolNames: []string{"get_models", "get_explores", "get_dimensions", "get_measures", "get_filters", "get_parameters", "query", "query_sql", "query_url", "get_looks", "run_look", "make_look", "get_dashboards", "run_dashboard", "make_dashboard", "add_dashboard_element", "add_dashboard_filter", "generate_embed_url", "health_pulse", "health_analyze", "health_vacuum", "dev_mode", "get_projects", "get_project_files", "get_project_file", "create_project_file", "update_project_file", "delete_project_file", "validate_project", "get_connections", "get_connection_schemas", "get_connection_databases", "get_connection_tables", "get_connection_table_columns"},
1781+
ToolNames: []string{"get_models", "get_explores", "get_dimensions", "get_measures", "get_filters", "get_parameters", "query", "query_sql", "query_url", "get_looks", "run_look", "make_look", "get_dashboards", "run_dashboard", "make_dashboard", "add_dashboard_element", "add_dashboard_filter", "generate_embed_url", "health_pulse", "health_analyze", "health_vacuum", "dev_mode", "get_projects", "get_project_files", "get_project_file", "create_project_file", "update_project_file", "delete_project_file", "get_project_directories", "create_project_directory", "delete_project_directory", "validate_project", "get_connections", "get_connection_schemas", "get_connection_databases", "get_connection_tables", "get_connection_table_columns"},
17821782
},
17831783
},
17841784
},

docs/en/reference/prebuilt-tools.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ See [Usage Examples](../reference/cli.md#examples).
543543
* `create_project_file`: Create a new LookML file.
544544
* `update_project_file`: Update an existing LookML file.
545545
* `delete_project_file`: Delete a LookML file.
546+
* `get_project_directories`: Retrieves a list of project directories for a given LookML project.
547+
* `create_project_directory`: Creates a new directory within a specified LookML project.
548+
* `delete_project_directory`: Deletes a directory from a specified LookML project.
546549
* `validate_project`: Check the syntax of a LookML project.
547550
* `get_connections`: Get the available connections in a Looker instance.
548551
* `get_connection_schemas`: Get the available schemas in a connection.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "looker-create-project-directory"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "looker-create-project-directory" tool creates a new directory in a LookML project.
7+
aliases:
8+
- /resources/tools/looker-create-project-directory
9+
---
10+
11+
## About
12+
13+
A `looker-create-project-directory` tool creates a new directory within a specified LookML project.
14+
15+
It's compatible with the following sources:
16+
17+
- [looker](../../sources/looker.md)
18+
19+
## Example
20+
21+
```yaml
22+
kind: tools
23+
name: looker-create-project-directory
24+
type: looker-create-project-directory
25+
source: looker-source
26+
description: |
27+
This tool creates a new directory within a specific LookML project.
28+
It is useful for organizing project files.
29+
30+
Parameters:
31+
- project_id (string): The ID of the LookML project.
32+
- directory_path (string): The path of the directory to create.
33+
34+
Output:
35+
A string confirming the creation of the directory.
36+
```
37+
38+
## Reference
39+
40+
| **field** | **type** | **required** | **description** |
41+
|-------------|:--------:|:------------:|----------------------------------------------------|
42+
| type | string | true | Must be "looker-create-project-directory". |
43+
| source | string | true | Name of the source Looker instance. |
44+
| description | string | true | Description of the tool that is passed to the LLM. |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "looker-delete-project-directory"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "looker-delete-project-directory" tool deletes a directory from a LookML project.
7+
aliases:
8+
- /resources/tools/looker-delete-project-directory
9+
---
10+
11+
## About
12+
13+
A `looker-delete-project-directory` tool deletes a directory from a specified LookML project.
14+
15+
It's compatible with the following sources:
16+
17+
- [looker](../../sources/looker.md)
18+
19+
## Example
20+
21+
```yaml
22+
kind: tools
23+
name: looker-delete-project-directory
24+
type: looker-delete-project-directory
25+
source: looker-source
26+
description: |
27+
This tool deletes a directory from a specific LookML project.
28+
It is useful for removing unnecessary or obsolete directories.
29+
30+
Parameters:
31+
- project_id (string): The ID of the LookML project.
32+
- directory_path (string): The path of the directory to delete.
33+
34+
Output:
35+
A string confirming the deletion of the directory.
36+
```
37+
38+
## Reference
39+
40+
| **field** | **type** | **required** | **description** |
41+
|-------------|:--------:|:------------:|----------------------------------------------------|
42+
| type | string | true | Must be "looker-delete-project-directory". |
43+
| source | string | true | Name of the source Looker instance. |
44+
| description | string | true | Description of the tool that is passed to the LLM. |
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "looker-get-project-directories"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "looker-get-project-directories" tool returns the directories within a specific LookML project.
7+
aliases:
8+
- /resources/tools/looker-get-project-directories
9+
---
10+
11+
## About
12+
13+
A `looker-get-project-directories` tool retrieves the directories within a specified LookML project.
14+
15+
It's compatible with the following sources:
16+
17+
- [looker](../../sources/looker.md)
18+
19+
## Example
20+
21+
```yaml
22+
kind: tools
23+
name: looker-get-project-directories
24+
type: looker-get-project-directories
25+
source: looker-source
26+
description: |
27+
This tool retrieves a list of directories within a specific LookML project.
28+
It is useful for exploring the project structure.
29+
30+
Parameters:
31+
- project_id (string): The ID of the LookML project.
32+
33+
Output:
34+
A JSON array of strings, representing the directories within the project.
35+
```
36+
37+
## Reference
38+
39+
| **field** | **type** | **required** | **description** |
40+
|-------------|:--------:|:------------:|----------------------------------------------------|
41+
| type | string | true | Must be "looker-get-project-directories". |
42+
| source | string | true | Name of the source Looker instance. |
43+
| description | string | true | Description of the tool that is passed to the LLM. |

internal/prebuiltconfigs/tools/looker.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,48 @@ tools:
959959
Output:
960960
A confirmation message upon successful file deletion.
961961
962+
get_project_directories:
963+
kind: looker-get-project-directories
964+
source: looker-source
965+
description: |
966+
This tool retrieves the list of directories within a specified LookML project.
967+
968+
Parameters:
969+
- project_id (required): The unique ID of the LookML project.
970+
971+
Output:
972+
A JSON array of strings, where each string is the name of a directory within the project.
973+
974+
create_project_directory:
975+
kind: looker-create-project-directory
976+
source: looker-source
977+
description: |
978+
This tool creates a new directory within a specified LookML project.
979+
980+
Prerequisite: The Looker session must be in Development Mode. Use `dev_mode: true` first.
981+
982+
Parameters:
983+
- project_id (required): The unique ID of the LookML project.
984+
- directory_path (required): The path to the new directory within the project.
985+
986+
Output:
987+
A confirmation message upon successful directory creation.
988+
989+
delete_project_directory:
990+
kind: looker-delete-project-directory
991+
source: looker-source
992+
description: |
993+
This tool permanently deletes a specified directory within a LookML project.
994+
995+
Prerequisite: The Looker session must be in Development Mode. Use `dev_mode: true` first.
996+
997+
Parameters:
998+
- project_id (required): The unique ID of the LookML project.
999+
- directory_path (required): The path to the directory within the project.
1000+
1001+
Output:
1002+
A confirmation message upon successful directory deletion.
1003+
9621004
validate_project:
9631005
kind: looker-validate-project
9641006
source: looker-source
@@ -1087,6 +1129,9 @@ toolsets:
10871129
- create_project_file
10881130
- update_project_file
10891131
- delete_project_file
1132+
- get_project_directories
1133+
- create_project_directory
1134+
- delete_project_directory
10901135
- validate_project
10911136
- get_connections
10921137
- get_connection_schemas

internal/tools/looker/lookercommon/lookercommon.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Google LLC
1+
// Copyright 2026 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -301,3 +301,32 @@ func UpdateProjectFile(l *v4.LookerSDK, projectId string, fileContent FileConten
301301
err := l.AuthSession.Do(nil, "PUT", "/4.0", path, nil, fileContent, options)
302302
return err
303303
}
304+
305+
func GetProjectDirectories(l *v4.LookerSDK, projectId string, options *rtl.ApiSettings) (string, error) {
306+
var result string
307+
path := fmt.Sprintf("/projects/%s/directories", url.PathEscape(projectId))
308+
err := l.AuthSession.Do(&result, "GET", "/4.0", path, nil, nil, options)
309+
return result, err
310+
}
311+
312+
type Directory struct {
313+
Path string `json:"path"`
314+
}
315+
316+
func CreateProjectDirectory(l *v4.LookerSDK, projectId string, directoryPath string, options *rtl.ApiSettings) error {
317+
d := Directory{
318+
Path: directoryPath,
319+
}
320+
var result string
321+
path := fmt.Sprintf("/projects/%s/directories", url.PathEscape(projectId))
322+
return l.AuthSession.Do(&result, "POST", "/4.0", path, nil, d, options)
323+
}
324+
325+
func DeleteProjectDirectory(l *v4.LookerSDK, projectId string, directoryPath string, options *rtl.ApiSettings) error {
326+
var query = map[string]any{
327+
"path": directoryPath,
328+
}
329+
var result string
330+
path := fmt.Sprintf("/projects/%s/directories", url.PathEscape(projectId))
331+
return l.AuthSession.Do(&result, "DELETE", "/4.0", path, query, nil, options)
332+
}

0 commit comments

Comments
 (0)