Skip to main content
Glama

Openfda Dataframe Query

openfda_dataframe_query
Read-onlyIdempotent

Run a read-only SQL SELECT against a DataCanvas table staged by an openFDA search tool (call one with stage=true; its response carries canvas_id + canvas_table). Enables GROUP BY, COUNT/SUM/AVG, time-series, and joins across the staged result set without re-paging the API. Call openfda_dataframe_describe first to get the exact table and column names. Results are capped at the canvas row limit — when truncated is true, page the rest with ORDER BY plus LIMIT/OFFSET. Scalar fields are stored as text (CAST for numeric math); nested objects/arrays are JSON columns — read them with DuckDB json functions, e.g. json_extract_string(openfda, '$.brand_name[0]'). Only SELECT is allowed — DDL, DML, COPY, and file-reading functions are blocked.

Input Schema

NameRequiredDescriptionDefault
queryYesSQL SELECT against the staged table. Use the table name from openfda_dataframe_describe. Example: "SELECT classification, COUNT(*) AS n FROM spilled_ab12cd34 GROUP BY classification ORDER BY n DESC".
canvas_idYesCanvas ID from the canvas_id field of an openFDA search tool response (openfda_search_* or openfda_lookup_ndc), present when the search ran with stage=true.

Output Schema

NameRequiredDescriptionDefault
rowsNoRows returned by the query (capped at the canvas row limit).
errorNoPresent when the call failed. Absent on success.
canvas_idNoCanvas ID that was queried — reuse for follow-up queries.
row_countNoNumber of rows in this response. Equals the canvas row limit when truncated is true.
truncatedNoTrue when the result hit the canvas row limit and rows beyond it were dropped. Page the rest with ORDER BY plus LIMIT/OFFSET.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, uses a blocked operation, or fails on a staged value (a CAST that does not convert). Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE=none. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, uses a blocked operation, or fails on a staged value (a CAST that does not convert). Other values are possible when a failure originates below the handler."
  2. Changed4 schema fields changed
    • changedInput schema / properties / canvas_id / description
      Previous value: -"Canvas ID from an openFDA search tool response (the canvas_id field, present when the search ran with stage=true)."New value: +"Canvas ID from the canvas_id field of an openFDA search tool response (openfda_search_* or openfda_lookup_ndc), present when the search ran with stage=true."
    • removedInput schema / properties / canvas_id / minLength
      Removed value: -1
    • changedInput schema / properties / canvas_id / pattern
      Previous value: -"\\S"New value: +"^[A-Za-z0-9_-]{10}$"
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, or uses a blocked operation. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, uses a blocked operation, or fails on a staged value (a CAST that does not convert). Other values are possible when a failure originates below the handler."
  3. Changed6 schema fields changed
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedInput schema / additionalProperties
      Added value: +false
    • changedOutput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedOutput schema / anyOf
      Added value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "rows",
      +      "row_count",
      +      "truncated",
      +      "canvas_id"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / error
      Added value: +{
      +  "additionalProperties": {},
      +  "description": "Present when the call failed. Absent on success.",
      +  "properties": {
      +    "code": {
      +      "description": "JSON-RPC error code for this failure.",
      +      "maximum": 9007199254740991,
      +      "minimum": -9007199254740991,
      +      "type": "integer"
      +    },
      +    "data": {
      +      "additionalProperties": {},
      +      "properties": {
      +        "reason": {
      +          "description": "Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, or uses a blocked operation. Other values are possible when a failure originates below the handler.",
      +          "examples": [
      +            "canvas_disabled",
      +            "canvas_not_found",
      +            "missing_table",
      +            "invalid_query"
      +          ],
      +          "type": "string"
      +        },
      +        "recovery": {
      +          "additionalProperties": {},
      +          "description": "Actionable next step for the caller.",
      +          "properties": {
      +            "hint": {
      +              "type": "string"
      +            }
      +          },
      +          "required": [
      +            "hint"
      +          ],
      +          "type": "object"
      +        },
      +        "retryable": {
      +          "description": "Whether retrying may succeed.",
      +          "type": "boolean"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "message": {
      +      "description": "Human-readable description of what went wrong.",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "code",
      +    "message"
      +  ],
      +  "type": "object"
      +}
    • removedOutput schema / required
      Removed value: -[
      -  "rows",
      -  "row_count",
      -  "truncated",
      -  "canvas_id"
      -]
  4. Changed4 schema fields changed
    • changedInput schema / properties / canvas_id / description
      Previous value: -"Canvas ID from an openFDA search tool response (the canvas_id field)."New value: +"Canvas ID from an openFDA search tool response (the canvas_id field, present when the search ran with stage=true)."
    • changedOutput schema / properties / row_count / description
      Previous value: -"Number of rows in this response."New value: +"Number of rows in this response. Equals the canvas row limit when truncated is true."
    • addedOutput schema / properties / truncated
      Added value: +{
      +  "description": "True when the result hit the canvas row limit and rows beyond it were dropped. Page the rest with ORDER BY plus LIMIT/OFFSET.",
      +  "type": "boolean"
      +}
    • changedOutput schema / required
      Previous value: -[
      -  "rows",
      -  "row_count",
      -  "canvas_id"
      -]New value: +[
      +  "rows",
      +  "row_count",
      +  "truncated",
      +  "canvas_id"
      +]
  5. Changed4 schema fields changed
    • addedInput schema / properties / canvas_id / minLength
      Added value: +1
    • addedInput schema / properties / canvas_id / pattern
      Added value: +"\\S"
    • addedInput schema / properties / query / minLength
      Added value: +1
    • addedInput schema / properties / query / pattern
      Added value: +"\\S"
  6. Added

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond readOnlyHint/idempotentHint: declares the only-SELECT restriction with blocked statement classes (DDL, DML, COPY, file readers), the canvas row cap and truncation behavior, text-vs-JSON column typing, and the DuckDB json_extract_string idiom. This is exactly the mutation/safety context the annotations cannot express.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core action, then prerequisite, then limits and typing caveats – a logical order. It is dense (a single long paragraph with several distinct rules) but nearly every sentence adds actionable information; splitting into bullets would aid scanning without cutting content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return values needn't be explained, and the description covers everything else an agent needs: entry conditions, ordering of calls, row caps, pagination, type coercion, and dialect-specific query constraints. Nothing material for correct invocation is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3; the description adds real value by tying canvas_id to a staged search response and warning that query must use the describe-supplied table name, plus CAST guidance for text scalars. The JSON-extraction example further clarifies how to query nested columns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: run a read-only SQL SELECT against a DataCanvas table staged by an openFDA search tool. It situates the tool precisely in the workflow (stage=true -> canvas_id/canvas_table) so an agent can tell it apart from the search/describe siblings without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit prerequisites (a prior search with stage=true, and openfda_dataframe_describe first for table/column names) and operational guidance for truncated results (ORDER BY + LIMIT/OFFSET). It does not explicitly compare against the openfda_count_values sibling, so aggregation-vs-simple-count selection is left implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.