← MetalCONTENT HISTORY
WHAT CHANGED
Update to Metal
Snapshot Nov 23, 2026 · 18:22 UTC · version 0.2.8
Collection source: downloaded plugin package.
First saved snapshot
No earlier snapshot is available to establish a change.
Save Metal and check future changes in Following.
Up to 3 plugins free · no card required.
Compare saved observations
Download comparison JSONFull technical diff · 0 changed fields
Full snapshot data
{
"description": "Use when a Metal task needs a read-only Python script run through the Metal MCP's run_metal_sdk_query tool: joins, aggregations or bounded batch reads that would take many separate Metal tool calls. Covers method discovery, the script contract, limits, errors, pagination and batches.",
"included_files": [
{
"relative_path": "references/patterns.md",
"size_in_bytes": 2516
}
],
"name": "metal-sdk-scripts",
"skill_md_contents": "---\nname: metal-sdk-scripts\ndescription: \"Use when a Metal task needs a read-only Python script run through the Metal MCP's run_metal_sdk_query tool: joins, aggregations or bounded batch reads that would take many separate Metal tool calls. Covers method discovery, the script contract, limits, errors, pagination and batches.\"\n---\n\n# Metal SDK Scripts\n\nBefore starting, read [Safety and confirmation](../../references/safety.md) and apply it throughout this task.\n\n`run_metal_sdk_query` runs a short Python script inside Metal. The script gets a `metal` object whose methods read the user's Metal data, and returns one compact JSON result. Use it to join, filter or aggregate data that would otherwise take many separate tool calls. This skill says when to use it, how to find methods, what the script may do, and how to stay inside its limits.\n\n## When the tool is missing\n\n`run_metal_sdk_query` exists only when the organization has programmatic queries turned on in its Metal settings and the connection's token carries the `read:programmatic` scope. `list_sdk_methods` and `get_sdk_method` can be present without it, because dashboard work also uses them.\n\nIf `run_metal_sdk_query` is not in your tool list:\n\n- Do the task with the regular Metal tools when a reasonable number of calls covers it.\n- Otherwise tell the user that programmatic queries are not available on their Metal connection.\n- Don't work around it. Don't run SDK code in a dashboard widget, a workflow step or this client's own sandbox to get the same effect.\n\n## When to use a script\n\n- Prefer a dedicated Metal tool for a simple lookup, such as one company or one search.\n- Use a script when the answer needs several dependent reads, a join across record types, or a count, sum or grouping over many records.\n- Use a script when several independent reads can go in one `metal.batch` call instead of many tool calls.\n- Return only the answer: the counts, the summary, the few rows the user asked for. Don't return raw collections.\n\n## Find methods before you write\n\nThe method set is closed. A script can call only the methods `list_sdk_methods` returns.\n\n1. Call `list_sdk_methods` with a `query`. The match is a case-insensitive substring of the method's name, signature, one-line description, HTTP method and path. Try a resource word such as `deal`, `company` or `observation`. Results come 20 per page by default, at most 50 with `pageSize`; page with `page` while `hasMore` is true.\n2. Call `get_sdk_method` with the method `name` for every method you plan to call. Its `reference` gives the signature, which arguments go in `query=` and which in `body=`, the response envelope, enums and usage notes. Write field names from the reference, not from the method name.\n3. If a method has no reference (`documented` is false), run a first script that returns one sample record in `_output`, then adapt to the real shape. Don't guess a response shape.\n\n## The script contract\n\n- Globals: `metal`, `input` (the `input` object you pass to the tool, or `{}`), and the modules `json`, `math` and `statistics`.\n- Assign a JSON-serializable value to `_output`. A script that doesn't set it fails. `NaN` and infinity are not valid JSON, so guard divisions and empty `statistics` inputs.\n- Optionally assign `_citations`, a list of objects. `metal.citations.collect(*responses, extra=None)` gathers the `citations` lists from SDK responses and removes duplicates.\n- Pass record IDs and parameters through `input`, not by pasting them into the script.\n- `print` output is discarded. Put anything you need to see in `_output`.\n\nThe runner rejects these before the script runs:\n\n- Imports outside `collections`, `datetime`, `decimal`, `html`, `itertools`, `json`, `math`, `re`, `statistics` and `time`. Import `datetime` yourself; it is not pre-bound.\n- Any attribute that starts with `_`, including dunders, and any name that starts with `_` other than `_`, `_output` and `_citations`. Name helper functions without a leading underscore.\n- `.format()` and `.format_map()`. Use f-strings.\n\nBuiltins are limited. `open`, `getattr`, `setattr`, `type` and class definitions are not available. Use `isinstance` and `hasattr`, and plain functions, dicts and lists.\n\n## Calling methods\n\n```python\ndeal = metal.get_deal(input[\"dealId\"])\ncompanies = metal.list_companies(query={\"page\": 1, \"limit\": 50})\npage = metal.search_deals(query={\"page\": 1, \"limit\": 100}, body={\"filters\": {\"and\": [{\"field\": \"deal_closeDate\", \"operator\": \"gte\", \"value\": \"2026-01-01T00:00:00Z\"}]}})\nsame_deal = metal.call_method(\"get_deal\", input[\"dealId\"])\n```\n\n- Path arguments are positional, in the order the reference gives. IDs are 24-character hex strings; pass them as `str`.\n- `query=` holds query-string parameters. Keys whose value is `None` are dropped.\n- `body=` holds the request body of a POST method, such as the `search_*` methods.\n- A response that is exactly `{\"data\": ...}` is unwrapped to its `data`. A response with other top-level keys keeps its envelope. For example, `search_deals` returns `{\"data\": [...], \"metadata\": {...}}`: read rows from `result[\"data\"]` and totals from `result[\"metadata\"]`. Never iterate the envelope itself.\n- `metal.available_methods()` lists the callable methods from inside a script.\n\n## Limits\n\n| Limit | Value | What happens |\n|---|---|---|\n| Script size | 64 KiB | The tool rejects the call |\n| `input` size | 64 KiB, serialized | The tool rejects the call |\n| SDK calls | 20 per run; a batch of N calls counts as N | The call that would pass 20 raises an error |\n| SDK response bytes | 2 MiB, cumulative across all calls | The call that would pass it raises an error |\n| One SDK call or batch | The runner waits at most 10 seconds for its response | The call fails |\n| Output | 512 KiB for serialized `_output` plus `_citations` | The run fails with an output-size error |\n| Script execution | 25 seconds | The run fails with a timeout error |\n| Whole request | 60 seconds | The tool returns a timeout error |\n\nThese limits shape the script:\n\n- Filter on the server. Pass filters in `body=` or `query=` rather than fetching a broad list and filtering in Python.\n- Plan the call budget before you write a loop. Twenty calls is twenty pages, or one batch of twenty reads, not both.\n- When a task needs more than one run can do, split it into several runs with narrower filters, or tell the user what the bound covered.\n\nIf the tool returns a capacity error with `retry_after`, wait that many seconds before you call it again.\n\n## Pagination\n\nEvery page is one call against the 20-call budget.\n\n- For a GET list method, `metal.paginate(name, *path_args, query=None, page_size=50, max_pages=100)` yields records across pages. It sends `page` and `limit`, follows a `nextCursor` when the response carries one, and stops when the response says there are no more pages or a page comes back short. Set `max_pages` to the calls you can spare, not the default. When `max_pages` runs out first, it raises an error.\n- `paginate` sends no request body, so it can't page a POST `search_*` method. Page those yourself with `body=` and `query={\"page\": n, \"limit\": size}`, and stop at `metadata.totalPages` or the budget you set.\n- Read each method's maximum `limit` from `get_sdk_method`. A larger page uses fewer calls but more of the 2 MiB response budget.\n- Report whether the scan was complete. When the budget stopped it early, say how many records or pages it read and how many exist.\n\nSee `references/patterns.md` for a hand-paged search, a batch read and per-record error handling.\n\n## Batches\n\n`metal.batch` sends independent reads in one round trip:\n\n```python\nresults = metal.batch([{\"name\": \"get_deal\", \"pathArgs\": [deal_id]} for deal_id in input[\"dealIds\"]])\n```\n\n- Each item is a dict with `name` and, as needed, `pathArgs`, `query` and `body`.\n- A batch holds 1 to 20 calls, and each call counts against the 20-call budget.\n- Results come back unwrapped, one per call, in order.\n- The calls run one after another, and the whole batch shares the 10-second wait. Keep slow calls out of large batches.\n- The first failing call fails the whole batch, and the results of the calls before it are lost. Use a batch only for reads you expect to succeed. When some IDs may be missing, make separate calls and handle each error.\n- Use a batch only for calls that don't depend on each other. Make dependent calls one after another.\n\n## Errors\n\nA failed SDK call raises an exception with a `.status` attribute (the HTTP status, or `None`) and a message that names the status. A runner limit, such as the call budget, raises the same kind of exception. Calling a method that doesn't exist raises an `AttributeError` that tells you to check the available methods.\n\nThe script can't import the SDK's error classes. Catch `Exception`, then read `exc.status` after `hasattr(exc, \"status\")`.\n\nAn uncaught SDK error reaches you with its message mainly when Metal rejected the request as invalid (status 400 or 422), the Metal SDK broker denied it, or the call budget, the response budget or the execution deadline stopped the call. Any other uncaught SDK error, such as a 404 or a call that passed the 10-second wait, reaches you only as a generic failure, without the status or message. Catch the errors you expect, such as a 404 for a missing record, and report them in `_output`:\n\n```python\ntry:\n deal = metal.get_deal(deal_id)\nexcept Exception as exc:\n if hasattr(exc, \"status\") and exc.status == 404:\n deal = None\n else:\n raise\n```\n\nOther script errors, such as a syntax error or a `KeyError`, come back with the message, an error `type` in `details`, and an `executionId`. Fix the script and run it again. Give the user the `executionId` only if you report a failure you can't fix.\n\n## Reading the result\n\nA successful call returns `data` (your `_output`), `citations` when the script set them, and `meta`. `meta.sdkCallCount` and `meta.sdkResponseBytes` show how much of the budget the run used; check them before you scale a script up.\n\n## Connected MCP tools in a script\n\n`query_mcp_tool` is an SDK method that calls a tool on an MCP server the user connected in Metal, such as a data warehouse. Use it in a script only when you need to combine that tool's results with Metal data or with other calls in one run. For a single call, use `call_connected_mcp_tool`.\n\n```python\nrows = metal.query_mcp_tool(input[\"connectionId\"], \"search_company\", body={\"arguments\": {\"domain\": \"acme.com\"}})\n```\n\n- The path arguments are the connection ID and the tool name. Get both, and the tool's input schema, from `list_connected_mcp_tools`; its `connectionId` is the connection ID.\n- First list connections, then call `list_connected_mcp_tools` with the selected `server` name or `connectionId` to get its schemas. For a single read, call `call_connected_mcp_tool` with `server`, `tool` and `arguments` instead of starting a script.\n- Wrap the tool's arguments as `body={\"arguments\": {...}}`. A trailing positional argument is not sent.\n- Metal calls only tools that the server marks read-only.\n- The 10-second wait applies. A slow remote tool fails here even when `call_connected_mcp_tool` could finish it.\n- The response holds the tool's `content` blocks. `isError` is present when the remote tool reported an error; report that content rather than retrying.\n\n## Dashboard widget scripts are a different runtime\n\nDashboard widget scripts also get a `metal` object, and `list_sdk_methods` and `get_sdk_method` describe the methods for both. The runtime is different, so don't copy a script between them unchanged. The `dashboard-building` skill covers widget scripts.\n\n| | `run_metal_sdk_query` | Widget script |\n|---|---|---|\n| `metal.<method>(...)`, `call_method`, `available_methods`, `citations.collect` | Yes | Yes |\n| `paginate` | Yes | Only on some of Metal's widget backends; page by hand |\n| `batch` with dicts | Yes | No |\n| `get_file_bytes`, `open_file` | No | Yes |\n| Error raised by a failed call | Exception with `.status` | `MetalAPIError` |\n| SDK calls | 20 | 250 |\n| Cumulative SDK responses | 2 MiB | 32 MiB |\n| Output | 512 KiB | 4 MiB |\n| Execution time | 25 seconds | 50 seconds |\n| One SDK call | 10 seconds | 30 seconds |\n\n`metal.stream_to_workspace` also exists in `run_metal_sdk_query`, but a script there can't open files and its sandbox is discarded after the run. Don't use it.\n\n## Read-only and scoped to the user\n\n- Every SDK method reads. No method creates, updates or deletes Metal data, and scripts have no filesystem, subprocess or network access. For a change, use the Metal tool that makes it, with the user's approval.\n- A script runs as the signed-in user in their organization and sees only what that user can read.\n- `metal.get_current_user()` and `metal.get_ctx_org()` return the user and organization the script runs as.\n"
}SHA-256 of public snapshot: 356e3f7d937557821e38897b0a47bf098ac626bd228392ce977d21db581875df