eia-energy-mcp-server
Browse and query the EIA API v2 — electricity, petroleum, natural gas, coal, forecasts via MCP.
我该使用它吗
质量与安全性
发现(1)
- LOW在 eia_browse_routes 中
基于对工具定义和协议合规性的自动分析。
上下文开销
这是每次将服务器的工具加载到模型上下文窗口时所消耗的大致 token 数。数值越高,可用于其他任务的注意力就越少。
安装
一键安装
将以下内容添加到你的 `claude_desktop_config.json` 文件中:
{
"mcpServers": {
"eia-energy-mcp-server": {
"command": "bun",
"args": [
"@cyanheads/eia-energy-mcp-server"
]
}
}
}可运行的软件包
0.4.2streamable-http远程端点
https://eia-energy.caseyjhand.com/mcpstreamable-http它能做什么
工具清单
工具(6)
🟢eia_browse_routes(path)
Lists child routes under a given path in the EIA dataset taxonomy. Start with no path to get the 14 top-level categories (electricity, petroleum, natural-gas, steo, aeo, ieo, seds, etc.), then drill into subcategories. Each result includes an isLeaf flag — leaf routes are queryable endpoints; non-leaf routes have children to browse. When isLeaf is true on the browsed path itself, switch to eia_describe_route.
输入模式
{
"type": "object",
"properties": {
"path": {
"description": "Route path to browse (e.g. \"electricity\", \"petroleum/pri\"). Omit for root. Leading, trailing, and doubled slashes are stripped, so an EIA-doc spelling like \"/electricity/retail-sales/\" resolves to the same route.",
"type": "string"
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "The path that was browsed (empty string for root)."
},
"children": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Route segment ID."
},
"name": {
"type": "string",
"description": "Human-readable name."
},
"description": {
"type": "string",
"description": "Route description."
},
"route": {
"type": "string",
"description": "Full route path usable in eia_describe_route or eia_query_route."
},
"isLeaf": {
"type": "boolean",
"description": "True when this child is a queryable leaf route with data."
}
},
"required": [
"id",
"name",
"description",
"route",
"isLeaf"
],
"additionalProperties": false,
"description": "A child route entry."
},
"description": "Child entries under the browsed path."
},
"isLeaf": {
"type": "boolean",
"description": "True when the browsed path itself is a leaf route — no children to drill into; use eia_describe_route instead."
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `route_not_found`: Path does not exist in the EIA taxonomy. Other values are possible when a failure originates below the handler.",
"examples": [
"route_not_found"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"path",
"children",
"isLeaf"
]
},
{
"required": [
"error"
]
}
]
}🟢eia_describe_route(route, facet, values_offset)
Returns metadata for a leaf route: available facets with their valid values, data column names and units, frequency options, and date range. Call this before eia_query_route to discover valid facet IDs, facet values, column IDs, and frequency codes. Each facet returns a capped window of its values with value_count and values_truncated alongside; pass facet and values_offset to page through the rest of one facet. A values_offset past the last value of a facet returns an empty window for it and a notice naming the count to page against. Facet values are fetched from separate EIA endpoints and merged — results are cached per-route for the process lifetime to minimize API calls.
输入模式
{
"type": "object",
"properties": {
"route": {
"type": "string",
"minLength": 1,
"description": "Leaf route path (e.g. \"electricity/retail-sales\", \"steo\"). Discoverable via eia_browse_routes or eia_search_routes. Leading, trailing, and doubled slashes are stripped, so an EIA-doc spelling like \"/electricity/retail-sales/\" resolves to the same route."
},
"facet": {
"description": "Restrict the response to one facet by ID (e.g. \"stateid\"). Use with values_offset to page a facet whose values were truncated. Omit to get every facet.",
"type": "string",
"minLength": 1
},
"values_offset": {
"default": 0,
"description": "Index of the first facet value to return, applied to every facet in the response. Use the value named in a truncation hint to continue past the cap.",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"route"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"route": {
"type": "string",
"description": "The route path described."
},
"description": {
"type": "string",
"description": "Human-readable description of the dataset."
},
"facets": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Facet ID — use as key in the filters parameter of eia_query_route (e.g. filters: { \"stateid\": \"TX\" })."
},
"description": {
"type": "string",
"description": "Facet description."
},
"values": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Facet value ID — use as filter value."
},
"name": {
"type": "string",
"description": "Human-readable name. Falls back to the alias, then to the id, on the values EIA sends without one."
},
"alias": {
"description": "Short alias, when provided by EIA.",
"type": "string"
}
},
"required": [
"id",
"name"
],
"additionalProperties": false,
"description": "A valid facet value."
},
"description": "Valid values for this facet dimension, starting at values_offset and capped at EIA_FACET_VALUE_CAP."
},
"value_count": {
"type": "number",
"description": "Total values this facet has upstream, independent of the returned window."
},
"values_truncated": {
"type": "boolean",
"description": "True when values stops short of value_count. Call eia_describe_route again with this facet ID and values_offset set to values_offset + values.length for the next page."
}
},
"required": [
"id",
"description",
"values",
"value_count",
"values_truncated"
],
"additionalProperties": false,
"description": "A filterable dimension for this route."
},
"description": "Filterable dimensions. Each facet has an ID and a window of its valid values. Restricted to one entry when the facet input is set."
},
"values_offset": {
"type": "number",
"description": "Index of the first facet value returned, echoing the requested offset."
},
"data_columns": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Column ID — use in the columns parameter of eia_query_route."
},
"alias": {
"type": "string",
"description": "Human-readable column alias."
},
"units": {
"type": "string",
"description": "Measurement units (e.g. \"cents per kilowatt-hour\")."
}
},
"required": [
"id",
"alias",
"units"
],
"additionalProperties": false,
"description": "A data column available for this route."
},
"description": "Data columns available for this route."
},
"frequencies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Frequency ID (e.g. \"monthly\", \"annual\")."
},
"description": {
"type": "string",
"description": "Human-readable description."
},
"query": {
"type": "string",
"description": "API query value for this frequency."
},
"format": {
"type": "string",
"description": "Period format string (e.g. \"YYYY-MM\", \"YYYY\")."
}
},
"required": [
"id",
"description",
"query",
"format"
],
"additionalProperties": false,
"description": "A frequency option for eia_query_route."
},
"description": "Valid frequency options for eia_query_route."
},
"date_range": {
"type": "object",
"properties": {
"start": {
"type": "string",
"description": "Earliest available period."
},
"end": {
"type": "string",
"description": "Latest available period."
}
},
"required": [
"start",
"end"
],
"additionalProperties": false,
"description": "Available date range for this route."
},
"default_frequency": {
"type": "string",
"description": "Default frequency ID used when none is specified."
},
"default_date_format": {
"type": "string",
"description": "Period format for the default frequency (e.g. \"YYYY-MM\")."
},
"notice": {
"description": "Guidance when values_offset lands past the last value of one or more facets — names each emptied facet, its value_count, and its last valid offset. Absent when every facet returned values.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `route_not_found`: Route does not exist in the EIA taxonomy. `route_not_queryable`: Route is a category node with sub-routes, not a queryable leaf. `facet_not_found`: The facet input names an ID the route does not expose. `rate_limited`: EIA rate limit hit during facet fan-out. Other values are possible when a failure originates below the handler.",
"examples": [
"route_not_found",
"route_not_queryable",
"facet_not_found",
"rate_limited"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"route",
"description",
"facets",
"values_offset",
"data_columns",
"frequencies",
"date_range",
"default_frequency",
"default_date_format"
]
},
{
"required": [
"error"
]
}
]
}🟢eia_search_routes(query, limit)
Fuzzy text search across route names, descriptions, and category labels. Resolves natural-language queries like "electricity retail sales by state" or "natural gas imports" to matching route paths. Multi-term queries are also matched term by term, so combining a commodity, a metric, and a sector — "electricity price residential", "coal generation industrial sector" — reaches the route carrying that data even when no single entry reads like the whole phrase. STEO series names are indexed so queries like "ethanol net imports" or "crude oil production forecast" also resolve, and so are facet values, so a fuel type or sector term like "wind" or "anthracite coal" resolves to the route that exposes it, with filter_hint carrying the filter to pass on. Results include isLeaf so you know whether to browse further or query directly. Results with score > 0.72 are weak matches — try a more specific query or use eia_browse_routes to explore the taxonomy. The first call after server start waits 24-30s while the index warms, and at most 45s; every later call returns in milliseconds. Check indexComplete before reading anything into a short or empty result set.
输入模式
{
"type": "object",
"properties": {
"query": {
"type": "string",
"minLength": 1,
"description": "Free-text search terms to match against route names and descriptions."
},
"limit": {
"default": 10,
"description": "Maximum results to return (default 10, max 30).",
"type": "integer",
"minimum": 1,
"maximum": 30
}
},
"required": [
"query"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"route": {
"type": "string",
"description": "Route path — usable directly in eia_describe_route or eia_query_route."
},
"name": {
"type": "string",
"description": "Human-readable route name."
},
"description": {
"type": "string",
"description": "Route description."
},
"score": {
"type": "number",
"description": "Match score: 0 = exact, 1 = no match. Lower is better; above 0.72 the match is unreliable. On a multi-term query it is the better of the whole-phrase score and a per-term score that penalizes each query term the entry does not carry."
},
"isLeaf": {
"type": "boolean",
"description": "True when the route is a queryable leaf; false when it has sub-routes to browse."
},
"filter_hint": {
"description": "Pre-built filter for eia_query_route when a specific facet value is required. Present on STEO series and facet-value results — pass directly as filters (e.g. eia_query_route(route=\"steo\", filters=filter_hint)).",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "string"
}
}
},
"required": [
"route",
"name",
"description",
"score",
"isLeaf"
],
"additionalProperties": false,
"description": "A search result entry."
},
"description": "Ranked matches, best first."
},
"effectiveQuery": {
"type": "string",
"description": "Query as submitted to the Fuse.js index."
},
"totalIndexed": {
"type": "number",
"description": "Total entries in the search index (routes + STEO series names + facet values)."
},
"indexComplete": {
"type": "boolean",
"description": "True when this answer was ranked against the complete corpus. False means part of it is missing (see indexGaps) — results may be short, and a better match may exist that was never scored."
},
"indexGaps": {
"description": "Present only when indexComplete is false: route paths whose metadata could not be fetched (call eia_browse_routes on one to re-fetch it) and index passes that did not land (\"steo_series\", \"facet_values\").",
"type": "array",
"items": {
"type": "string"
}
},
"truncated": {
"type": "boolean",
"description": "True when matches were capped at limit; more may exist."
},
"shown": {
"type": "number",
"description": "Number of results returned."
},
"cap": {
"type": "number",
"description": "The limit that was applied."
},
"notice": {
"description": "Recovery hint when no routes matched — suggests alternative queries or using eia_browse_routes.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode."
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"results",
"effectiveQuery",
"totalIndexed",
"indexComplete",
"truncated",
"shown",
"cap"
]
},
{
"required": [
"error"
]
}
]
}🟢eia_query_route(route, filters, columns, frequency, start, ...)
Fetches data from a leaf route with optional facet filters, date range, frequency, and column selection. Use eia_describe_route first to discover valid facet IDs, facet values, column IDs, and frequency codes. Data values are strings in the response (EIA API returns all numeric values as strings, e.g. "9.13"); cast to DOUBLE in SQL when arithmetic is needed. Returns a preview inline and stages nothing by default — one upstream request, whatever total says. Pass stage: true to also page past the preview and stage the accumulated set as a DataCanvas table, then pass the returned dataset name to eia_dataframe_query for SQL. Every dataset a tenant stages lands in the same canvas, so tables from different routes cross-join by name with nothing to thread between calls.
输入模式
{
"type": "object",
"properties": {
"route": {
"type": "string",
"minLength": 1,
"description": "Leaf route path (e.g. \"electricity/retail-sales\", \"steo\"). Discoverable via eia_browse_routes or eia_search_routes. Leading, trailing, and doubled slashes are stripped, so an EIA-doc spelling like \"/electricity/retail-sales/\" resolves to the same route."
},
"filters": {
"description": "Facet filters keyed by facet ID (e.g. { \"stateid\": \"TX\", \"sectorid\": [\"RES\", \"COM\"] }). Use the facets[].id values returned by eia_describe_route as keys here.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"columns": {
"description": "Data column IDs to return (reduces payload). Defaults to all. IDs discoverable via eia_describe_route.",
"type": "array",
"items": {
"type": "string"
}
},
"frequency": {
"description": "Aggregation frequency ID (e.g. \"monthly\", \"annual\"). Defaults to route default. Valid IDs from eia_describe_route.",
"type": "string"
},
"start": {
"description": "Period start in the route date format (e.g. \"2020-01\" for monthly, \"2020\" for annual). Format from eia_describe_route.",
"type": "string"
},
"end": {
"description": "Period end (same format as start).",
"type": "string"
},
"sort": {
"description": "Result ordering.",
"type": "array",
"items": {
"type": "object",
"properties": {
"column": {
"type": "string",
"description": "Column ID to sort by."
},
"direction": {
"type": "string",
"enum": [
"asc",
"desc"
],
"description": "Sort direction."
}
},
"required": [
"column",
"direction"
],
"description": "A sort criterion."
}
},
"offset": {
"default": 0,
"description": "Row offset into the matching set (default 0). An offset at or beyond total returns zero rows.",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"length": {
"default": 100,
"description": "Rows in the inline preview (default 100, max 5000 per EIA limit). With stage: true, staging is not bounded by this — it pages past the preview on its own.",
"type": "integer",
"minimum": 1,
"maximum": 5000
},
"stage": {
"default": false,
"description": "Stage the matching rows as a DataCanvas table for SQL (default false). Off, the call makes one upstream request and returns the preview alone. On, the service pages past the preview up to EIA_CANVAS_MAX_ROWS and registers the accumulated rows, returning the handle in dataset — several extra upstream requests and seconds of latency on a large route, so turn it on when moving to analysis, not while exploring. Requires a canvas (CANVAS_PROVIDER_TYPE=duckdb); without one nothing is staged whatever this is set to.",
"type": "boolean"
}
},
"required": [
"route"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"route": {
"type": "string",
"description": "The route path queried, in canonical spelling — any leading, trailing, or doubled slashes the input carried are stripped. Reusable verbatim in a follow-up call."
},
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {},
"additionalProperties": {},
"description": "A single data row with dynamic column keys."
},
"description": "Preview rows. All numeric values are strings per the EIA API (e.g. \"9.13\"). Cast to DOUBLE in SQL for arithmetic: CAST(value AS DOUBLE). Per-column units appear as {col}-units fields inline in each row. Keys are dynamic column IDs from the EIA route."
},
"total": {
"type": "number",
"description": "Total matching rows in the EIA dataset for this query (may exceed returned rows when pagination or spillover applies)."
},
"returned_count": {
"type": "number",
"description": "Number of rows in this response. When returned_count < total, use offset pagination or DataCanvas for the rest."
},
"frequency": {
"type": "string",
"description": "Frequency of the returned data."
},
"date_format": {
"type": "string",
"description": "Period format for the returned data (e.g. \"YYYY-MM\")."
},
"notice": {
"description": "Informational message when the response carries no rows — either zero rows matched the filters (broaden the query) or offset paged past the last row (reduce offset below total).",
"type": "string"
},
"dataset": {
"description": "df_<id> table handle for the registered dataset — pass directly to eia_dataframe_query SQL (SELECT ... FROM df_<id>). Present only on a stage: true call against a deployment with a canvas configured; absent otherwise, since nothing was staged. Every dataset a tenant stages shares one canvas, so handles from different routes join directly.",
"type": "string"
},
"canvas_preview_note": {
"description": "Human-readable note when total exceeds the inline preview. On a stage: true call it names how many rows actually reached the canvas table, and where in the matching set those rows sit whenever the stage does not start at row 1; when staging also stopped short of total (the EIA_CANVAS_MAX_ROWS cap, or an upstream page that did not return), it says so and gives the offset to resume from. Where staging was not requested it places the inline page against total and names stage: true as the way to get SQL access to the rest; where no canvas is configured at all, staging is unavailable, so it names offset paging and CANVAS_PROVIDER_TYPE=duckdb instead.",
"type": "string"
},
"truncation_warning": {
"description": "Upstream advisories forwarded verbatim from EIA's warnings[], joined with '; ' when more than one applies. These describe the inline page — EIA's \"incomplete return\" entry fires whenever the requested length is under total, at any size — not a 5,000-row ceiling on this response. Absent when the response already accounts for the gap the advisory names (the staged table reaches the last row, notice explains the empty page, or canvas_preview_note places the inline page against total because nothing was staged).",
"type": "string"
},
"effectiveRoute": {
"type": "string",
"description": "The route path that was queried."
},
"totalCount": {
"type": "number",
"description": "Total matching rows in the EIA dataset."
},
"returnedCount": {
"type": "number",
"description": "Rows in this response. When returnedCount < totalCount, use offset or canvas for the rest."
},
"appliedFilters": {
"description": "Facet filters applied to the query, when provided.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"appliedStart": {
"description": "Echo of the start period as applied, when a start was provided.",
"type": "string"
},
"appliedEnd": {
"description": "Echo of the end period as applied, when an end was provided.",
"type": "string"
},
"appliedFrequency": {
"description": "Echo of the frequency as applied, when a frequency was provided.",
"type": "string"
},
"appliedColumns": {
"description": "Echo of the column projection as applied, when columns were provided.",
"type": "array",
"items": {
"type": "string"
}
},
"appliedSort": {
"description": "Echo of the result ordering as applied, when a sort was provided — the ordering that decided which rows a capped stage holds.",
"type": "array",
"items": {
"type": "object",
"properties": {
"column": {
"type": "string",
"description": "Column ID sorted by."
},
"direction": {
"type": "string",
"enum": [
"asc",
"desc"
],
"description": "Sort direction."
}
},
"required": [
"column",
"direction"
],
"additionalProperties": false,
"description": "A sort criterion as applied."
}
},
"appliedOffset": {
"type": "number",
"description": "Row offset applied to the query — the cause when a page comes back empty."
},
"appliedLength": {
"type": "number",
"description": "Preview row count requested for this call."
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `route_not_found`: Route does not exist in the EIA taxonomy. `route_not_queryable`: Route is a category node with sub-routes, not a queryable leaf. `invalid_facet`: An unknown facet key was used in filters. `invalid_column`: An unknown data column ID was passed in columns. `invalid_frequency`: An unknown frequency code was passed. `invalid_sort`: A sort entry named a column the route does not sort by. `invalid_period`: start or end was not in a period format the route accepts. `no_data`: Date range is inverted (start is after end). `rate_limited`: EIA rate limit hit (OVER_RATE_LIMIT). Other values are possible when a failure originates below the handler.",
"examples": [
"route_not_found",
"route_not_queryable",
"invalid_facet",
"invalid_column",
"invalid_frequency",
"invalid_sort",
"invalid_period",
"no_data",
"rate_limited"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"route",
"data",
"total",
"returned_count",
"frequency",
"date_format",
"effectiveRoute",
"totalCount",
"returnedCount",
"appliedOffset",
"appliedLength"
]
},
{
"required": [
"error"
]
}
]
}🟢eia_dataframe_describe(name)
List canvas dataframes (df_<id>) materialized by eia_query_route calls that passed stage: true, with provenance, expiry, row count, and column schema. Nothing is staged until such a call runs, so an empty list on a fresh session means no query has staged yet, not that staging failed. Drops entries for dataframes the canvas no longer holds before responding, so the list is always current. Pass a specific name to inspect one dataframe; omit to list all active dataframes for this tenant. A name that is not staged comes back as found=false alongside the handles that are, never as an empty list. Listing is not use: only an eia_dataframe_query statement naming a dataframe extends its expiry, so a dataframe polled with this tool and never queried still lapses on schedule.
输入模式
{
"type": "object",
"properties": {
"name": {
"description": "df_<id> handle to describe a single dataframe. Omit to list all active dataframes.",
"type": "string"
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"requested_name": {
"description": "Echo of the name input. Absent when no name was supplied.",
"type": "string"
},
"found": {
"description": "True when the requested name is staged, false when it is not. Absent when no name was supplied — an unscoped list has nothing to resolve.",
"type": "boolean"
},
"active_names": {
"type": "array",
"items": {
"type": "string"
},
"description": "Every df_<id> handle staged for this tenant, regardless of the requested scope. On a miss these are the handles that are still usable."
},
"dataframes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Canvas table name (df_<id>)."
},
"source_tool": {
"type": "string",
"description": "Tool that produced this dataframe."
},
"query_params": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {},
"description": "Input parameters the source tool was called with."
},
"created_at": {
"type": "string",
"description": "ISO 8601 creation timestamp."
},
"expires_at": {
"description": "ISO 8601 expiry, extended each time an eia_dataframe_query statement references this dataframe. Reading it here does not extend it. Absent when the dataframe carries no expiry of its own and follows the canvas lifecycle.",
"type": "string"
},
"row_count": {
"type": "number",
"description": "Rows materialized in the dataframe."
},
"truncated": {
"type": "boolean",
"description": "True when the EIA upstream had more rows than were registered."
},
"max_rows": {
"description": "Materialization cap that produced truncated, when applicable.",
"type": "number"
},
"column_schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Column name."
},
"type": {
"type": "string",
"description": "DuckDB column type (VARCHAR for EIA data values)."
},
"nullable": {
"type": "boolean",
"description": "Whether the column permits NULL."
}
},
"required": [
"name",
"type",
"nullable"
],
"additionalProperties": false,
"description": "A column in the dataframe schema."
},
"description": "Column schema (all EIA data columns are VARCHAR and nullable)."
}
},
"required": [
"name",
"source_tool",
"query_params",
"created_at",
"row_count",
"truncated",
"column_schema"
],
"additionalProperties": false,
"description": "A canvas dataframe entry."
},
"description": "Dataframes matching the requested scope, newest first. Empty when nothing is staged, or when a supplied name does not resolve — read found and active_names to tell those apart."
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `canvas_unavailable`: DataCanvas service is not configured for this deployment. Other values are possible when a failure originates below the handler.",
"examples": [
"canvas_unavailable"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"active_names",
"dataframes"
]
},
{
"required": [
"error"
]
}
]
}🟢eia_dataframe_query(sql, register_as, preview, row_limit)
Run a single-statement SELECT against canvas dataframes registered by eia_query_route calls that passed stage: true — a query that staged nothing leaves no table to select from. Standard DuckDB SQL — joins, aggregates, window functions, CTEs all supported. Reference dataframes by the df_<id> handles returned by eia_query_route or listed by eia_dataframe_describe. Read-only: writes, DDL, DROP, COPY, PRAGMA, ATTACH, and external-file table functions are rejected. System catalogs (information_schema, pg_catalog, sqlite_master, duckdb_*) are denied. EIA data values are VARCHAR — use CAST(col AS DOUBLE) for arithmetic and aggregation. Optional register_as chains results as a new dataframe with a fresh expiry. Every dataframe named in the statement has its expiry extended by the query.
输入模式
{
"type": "object",
"properties": {
"sql": {
"type": "string",
"minLength": 1,
"description": "Single-statement SELECT against df_<id> tables. EIA data columns are VARCHAR — use CAST(col AS DOUBLE) for arithmetic. Example: SELECT period, CAST(value AS DOUBLE) AS val FROM df_XXXXX ORDER BY period"
},
"register_as": {
"description": "When set, persist the result as a new dataframe with a fresh expiry. Use to chain analyses without re-running upstream queries. The name must be unused — reusing a staged name is rejected, and the fix is a different name, not dropping the existing dataframe. eia_dataframe_describe lists the names already taken.",
"type": "string",
"minLength": 1
},
"preview": {
"description": "Rows to include in the immediate response. Defaults to row_limit. Set lower when chaining via register_as and only a sample is needed inline.",
"type": "integer",
"minimum": 0,
"maximum": 10000
},
"row_limit": {
"default": 1000,
"description": "Hard cap on rows materialized in the response (default 1000, max 10000). Rows past the cap are dropped without being counted — the response then carries truncated: true and a totalRows equal to the cap rather than a true total. Pass register_as to materialize the whole result instead and get an exact count.",
"type": "integer",
"minimum": 1,
"maximum": 10000
}
},
"required": [
"sql"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}输出模式
{
"type": "object",
"properties": {
"columns": {
"type": "array",
"items": {
"type": "string"
},
"description": "Column names in projection order."
},
"rows": {
"type": "array",
"items": {
"type": "object",
"properties": {},
"additionalProperties": {},
"description": "A result row with dynamic keys matching the SQL projection columns."
},
"description": "Materialized rows, bounded by preview / row_limit."
},
"registered_as": {
"description": "Set when register_as was supplied and the new dataframe was materialized.",
"type": "string"
},
"expires_at": {
"description": "ISO 8601 expiry for the newly registered dataframe, when applicable. Extended each time a later query references it.",
"type": "string"
},
"totalRows": {
"type": "number",
"description": "Rows the query materialized. Exact when truncated is false — including on the register_as path, which stages and counts the whole result past row_limit. Equal to row_limit when truncated is true: a floor on the real match count, not a total."
},
"returnedRows": {
"type": "number",
"description": "Rows included in this response."
},
"truncated": {
"type": "boolean",
"description": "True when row_limit cut the result: more rows matched than the cap and the remainder was dropped without being counted. False when every matching row was materialized, including on the register_as path, which counts the new dataframe exactly."
},
"executedSql": {
"type": "string",
"description": "Echo of the SQL statement that was executed — confirms the exact query that ran."
},
"notice": {
"description": "Guidance when either cap bound the response — names the cap that applied and how to reach the rows it withheld.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `canvas_unavailable`: DataCanvas service is not configured for this deployment. `system_catalog_access`: SQL references a denied system catalog (information_schema, pg_catalog, sqlite_master, duckdb_*). `missing_table`: SQL references a df_<id> table that is not staged — mistyped, already dropped, or past its expiry. `non_select_statement`: The statement is not a single read-only SELECT — writes, DDL, DROP, COPY, PRAGMA, and ATTACH are rejected. `invalid_sql`: DuckDB could not parse or bind the statement — a syntax error, or a column or alias that does not exist on the referenced dataframe. `register_as_clash`: register_as names a dataframe that is already staged for this tenant. Other values are possible when a failure originates below the handler.",
"examples": [
"canvas_unavailable",
"system_catalog_access",
"missing_table",
"non_select_statement",
"invalid_sql",
"register_as_clash"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"columns",
"rows",
"totalRows",
"returnedRows",
"truncated",
"executedSql"
]
},
{
"required": [
"error"
]
}
]
}社区
证据