MCP Server Framework - v1.0.0
    Preparing search index...

    Interface ResourceTemplateDefinition<TInput>

    Resource template definition - for dynamic URIs (RFC 6570).

    Templates allow LLMs to access content with variable parameters. Use Zod schemas for type-safe parameter handling.

    // With typed parameters
    const logResource = defineResourceTemplate({
    name: 'log-viewer',
    description: 'View logs by ID',
    uriTemplate: 'myapp://logs/{logId}',
    mimeType: 'text/plain',
    input: z.object({
    logId: z.string().describe('Log identifier'),
    }),
    read: async ({ logId }) => fetchLog(logId),
    list: async () => [
    { uri: 'myapp://logs/1', name: 'Log 1' },
    ],
    });

    // Without schema (params are Record<string, string>)
    const simpleResource = defineResourceTemplate({
    name: 'simple',
    description: 'Simple item lookup',
    uriTemplate: 'myapp://item/{id}',
    read: async (params) => getItem(params.id),
    });
    interface ResourceTemplateDefinition<TInput extends AnyZodObject = AnyZodObject> {
        complete?: CompletionCallback;
        description: string;
        input?: TInput;
        list?: () => Promise<
            { description?: string; mimeType?: string; name?: string; uri: string }[],
        >;
        mimeType?: string;
        name: string;
        read: (
            params: TypeOf<TInput>,
        ) => Promise<string | Uint8Array<ArrayBufferLike>>;
        requiredScopes?: readonly string[];
        uriTemplate: string;
    }

    Type Parameters

    Hierarchy (View Summary)

    Index

    Properties

    Optional callback for argument autocompletion.

    When provided, enables clients to request autocompletion suggestions for URI template variables. The callback receives the variable name and current partial value, and returns matching suggestions.

    The SDK automatically registers the completions capability when any resource template provides a complete callback.

    The URI template variable name being completed

    The current partial value typed by the user

    Completion suggestions

    defineResourceTemplate({
    name: 'note',
    uriTemplate: 'notes://note/{noteId}',
    read: async ({ noteId }) => fetchNote(noteId),
    complete: async (argName, argValue) => ({
    values: allNoteIds.filter(id => id.startsWith(argValue)),
    }),
    });
    description: string

    Human-readable description shown to LLM

    input?: TInput

    Zod object schema for parameter validation.

    When provided, parameters extracted from the URI are validated against this schema before being passed to read().

    input: z.object({
    logId: z.string().describe('Log identifier'),
    format: z.enum(['json', 'text']).optional(),
    })
    list?: () => Promise<
        { description?: string; mimeType?: string; name?: string; uri: string }[],
    >

    Optional function to enumerate available resources.

    When provided, this enables LLMs to discover what resources are available for this template. Useful for dynamic resource discovery.

    mimeType?: string

    MIME type of the content (optional)

    name: string

    Unique resource name for identification

    read: (params: TypeOf<TInput>) => Promise<string | Uint8Array<ArrayBufferLike>>

    Content provider function with template parameters.

    Type Declaration

      • (params: TypeOf<TInput>): Promise<string | Uint8Array<ArrayBufferLike>>
      • Parameters

        • params: TypeOf<TInput>

          Parameters extracted from URI template (typed if input schema provided)

        Returns Promise<string | Uint8Array<ArrayBufferLike>>

        String content or Uint8Array for binary data

    requiredScopes?: readonly string[]

    Scopes required to read this resource template (RBAC).

    When set, the framework checks authInfo.scopes BEFORE the read handler executes. All listed scopes must be present (AND logic). If the check fails, a 403 Forbidden error is returned.

    Omit or set to undefined for resources accessible to any authenticated user.

    uriTemplate: string

    URI template pattern using RFC 6570 (e.g., 'myapp://logs/{logId}')