返回 AiToEarn
resource-template.decorator.ts
根目录 / project / aitoearn-backend / libs / nest-mcp / src / decorators / resource-template.decorator.ts
1 import { SetMetadata } from '@nestjs/common'
2 import { MCP_RESOURCE_TEMPLATE_METADATA_KEY } from './constants'
3
4 export interface ResourceTemplateOptions {
5 uriTemplate: string // URI template following RFC 6570
6 name?: string // Human-readable name
7 description?: string // Optional description
8 mimeType?: string // Optional MIME type
9 _meta?: Record<string, any>
10 }
11
12 export interface ResourceTemplateMetadata {
13 uriTemplate: string // URI template following RFC 6570
14 name: string // Human-readable name
15 description?: string // Optional description
16 mimeType?: string // Optional MIME type
17 _meta?: Record<string, any>
18 }
19
20 /**
21 * Decorator that marks a controller method as an MCP resource.
22 * @param {object} options - The options for the decorator
23 * @param {string} options.name - The name of the resource
24 * @param {string} options.uriTemplate - The URI template of the resource
25 * @returns {MethodDecorator} - The decorator
26 */
27 export function ResourceTemplate(options: ResourceTemplateOptions) {
28 return SetMetadata(MCP_RESOURCE_TEMPLATE_METADATA_KEY, options)
29 }
30
30 lines TYPESCRIPT