Skip to main content
Glama

Openfda Count Values

openfda_count_values
Read-only

Aggregate and tally unique values for any field across any openFDA endpoint. Returns ranked term-count pairs sorted by count descending; a date field tallies one term per distinct YYYYMMDD date, ranked the same way. Pair with openfda_search_adverse_events, openfda_search_drug_approvals, openfda_search_device_clearances, openfda_search_recalls, openfda_get_drug_label, or openfda_lookup_ndc when sample records help interpret the aggregates.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "endpoint": "<endpoint>",
      "count": "<count>"
    },
    "name": "openfda_count_values"
  }
}

Input Schema

NameRequiredDescriptionDefault
countYesField to count. openfda_describe_fields gives the verified expression per field as countAs (null = not countable in any form). Otherwise: append .exact for whole-phrase counting of free-text fields (e.g. "patient.reaction.reactionmeddrapt.exact"); count identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) bare — .exact on those is rejected as not countable. A date field (receivedate, report_date, decision_date) is counted bare and yields one term per distinct YYYYMMDD date.
limitNoNumber of top terms to return. truncated reports whether more distinct terms exist beyond it, except at 1000 — openFDA's own count maximum — where openFDA offers no way to tell. A date field is the exception: openFDA sends every date, so the tool ranks them all and truncated is exact at any limit; scope search to at most limit dates to list each one. Default 100; a larger value returns at most 1000 and says so.
searchNoFilter query to scope the count (e.g. patient.drug.medicinalproduct:"metformin"). Omit to count across every record in the endpoint. A "+" between clauses reads as a space; inside a quoted phrase it is a literal plus.
endpointYesFull openFDA endpoint path (e.g. "drug/event", "device/classification")

Output Schema

