> ## Documentation Index
> Fetch the complete documentation index at: https://veryfront.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# veryfront/resource

> Declare and register resources exposable over MCP.

## Import

```ts theme={null}
import { resource, resourceRegistry } from "veryfront/resource";
```

## Examples

```ts theme={null}
import { resource } from "veryfront/resource";
import { defineSchema } from "veryfront/schemas";

const docsBySection: Record<string, string> = {
  agents: "Agents accept messages, tools, context, and runtime options.",
  tools: "Tools expose schema-backed callable capabilities.",
};

const docs = resource({
  pattern: "docs/:section",
  description: "API documentation",
  paramsSchema: defineSchema((v) => v.object({ section: v.string() }))(),
  load: ({ section }) => {
    return { content: docsBySection[section] ?? "Section not found." };
  },
});

const result = await docs.load({ section: "agents" });
```

## API

### `resource(config)`

Create a typed resource definition.

| Property       | Type                                                       | Description                                      | Source                                                                                    |
| -------------- | ---------------------------------------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| `pattern?`     | `string`                                                   | URI template pattern for parameterized resources | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L19) |
| `description`  | `string`                                                   | Resource description                             | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L20) |
| `title?`       | `string`                                                   |                                                  | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L21) |
| `paramsSchema` | <code>Schema\<TParams></code>                              | Zod schema for URI parameters                    | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L22) |
| `load`         | <code>(params: TParams) => Promise\<TData> \| TData</code> | Function returning resource content              | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L23) |
| `subscribe?`   | <code>(params: TParams) => AsyncIterable\<TData></code>    | Async iterable for real-time resource updates    | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L24) |
| `mcp?`         | `McpConfig`                                                | MCP server configuration                         | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L25) |

**Returns:** <code>Resource\<TParams, TData></code>

## Exports

### Functions

| Name       | Description                         | Source                                                                                      |
| ---------- | ----------------------------------- | ------------------------------------------------------------------------------------------- |
| `resource` | Create a typed resource definition. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/factory.ts#L13) |

### Types

| Name             | Description                       | Source                                                                                    |
| ---------------- | --------------------------------- | ----------------------------------------------------------------------------------------- |
| `Resource`       | Public API contract for resource. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L29) |
| `ResourceConfig` | Configuration used by resource.   | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/types.ts#L18) |

### Constants

| Name               | Description                     | Source                                                                                       |
| ------------------ | ------------------------------- | -------------------------------------------------------------------------------------------- |
| `resourceRegistry` | Shared resource registry value. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/resource/registry.ts#L50) |
