Search results

Reference

The result envelope that every search tool returns: the award page, counts, paging fields, the cap flag, per-page aggregates and the paging hint text.

Status
stable
Trust tier
unverified
Generated
claude-code/claude-opus-5-5, 2026-12-05
Tags
searchpagingresultsoutput-schema

The three search tools, search_nsf_awards, search_by_institution and search_by_pi, all return the same envelope. buildSearchOutput in src/tools/shared.ts builds it, and SearchOutputSchema in src/types/mcp-tools.types.ts declares it as the tools’ output schema.1 2 The envelope holds one page of award records, the total match count, the paging state, a flag for the API’s 10,000-match cap, and aggregates over the page, plus a one-line paging hint.

Use this page to read a search result and to page through a long one. The request side of paging (offset, limit, detail, printFields, status) is in Shared search parameters. The fields of each record in awards are in Award record.

Result layout

Every successful tool call returns the data twice: as structuredContent, and as compact JSON text (JSON.stringify(data)) in the first content item. Search results carry a paging hint in the envelope’s hint field and repeat it as a second text item, for clients that show only text.3 1 The hint is in the envelope too because some clients, Claude Code among them, pass only the structured content or the first content block to the model, so a hint only in content[1] never reached it.3

Part Content
structuredContent The envelope object. The client validates it against SearchOutputSchema.
content[0] { "type": "text", "text": "<the envelope as JSON>" }
content[1] { "type": "text", "text": "<paging hint>" }, the same text as hint (see Paging hint)

toCallToolResult adds the second block only when the data has a string hint, which only buildSearchOutput sets, so the two lookup tools never get one.3 4 A failed call has neither structuredContent nor a hint; see Errors.

Schema

Field Type Meaning
awards array of award records The records on this page, in API order. Summary records by default; full records without the outcomes report and publications with detail: "full"; a projection with printFields.
totalResults integer Total matching awards. The API caps this at 10000. For search_by_pi with includeCoPIs, the size of the merged, de-duplicated list, counting only awards that name the person as PI or Co-PI.
offset integer The offset of the request (default 0).
limit integer The limit of the request (default 25).
returned integer Number of records in awards. Can be lower than limit on the last page or near the cap.
hasMore boolean true when another page can be fetched.
nextOffset integer, optional Present only when hasMore is true: offset + returned. Pass it as offset for the next page.
capped boolean true when totalResults is 10000 or more, which means the API stopped counting. Narrow the search to reach the rest.
pageSummary object Aggregates over this page only: totalEstimatedAmt, byInstitution, byProgram.
hint string, optional One-line paging guidance for this result; see Paging hint. Every search result has it.

Field list from buildSearchOutput and SearchOutputSchema.1 2 buildSearchOutput emits the fields in the order awards, totalResults, offset, returned, hasMore, nextOffset (when present), capped, limit, pageSummary, hint; content[0] keeps that order.1

pageSummary

Field Type Meaning
totalEstimatedAmt number Sum of estimatedTotalAmt over the awards on this page, in US dollars. An award without an amount counts as 0.
byInstitution object of counts Number of awards on this page per institution. The key is awardeeName, else awardee, else Unknown.
byProgram object of counts Number of awards on this page per funding program. The key is fundProgramName, else Unknown.

The aggregates are computed from the full normalized records before they are shaped, so they are present even when printFields leaves out the fields they are based on. They cover the page, not the whole result set.1 2

How the paging fields are computed

  • totalResults is response.metadata.totalCount from the API. If the API sends no count, the client uses offset + returned instead.5
  • hasMore is true only when all three hold:1 5
    1. The upstream page reports more: offset + returned < min(totalCount, 10000). Without a count, the page was full (returned equals the page size requested).
    2. The page is not empty.
    3. offset + returned is below 10000.
  • nextOffset is offset + returned, and only appears with hasMore.1
  • capped is totalResults >= 10000.1
  • Pages near the cap. The API answers a request with offset + rpp > 10000 with no records and a FATAL notification (AwardAPI-004). The client therefore shortens such a page to end at record 10000, so offset: 9990 returns the last 10 records instead of an error. The schema stops offset at 9999.5 6 2 See Paging and limits.

For search_by_pi with includeCoPIs, the server fetches both searches in full, merges them, drops duplicates and awards that do not name the person, sorts them by start date (newest first, ties broken by award id, descending), and slices the page itself. Then totalResults is the merged count, hasMore is offset + returned < totalResults, and capped is never true because each side is limited to 250 matches.7 See search_by_pi.

Paging hint

pagingHint in src/tools/shared.ts builds the hint from three parts. buildSearchOutput stores it as hint, and toCallToolResult repeats it as content[1]. src/server.ts re-exports pagingHint.1 3

