code_mode
Process US government data tool outputs with JavaScript to extract specific fields, counts, or filters, reducing response size by focusing only on needed information.
Instructions
Run a JavaScript processing script against any tool's output in a WASM sandbox.
Calls the specified tool first, then runs your script with the raw response as DATA (string).
Only your script's console.log() output enters context — typically 65-99% smaller.
USE THIS when you need specific fields, counts, or filters from a large response. DO NOT use this when you need to read and interpret the full data for cross-referencing or analysis.
The script can: JSON.parse(DATA), use loops/map/filter/reduce, Math, string ops, console.log(). The script CANNOT: access files, network, Node.js APIs, or import modules.
Example — count serious reactions for a drug: tool='fda_drug_events', tool_args={"search":"patient.drug.openfda.brand_name:aspirin","limit":100}, code='const d=JSON.parse(DATA);const data=d.data||d;const items=data.items||data.results||[];' + 'const counts={};items.forEach(r=>{const rxs=r.reactions||[];rxs.forEach(rx=>{counts[rx]=(counts[rx]||0)+1})});' + 'Object.entries(counts).sort((a,b)=>b[1]-a[1]).slice(0,10).forEach(([k,v])=>console.log(k+": "+v))'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tool | Yes | Name of the MCP tool to call (e.g. 'fda_drug_events', 'fred_series_data', 'congress_search_bills') | |
| tool_args | No | Arguments to pass to the tool, as a JSON object (e.g. {"search": "serious:1", "limit": 50}) | |
| code | Yes | JavaScript code to process the result. The tool's full response is available as DATA (string). Use JSON.parse(DATA) to parse it. Use console.log() to produce output. Only console.log output is returned — keep it concise. |