Visitar URL original
feat(looker): support running saved queries by query_id in query tool by pjmsmithgoogle · Pull Request #4220 · googleapis/mcp-toolbox · GitHub
Skip to content

feat(looker): support running saved queries by query_id in query tool - #4220

Open
pjmsmithgoogle wants to merge 4 commits into
googleapis:mainfrom
pjmsmithgoogle:feat-looker-query-by-id
Open

pjmsmithgoogle wants to merge 4 commits into
googleapis:mainfrom
pjmsmithgoogle:feat-looker-query-by-id

Conversation

@pjmsmithgoogle

@pjmsmithgoogle pjmsmithgoogle commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add support to the looker-query (query) tool for executing saved Looker queries by numeric ID or slug via an optional query_id parameter, alongside optional result_format (json or json_detail), vis_config, and generate_drill_links parameters:

  • When query_id is provided, model, explore, and fields are optional.
  • When filters or sorts overrides are supplied alongside query_id, fetch the base saved query via sdk.Query (with sdk.QueryForSlug fallback), merge filter/sort overrides into a v4.WriteQuery (BuildWriteQueryWithOverrides), escape unquoted parameter filters, and execute via RunInlineQueryWithDrillLinks.
  • When no overrides are supplied (or sorts match the base query), run the saved query directly via GET/POST /4.0/queries/{query_id}/run/{format} (RunSavedQueryWithDrillLinks), falling back to sdk.QueryForSlug + inline execution when a slug is passed.
  • Support result_format: "json_detail" (with optional StripDrillLinks when generate_drill_links=false) and vis_config pass-through for both saved and inline queries.
  • Extract human-readable error messages from Looker SDK HTTP JSON error payloads (ExtractLookerErrorMessage).

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #4221

@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 enhances the looker-query tool to support executing saved Looker queries by ID or slug (via query_id), in addition to running inline queries. It introduces new parameters (result_format, vis_config, and generate_drill_links), supports merging filter and sort overrides, and adds utility functions to strip drill links from json_detail responses and extract human-readable SDK error messages. Unit and integration tests have been updated accordingly. The review feedback suggests improving error handling by returning explicit validation errors instead of silently ignoring failures when parsing vis_config JSON or converting the sorts parameter.

Comment thread internal/tools/looker/lookerquery/lookerquery.go
Comment thread internal/tools/looker/lookerquery/lookerquery.go
@drstrangelooker

Copy link
Copy Markdown
Contributor

Can you rebase this on origin/main and resolve the conflicts?

Add support to the `looker-query` (`query`) tool for executing saved Looker queries by numeric ID or slug via an optional `query_id` parameter, alongside optional `result_format` (`json` or `json_detail`), `vis_config`, and `generate_drill_links` parameters:
- When `query_id` is provided, `model`, `explore`, and `fields` are optional.
- When `filters` or `sorts` overrides are supplied alongside `query_id`, fetch the base saved query via `sdk.Query` (with `sdk.QueryForSlug` fallback), merge filter/sort overrides into a `v4.WriteQuery` (`BuildWriteQueryWithOverrides`), escape unquoted parameter filters, and execute via `RunInlineQueryWithDrillLinks`.
- When no overrides are supplied (or `sorts` match the base query), run the saved query directly via `GET/POST /4.0/queries/{query_id}/run/{format}` (`RunSavedQueryWithDrillLinks`), falling back to `sdk.QueryForSlug` + inline execution when a slug is passed.
- Support `result_format: "json_detail"` (with optional `StripDrillLinks` when `generate_drill_links=false`) and `vis_config` pass-through for both saved and inline queries.
- Extract human-readable error messages from Looker SDK HTTP JSON error payloads (`ExtractLookerErrorMessage`).

---

- [x] **Statement of Origin:** I have read anderdstood the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). By submitting this pull request, I certify that I can make this contribution under the terms of the DCO.
- [x] **Code Style:** My code adheres to the style guidelines of this project.
- [x] **Self-Review:** I have performed a self-review of my own code.
- [x] **Comments:** I have commented my code, particularly in hard-to-understand areas.
- [x] **Documentation:** I have made corresponding changes to the documentation.
- [x] **No New Warnings:** My changes generate no new warnings.
- [x] **Tests:** I have added tests that prove my fix is effective or that my feature works.
- [x] **Passing Tests:** New and existing unit tests pass locally with my changes.
@pjmsmithgoogle
pjmsmithgoogle force-pushed the feat-looker-query-by-id branch from fbcebd4 to 1a5b6aa Compare October 8, 2026 00:17
@drstrangelooker

Copy link
Copy Markdown
Contributor

/gcbrun

@drstrangelooker drstrangelooker added the release candidate Use label to signal PR should be included in the next release. label Oct 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for running a saved query by query ID to the lookerquery tool

3 participants