Showing <returned> of <total> matching awards (offset <offset>).
  • <total> is totalResults, or 10000+ when capped is true.
  • When hasMore is true and nextOffset is present, it appends ` More results are available: call again with offset=.`
  • When capped is true, it appends ` The NSF API caps counts and paging at 10,000; narrow the search to reach the rest.`

The tests pin these outputs:4

Showing 3 of 981 matching awards (offset 0). More results are available: call again with offset=3.
Showing 6 of 31 matching awards (offset 25).
Showing 25 of 10000+ matching awards (offset 50). More results are available: call again with offset=75. The NSF API caps counts and paging at 10,000; narrow the search to reach the rest.

Paging through results

  1. Call the search with offset 0 (the default).
  2. While hasMore is true, call again with the same arguments and offset set to nextOffset.
  3. When capped is true, stop and narrow the search (a keyword, state or date range); the API serves no record past number 10,000.8

The API orders results by startDate, newest first, but the order of awards with equal start dates is not stable between calls. A page boundary may therefore repeat or skip an award.6 3 The includeCoPIs merge does not have this problem, because the server sorts it with an id tie-breaker.7

Output schema validation

SearchOutputSchema declares exact types for the envelope fields (integers for the counts), but each award record uses AwardRecordSchema, a loose object whose fields are mostly optional. A record with unexpected extra fields passes. A record whose known field has the wrong type, such as a string amount, fails validation and the call becomes an isError result with an Output validation error message.2 4 See Award record and Errors.

Examples

A search_nsf_awards call with keyword: "wildfire" and limit: 3, built from the trimmed live fixture (people replaced by placeholders and the Co-PI list shortened; the other two records abbreviated):9 4

{
  "awards": [
    {
      "id": "2535052",
      "title": "EPSCoR Graduate Fellowship Program (EGFP): Graduate fellowships to propel wildfire research in Montana",
      "pdPIName": "First Last",
      "coPDPI": ["First M Last", "First Last"],
      "awardeeName": "University of Montana",
      "awardeeCity": "MISSOULA",
      "awardeeStateCode": "MT",
      "startDate": "03/15/2027",
      "expDate": "02/28/2030",
      "estimatedTotalAmt": 1113000,
      "fundsObligatedAmt": 1113000,
      "fundProgramName": "EGF-EPSCoR Graduate Fellowship",
      "dirAbbr": "EDU",
      "divAbbr": "SFT",
      "transType": "Standard Grant",
      "activeAwd": true,
      "hasOutcomesReport": false
    },
    { "id": "2623880", "...": "..." },
    { "id": "2539349", "...": "..." }
  ],
  "totalResults": 981,
  "offset": 0,
  "returned": 3,
  "hasMore": true,
  "nextOffset": 3,
  "capped": false,
  "limit": 3,
  "pageSummary": {
    "totalEstimatedAmt": 2207849,
    "byInstitution": {
      "University of Montana": 1,
      "University of Wyoming": 1,
      "Boise State University": 1
    },
    "byProgram": {
      "EGF-EPSCoR Graduate Fellowship": 1,
      "Fire Science Innovations": 1,
      "WaLCZ-Water, Land, & Crit Zone": 1
    }
  },
  "hint": "Showing 3 of 981 matching awards (offset 0). More results are available: call again with offset=3."
}

The paging hint for this result, in hint and in content[1]:

Showing 3 of 981 matching awards (offset 0). More results are available: call again with offset=3.
  1. Shared tool helpers, buildSearchOutput and pagingHint ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9

  2. Tool input and output schemas ↩ ↩2 ↩3 ↩4 ↩5

  3. MCP server factory and toCallToolResult ↩ ↩2 ↩3 ↩4 ↩5

  4. In-process MCP protocol tests ↩ ↩2 ↩3 ↩4

  5. NSF Award API client ↩ ↩2 ↩3

  6. Live API behaviour notes in CLAUDE.md ↩ ↩2

  7. search_by_pi tool handler ↩ ↩2

  8. User guide ↩

  9. Trimmed live search page for keyword=wildfire ↩

Sources

  1. Shared tool helpers, buildSearchOutput and pagingHint shared-source
  2. MCP server factory and toCallToolResult server-source
  3. Tool input and output schemas tool-schema
  4. NSF Award API client api-client
  5. search_by_pi tool handler search-by-pi-source
  6. In-process MCP protocol tests server-tests
  7. Trimmed live search page for keyword=wildfire wildfire-fixture
  8. User guide usage-guide
  9. Live API behaviour notes in CLAUDE.md api-behaviour