NameRequiredDescriptionDefault
capNoThe limit applied to the term list.
metaNoResponse metadata
errorNoPresent when the call failed. Absent on success.
shownNoNumber of terms returned in this response.
noticeNoGuidance for this tally: why it is empty and how to widen it, how to reach terms past limit, the 1000-term maximum, count rows left out, limit clamp, SQL for AND-ed clauses on one array entry. Absent when nothing needs saying.
resultsNoTerm-count pairs sorted by count descending
termCountNoNumber of distinct terms returned
truncatedNoTrue when at least one more distinct term exists beyond the limit. Absent when the list is complete, and at the 1000-term maximum, where openFDA cannot show whether more exist (notice says so). Exact at any limit on a date field, where every date arrives.
truncationCeilingNoCount of the lowest-ranked term returned — omitted terms fall at or below it.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changed
    • changedInput schema / properties / endpoint / enum
      Previous value: -[
      -  "drug/event",
      -  "drug/label",
      -  "drug/enforcement",
      -  "drug/ndc",
      -  "drug/drugsfda",
      -  "drug/shortages",
      -  "food/event",
      -  "food/enforcement",
      -  "device/event",
      -  "device/510k",
      -  "device/pma",
      -  "device/recall",
      -  "device/enforcement",
      -  "device/classification",
      -  "device/registrationlisting",
      -  "device/udi",
      -  "device/covid19serology",
      -  "animalandveterinary/event",
      -  "tobacco/problem",
      -  "other/substance"
      -]New value: +[
      +  "drug/event",
      +  "drug/label",
      +  "drug/enforcement",
      +  "drug/ndc",
      +  "drug/drugsfda",
      +  "drug/orangebook",
      +  "drug/shortages",
      +  "food/event",
      +  "food/enforcement",
      +  "cosmetic/event",
      +  "device/event",
      +  "device/510k",
      +  "device/pma",
      +  "device/recall",
      +  "device/enforcement",
      +  "device/classification",
      +  "device/registrationlisting",
      +  "device/udi",
      +  "device/covid19serology",
      +  "animalandveterinary/event",
      +  "tobacco/problem",
      +  "other/substance",
      +  "other/nsde",
      +  "transparency/crl"
      +]
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. Separate clauses with spaces. A \"+\" written in the URL style of openFDA's examples also reads as a space where it separates: beside AND, OR, NOT, or TO, after a closing quote, paren, or bracket, or between a term and the next \"field:\" prefix (a:\"x\"+AND+b:\"y\", [20200101+TO+20201231], c:x+d:y). In a query that marks a clause required with a leading +field:, only the AND/OR/NOT/TO positions read that way. Any other \"+\" is sent as written, and inside a quoted phrase \"+\" is a literal plus sign. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request."New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. A \"+\" between clauses reads as a space; inside a quoted phrase it is a literal plus."
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, .exact on a field already indexed as a keyword, or a field with no countable form. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: search leaves a double quote, parenthesis, or range bracket unclosed, ends on a backslash, or holds a character openFDA refuses. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, .exact on a field already indexed as a keyword, or a field with no countable form. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / notice / description
      Previous value: -"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms (on a date field, how many distinct dates were counted); at the 1000-term maximum, that openFDA cannot show whether more distinct values exist; how many count rows openFDA sent without a value or numeric count, which are left out; when limit exceeded the 1000-term cap, the requested value and the cap applied. Absent when a complete list is returned at the requested limit."New value: +"Guidance for this tally: why it is empty and how to widen it, how to reach terms past limit, the 1000-term maximum, count rows left out, limit clamp, SQL for AND-ed clauses on one array entry. Absent when nothing needs saying."
  2. Changed4 schema fields changed
    • changedInput schema / properties / limit / description
      Previous value: -"Number of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell. A date field is the exception: openFDA sends every date, so the tool ranks them all and truncated is exact at any limit; scope search to at most limit dates to list each one."New value: +"Number of top terms to return. truncated reports whether more distinct terms exist beyond it, except at 1000 — openFDA's own count maximum — where openFDA offers no way to tell. A date field is the exception: openFDA sends every date, so the tool ranks them all and truncated is exact at any limit; scope search to at most limit dates to list each one. Default 100; a larger value returns at most 1000 and says so."
    • removedInput schema / properties / limit / maximum
      Removed value: -1000
    • changedInput schema / properties / limit / type
      Previous value: -"number"New value: +"integer"
    • changedOutput schema / properties / notice / description
      Previous value: -"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms (on a date field, how many distinct dates were counted); at the 1000-term maximum, that openFDA cannot show whether more distinct values exist; how many count rows openFDA sent without a value or numeric count, which are left out. Absent when a complete list is returned."New value: +"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms (on a date field, how many distinct dates were counted); at the 1000-term maximum, that openFDA cannot show whether more distinct values exist; how many count rows openFDA sent without a value or numeric count, which are left out; when limit exceeded the 1000-term cap, the requested value and the cap applied. Absent when a complete list is returned at the requested limit."
  3. Changed6 schema fields changed
    • changedInput schema / properties / count / description
      Previous value: -"Field to count. openfda_describe_fields gives the verified expression per field as countAs (null = not countable in any form). Otherwise: append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"); count identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) bare — .exact on those is rejected as not countable."New value: +"Field to count. openfda_describe_fields gives the verified expression per field as countAs (null = not countable in any form). Otherwise: append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"); count identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) bare — .exact on those is rejected as not countable. A date field (receivedate, report_date, decision_date) is counted bare and yields one term per distinct YYYYMMDD date."
    • changedInput schema / properties / limit / description
      Previous value: -"Number of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell."New value: +"Number of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell. A date field is the exception: openFDA sends every date, so the tool ranks them all and truncated is exact at any limit; scope search to at most limit dates to list each one."
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request."New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. Separate clauses with spaces. A \"+\" written in the URL style of openFDA's examples also reads as a space where it separates: beside AND, OR, NOT, or TO, after a closing quote, paren, or bracket, or between a term and the next \"field:\" prefix (a:\"x\"+AND+b:\"y\", [20200101+TO+20201231], c:x+d:y). In a query that marks a clause required with a leading +field:, only the AND/OR/NOT/TO positions read that way. Any other \"+\" is sent as written, and inside a quoted phrase \"+\" is a literal plus sign. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request."
    • changedOutput schema / properties / notice / description
      Previous value: -"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms; at the 1000-term maximum, that openFDA cannot show whether more distinct values exist. Absent when a complete list is returned."New value: +"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms (on a date field, how many distinct dates were counted); at the 1000-term maximum, that openFDA cannot show whether more distinct values exist; how many count rows openFDA sent without a value or numeric count, which are left out. Absent when a complete list is returned."
    • changedOutput schema / properties / results / items / properties / term / description
      Previous value: -"Field value"New value: +"Field value; on a date field, the date as YYYYMMDD"
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when at least one more distinct term exists beyond the limit. Absent when the list is complete, and at the 1000-term maximum, where openFDA cannot show whether more exist (notice says so)."New value: +"True when at least one more distinct term exists beyond the limit. Absent when the list is complete, and at the 1000-term maximum, where openFDA cannot show whether more exist (notice says so). Exact at any limit on a date field, where every date arrives."
  4. Changed5 schema fields changed
    • changedInput schema / properties / count / description
      Previous value: -"Field to count. Append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"). Identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) must be counted bare — .exact on those is rejected as not countable."New value: +"Field to count. openfda_describe_fields gives the verified expression per field as countAs (null = not countable in any form). Otherwise: append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"); count identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) bare — .exact on those is rejected as not countable."
    • changedInput schema / properties / limit / description
      Previous value: -"Number of top terms to return (default 100, max 1000)"New value: +"Number of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell."
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, or .exact on a field already indexed as a keyword. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, .exact on a field already indexed as a keyword, or a field with no countable form. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / notice / description
      Previous value: -"Guidance when no terms matched — how to verify the field name or adjust the count expression. Absent when terms are returned."New value: +"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms; at the 1000-term maximum, that openFDA cannot show whether more distinct values exist. Absent when a complete list is returned."
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when the term list was capped at the limit — more distinct terms may exist."New value: +"True when at least one more distinct term exists beyond the limit. Absent when the list is complete, and at the 1000-term maximum, where openFDA cannot show whether more exist (notice says so)."
  5. 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": [
      +      "meta",
      +      "results",
      +      "termCount"
      +    ]
      +  },
      +  {
      +    "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: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, or .exact on a field already indexed as a keyword. Other values are possible when a failure originates below the handler.",
      +          "examples": [
      +            "rate_limited",
      +            "upstream_error",
      +            "malformed_search",
      +            "query_error",
      +            "not_aggregatable"
      +          ],
      +          "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: -[
      -  "meta",
      -  "results",
      -  "termCount"
      -]
  6. Changed1 schema field changed
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint."New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request."
  7. Changed6 schema fields changed
    • changedInput schema / properties / count / description
      Previous value: -"Field to count. Append .exact for whole-phrase counting (e.g. \"patient.reaction.reactionmeddrapt.exact\", \"openfda.brand_name.exact\")"New value: +"Field to count. Append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"). Identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) must be counted bare — .exact on those is rejected as not countable."
    • addedInput schema / properties / count / minLength
      Added value: +1
    • addedInput schema / properties / count / pattern
      Added value: +"\\S"
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\")"New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint."
    • addedInput schema / properties / search / minLength
      Added value: +1
    • addedInput schema / properties / search / pattern
      Added value: +"\\S"
  8. Changed4 schema fields changed
    • addedOutput schema / properties / cap
      Added value: +{
      +  "description": "The limit applied to the term list.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / shown
      Added value: +{
      +  "description": "Number of terms returned in this response.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / truncated
      Added value: +{
      +  "description": "True when the term list was capped at the limit — more distinct terms may exist.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / truncationCeiling
      Added value: +{
      +  "description": "Count of the lowest-ranked term returned — omitted terms fall at or below it.",
      +  "type": "number"
      +}
  9. Added

TDQS

A4.1/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, so the safety profile is covered; the description adds material behavior beyond that: results are sorted count-descending, date fields tally one term per distinct YYYYMMDD, and truncation is reported — except at limit 1000 where openFDA itself cannot signal truncation. That truncation caveat is genuinely useful and not derivable from annotations.

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?

Three sentences, front-loaded with purpose and output shape, followed by behavior and then the pairing guidance. Dense but every clause carries information; the final sibling list is long but functional rather than filler.

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

Completeness4/5

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

With an output schema, full parameter coverage, and readOnlyHint present, the description is nearly complete — it covers aggregation semantics, sorting, date handling, and truncation limits. Only a clearer statement of when this is preferred over sibling search/dataframe tools is missing.

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

Parameters3/5

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

Schema description coverage is 100%, including detailed guidance on .exact vs bare keyword counting and the date-field case, so the description's job here is largely redundant. The schema already carries the count/limit/search/endpoint semantics, so baseline 3 applies with no meaningful added meaning in the description text.

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+resource: "Aggregate and tally unique values for any field across any openFDA endpoint," and immediately clarifies the output shape (ranked term-count pairs, descending). This distinguishes it from the openfda_search_* siblings, which return sample records rather than aggregates.

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?

Explicitly tells the agent to pair this with openfda_search_adverse_events / search_drug_approvals / get_drug_label / lookup_ndc "when sample records help interpret the aggregates," which gives real context for combined use. It stops short of stating when to prefer the dataframe or describe_fields tools instead, so it lacks a full when-not/alternative map.

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.