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

    Function defineResource

    • Define a resource with automatic registration.

      This is the recommended way to define static resources in the framework. The resource is automatically registered in the global registry when defined.

      Parameters

      Returns ResourceStaticDefinition

      The registered resource (for re-export and type inference)

      // resources/config.ts
      import { defineResource } from 'mcp-server-framework';

      export const configResource = defineResource({
      name: 'app-config',
      description: 'Application configuration',
      uri: 'myapp://config/main',
      mimeType: 'application/json',
      read: async () => JSON.stringify({
      version: '1.0.0',
      environment: process.env.NODE_ENV,
      }),
      });
      // resources/readme.ts - Text resource
      import { defineResource } from 'mcp-server-framework';
      import { readFile } from 'fs/promises';

      export const readmeResource = defineResource({
      name: 'readme',
      description: 'Project README file',
      uri: 'myapp://docs/readme',
      mimeType: 'text/markdown',
      read: async () => readFile('./README.md', 'utf-8'),
      });