---
title: "Call site.database.query"
method: POST
path: "/api/v1/tools/site.database.query"
tags: ["site"]
---

# Call site.database.query

`POST /api/v1/tools/site.database.query`

## Request

- Base URL: `https://app.goosybear.ai`
- URL: `https://app.goosybear.ai/api/v1/tools/site.database.query`
- Auth: HTTP bearer

Look inside a site's own database — 'what's in my site's database?', 'how many bookings are stored?', 'show me the products the site has'.  Read this site's own database with one read-only SQL statement. It is the site's whole schema — the same database the site's own code reads as env.DB — so start with `select name from sqlite_master where type='table'` if you do not know it. Put every value in `params` as a ? placeholder. The statement must start with select, with, explain, or pragma table_info / table_list and carry no semicolon: this tool REFUSES anything that could change data or schema. Not for changing data or schema — that is `site.database.execute`.

Every result names the workspace it ran in. Say which workspace the answer is about. When the account has more than one workspace and none is selected, this tool refuses with `workspace_ambiguous` and lists the choices — offer them, never pick one.

## Headers

- `x-request-id` string

## Request body

- object
  - `site_id` string, uuid, required: The site, as a UUID. Take it from page.list or from the conversation's context — never invent one.
  - `sql` string, required: ONE read-only SQL statement for this site's own SQLite (D1) database. It must start with select, with, explain, or pragma table_info / pragma table_list, carry no semicolon, and change nothing — anything that inserts, updates, deletes, replaces, creates, drops, alters or attaches is refused here; site.database.execute is the door for those. Put every value in `params` as a ? placeholder. Use `select name from sqlite_master where type='table'` first if you do not know the schema.
  - `params` string[]: The values for the ? placeholders, in order. Always strings — SQLite converts them.
  - `workspace` string: Which workspace to run in — its slug. Omit to use your default. With more than one reachable workspace and no default, the call is refused and the choices are listed.

## Response `200`

The call was admitted and dispatched. `ok` says whether the tool succeeded — a refusal the tool itself produced is still a 200, exactly as it is a successful JSON-RPC result over MCP.

- union
  - object: The tool ran and answered.
    - `ok` true, required
    - `site_id` string, uuid, required
    - `rows` object[], required
    - `row_count` integer, required
    - `truncated` boolean, required
    - `rows_read` integer, required
    - `workspace` string, required: The slug of the workspace this call ran in.
    - `working_in` object, required: Which workspace this call ran in, and how that was decided. Present on every workspace-scoped result.
      - `label` string, required: The chip words — e.g. "working in: Acme Main".
      - `note` string, required: Why this workspace — e.g. "your default", "this call only".
      - `workspace` string, required: The resolved workspace's slug.
      - `source` 'call-override' | 'key-pin' | 'stored-default' | 'sole-reachable', required: Which rung of the R7 precedence resolved the workspace.
  - ToolRefusal: A call that was admitted and dispatched, and did not succeed.
    - `ok` false, required
    - `code` string, required: The typed reason — e.g. `workspace_ambiguous`, `invalid_arguments`, or the tool's own failure code.
    - `message` string, required: A sentence a person can act on.
    - `workspaces` string[]: On a workspace refusal: the slugs this key may pass as `workspace`.
    - `issues` object[]: On `invalid_arguments`: which fields failed, and why.
      - `path` string, required
      - `message` string, required
    - `path` string: On an authoring refusal: where in your call's input it points, e.g. `steps.<key>.params.<field>`.
    - `fix` string: On an authoring refusal: the change to your call that would pass.
    - `instruction` string: On an authoring refusal: what to do next with it.

## Other responses

- `400`: The request could not be used: the body is present but not a JSON object (`tenant_api.malformed_body`); it is a top-level array carrying more messages than this endpoint accepts (`tenant_mcp.batch_too_large`); or the `Idempotency-Key` header is malformed (`tenant_api.idempotency_key_invalid`), disagrees with the body's `idempotency_key` (`tenant_api.idempotency_key_conflict`), or was sent to an action that cannot replay a retry (`tenant_api.idempotency_unsupported`). Nothing ran.
- `401`: No bearer credential, or one that did not resolve. Deliberately ONE undifferentiated answer for absent / unknown / revoked / expired, so the endpoint is never an oracle over the key space.
- `403`: The credential is good but the surface is not open to it — the platform or account API switch is off, or the holder lacks the `api.access` capability. The `code` says which.
- `404`: No such tool. The body names no tool and is identical for every unrecognised name.
- `429`: Over this key's per-minute cap. Carries `Retry-After` and `error.retry_after_seconds`.

---

[API](https://skmtc.dev/goosybear/apis/goosy-bear-api.md) · [All operations](https://skmtc.dev/goosybear/apis/goosy-bear-api/llms.txt) · [OpenAPI document](https://skmtc.dev/goosybear/apis/goosy-bear-api/revisions/6d82fb124064?raw)
