> For the complete documentation index, see [llms.txt](https://chaincontext.gitbook.io/help-center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaincontext.gitbook.io/help-center/building/resources-prompts-sampling.md).

# Resources, Prompts & Sampling

## Resources

MCP resources provide static or dynamic data that AI agents can read. Unlike tools (which are called with arguments), resources are accessed by URI.

### Resource types

| Type           | Description                                            |
| -------------- | ------------------------------------------------------ |
| `text`         | Plain text or JSON content stored in the database      |
| `url`          | External URL — the runtime fetches it at read time     |
| `file`         | File uploaded to Supabase Storage (PDFs, CSVs, images) |
| `onchain`      | On-chain data fetched via RPC at read time             |
| `contract_abi` | The ABI/IDL of an imported contract (auto-generated)   |

### Creating a resource

1. Go to your project → **Resources** tab
2. Click **Add Resource**
3. Choose the type and configure:
   * **Name** — displayed to the AI (e.g., "Token whitelist")
   * **URI** — the MCP resource URI (e.g., `chaincontext://resources/token-whitelist`)
   * **MIME type** — `text/plain`, `application/json`, `text/csv`, etc.
   * **Cache TTL** — how long to cache the content (in seconds, 0 = no cache)

### File uploads

{% hint style="info" %}
For file resources, upload the file directly. Supported: any file type, max 10 MB. Files are stored in Supabase Storage and served through signed URLs.
{% endhint %}

***

## Prompts

MCP prompts are reusable templates that AI agents can request. They support `{{variable}}` interpolation for dynamic content.

### Creating a prompt

1. Go to your project → **Prompts** tab
2. Click **Add Prompt**
3. Configure:
   * **Name** — the MCP prompt identifier (e.g., `analyze-portfolio`)
   * **Display name** — human-readable label
   * **Description** — what the prompt is for
   * **Template** — the prompt text with `{{variable}}` placeholders

### Variables

Variables are auto-detected from `{{double-brace}}` patterns in your template. For each variable you can set:

* **Description** — helps the AI understand what value to provide
* **Required** — whether the variable must be provided (defaults to true)

<details>

<summary>Example template</summary>

```
Analyze the DeFi portfolio for wallet {{walletAddress}} on {{network}}.
Focus on: yield optimization, risk exposure, and rebalancing opportunities.
Include current token balances and their USD values.
```

This auto-detects `walletAddress` and `network` as arguments.

</details>

### How prompts work in MCP

{% hint style="success" %}
When an AI agent calls `prompts/get` with your prompt name, the runtime loads the template, validates required arguments, replaces `{{variable}}` placeholders, and returns the rendered prompt as a message.
{% endhint %}

***

## Sampling

Sampling lets your MCP server request the AI to generate text — enabling "AI-in-the-loop" workflows.

{% hint style="warning" %}
Sampling requires client support. Not all MCP clients implement the sampling capability yet.
{% endhint %}

### Configuration

1. Go to your project → **Sampling** tab
2. Toggle **Enable sampling**
3. For each sampling template, configure:
   * **Trigger** — when to invoke sampling (e.g., after a specific tool runs)
   * **Prompt template** — the text sent to the AI for generation
   * **Model hints** — preferred model family (e.g., "claude", "gpt")
   * **Max tokens** — response length limit

### Use cases

* **Auto-summarize** tool results before returning them
* **Generate analysis** from raw on-chain data
* **Create alerts** with natural language descriptions of detected conditions
