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

# ResourceRegistry

> The ResourceRegistry manages all MCP resources within a scope, including both static resources and resource templates.

## Overview

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { ResourceRegistry } from '@frontmcp/sdk';

// Access via scope
const resources = scope.resources;

// List all static resources
const allResources = resources.getResources();

// List all resource templates
const templates = resources.getResourceTemplates();

// Find by URI
const resource = resources.findByUri('file:///config.json');
```

## Methods

### getResources()

Get all static resources (not templates).

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getResources(includeHidden?: boolean): ReadonlyArray<ResourceEntry>
```

| Parameter       | Type      | Default | Description              |
| --------------- | --------- | ------- | ------------------------ |
| `includeHidden` | `boolean` | `false` | Include hidden resources |

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Get all visible resources
const resources = registry.getResources();

// Include hidden resources
const allResources = registry.getResources(true);
```

### getResourceTemplates()

Get all resource templates.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getResourceTemplates(): ReadonlyArray<ResourceEntry>
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const templates = registry.getResourceTemplates();
for (const template of templates) {
  console.log(`Template: ${template.uriTemplate}`);
}
```

### findByUri()

Find a resource by exact URI match.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
findByUri(uri: string): ResourceEntry | undefined
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const resource = registry.findByUri('file:///config.json');
if (resource) {
  console.log(`Found: ${resource.name}`);
}
```

### matchTemplateByUri()

Match a URI against template resources.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
matchTemplateByUri(uri: string): {
  template: ResourceEntry;
  params: Record<string, string>;
} | undefined
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Given template: 'file:///users/{userId}/profile'
const match = registry.matchTemplateByUri('file:///users/123/profile');
if (match) {
  console.log(match.template.name); // user-profile
  console.log(match.params); // { userId: '123' }
}
```

### findResourceForUri()

Find resource by URI (exact match or template).

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
findResourceForUri(uri: string): ResourceEntry | undefined
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Will try exact match first, then template matching
const resource = registry.findResourceForUri('file:///users/123/profile');
```

### findByName()

Find a resource by its base name.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
findByName(name: string): ResourceEntry | undefined
```

### findByQualifiedName()

Find a resource by its fully qualified name.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
findByQualifiedName(qualifiedName: string): ResourceEntry | undefined
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const resource = registry.findByQualifiedName('my-app:config');
```

### getExported()

Lookup a resource by its exported (resolved) name.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getExported(name: string, opts?: { ignoreCase?: boolean }): ResourceEntry | undefined
```

### exportResolvedNames()

Produce unique, conflict-aware exported names.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
exportResolvedNames(opts?: ExportResolvedNamesOptions): Map<string, ResourceEntry>
```

### getInlineResources()

Get resources defined inline (local only).

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getInlineResources(): ReadonlyArray<ResourceEntry>
```

### listAllInstances()

List all resource instances (locals + adopted).

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
listAllInstances(): ReadonlyArray<ResourceEntry>
```

### listByOwner()

List resources by owner path.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
listByOwner(ownerPath: string): ReadonlyArray<ResourceEntry>
```

### registerResourceInstance()

Register a pre-constructed ResourceEntry directly.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
registerResourceInstance(resource: ResourceEntry): void
```

### registerDynamicResource()

Register a resource or template at runtime.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
registerDynamicResource(resourceDef: DynamicResourceDef): ResourceEntry
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Register a dynamic resource
const entry = registry.registerDynamicResource({
  name: 'dynamic-config',
  uri: 'config://runtime',
  description: 'Runtime configuration',
  mimeType: 'application/json',
  read: async () => ({ text: JSON.stringify(config) }),
});
```

### subscribe()

Subscribe to resource change events.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
subscribe(
  opts: SubscribeOptions,
  cb: (event: ResourceChangeEvent) => void
): () => void
```

**Returns:** Unsubscribe function.

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const unsubscribe = registry.subscribe({}, (event) => {
  console.log(`Resource ${event.kind}:`, event.entry?.uri);
});

// Later
unsubscribe();
```

### getCapabilities()

Get MCP capabilities for resources.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getCapabilities(): { subscribe: boolean; listChanged: boolean }
```

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const caps = registry.getCapabilities();
// { subscribe: false, listChanged: true }
```

### hasAny()

Check if any resources exist.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
hasAny(): boolean
```

### adoptFromChild()

Adopt resources from a child registry.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
adoptFromChild(child: ResourceRegistry, childOwner: Owner): void
```

## Change Events

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface ResourceChangeEvent {
  kind: 'added' | 'updated' | 'removed' | 'reset';
  changeScope: 'global' | 'session';
  version: number;
  snapshot: ReadonlyArray<ResourceEntry>;
  entry?: ResourceEntry;
  sessionId?: string;
  relatedRequestId?: string;
}
```

## Indexes

| Index           | Key           | Description                |
| --------------- | ------------- | -------------------------- |
| `byQualifiedId` | `qualifiedId` | Unique identifier lookup   |
| `byName`        | `name`        | Base name lookup           |
| `byUri`         | `uri`         | Static resource URI lookup |
| `byUriTemplate` | `uriTemplate` | Template URI lookup        |
| `byOwner`       | `ownerPath`   | All resources by owner     |

## Static vs Template Resources

<CardGroup cols={2}>
  <Card title="Static Resources" icon="file">
    Have a fixed `uri` property. Found via `findByUri()`.
  </Card>

  <Card title="Template Resources" icon="puzzle-piece">
    Have a `uriTemplate` with parameters. Matched via `matchTemplateByUri()`.
  </Card>
</CardGroup>

**Example:**

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Static resource
@Resource({
  name: 'config',
  uri: 'file:///config.json',
})
class ConfigResource extends ResourceContext { }

// Template resource
@ResourceTemplate({
  name: 'user-profile',
  uriTemplate: 'file:///users/{userId}/profile',
})
class UserProfileResource extends ResourceContext<{ userId: string }> { }
```

## Related

* [Resource Decorator](/frontmcp/sdk-reference/decorators/resource)
* [ResourceTemplate Decorator](/frontmcp/sdk-reference/decorators/resource-template)
* [ResourceContext](/frontmcp/sdk-reference/contexts/resource-context)
* [Registries Overview](/frontmcp/sdk-reference/registries/overview)
