# attach_policy_document

> MCP tool that accepts one policy or compliance document inline and exposes it as a read-only MCP resource, published when the files extension is enabled

Source: https://stackql.io/mcp/attach_policy_document

Accepts one policy or compliance document as text, such as an OPA/Rego policy, a compliance control set or another GRC document, and exposes it read-only as the MCP resource `stackql://policies/<id>`, so an agent can read it back while it checks live infrastructure against it.  The document is held in server memory only.  Available in StackQL releases from `v1.1.975`.

The tool is published only when the server runs with the [files extension](/command-line-usage/mcp#file-uploads) enabled (`server.extensions.files.enabled: true`).

See also:
[[ MCP overview ]](/command-line-usage/mcp) [[ MCP extensions ]](/command-line-usage/mcp#mcp-extensions) [[ `run_select_query` ]](/mcp/run_select_query)

* * *

## Inputs

| Argument | Required | Description |
|--|--|--|
|`document`|Yes|The file as an MCP `FileInput` with its bytes inline: `id`, `mimeType` and `size` are required, `data` carries the content base64-encoded (RFC 4648, standard alphabet, padded), and `name` and `digest` (`{"algorithm": "sha-256", "value": "<base64url, unpadded>"}`) are optional.|
|`label`|No|A name for the document.|

Accepted files are `.rego`, `.yaml`, `.yml`, `.json`, `.md`, `.txt` and `.csv`, with a text media type (`text/*`, `application/json`, `application/yaml` or `application/octet-stream` judged by content).  A document must be non-empty UTF-8 text no larger than `server.extensions.files.max_inline_bytes` (1 MiB by default, at most 2 MiB).  A missing `data`, invalid base64, a `size` that does not match the decoded bytes, a file over the limit, a wrong digest, binary content or an empty file returns a tool error and stores nothing.

* * *

## Output

| Renderer | Shape |
|--|--|
| Text + resource link | A one-line summary and a `resource_link` to `stackql://policies/<id>`, where `<id>` is generated by the server |

Read the document back with `resources/read` on the returned URI.  Stored documents do not survive a restart, and past 100 documents the oldest is dropped.

* * *

## Gating

Allowed in every server mode.  The tool touches no cloud resource and writes only server memory, so it is classified like a read.  The audit record keeps the document's name, media type, size and digest, never its content.
