| 1 | import { ServerCapabilities } from '@modelcontextprotocol/sdk/types.js' |
| 2 | import { CanActivate, ModuleMetadata, Provider, Type } from '@nestjs/common' |
| 3 | |
| 4 | export enum McpTransportType { |
| 5 | SSE = 'sse', |
| 6 | STREAMABLE_HTTP = 'streamable-http', |
| 7 | STDIO = 'stdio', |
| 8 | } |
| 9 | |
| 10 | export interface McpOptions { |
| 11 | // When and if, additional properties are introduced in ServerOptions or ServerInfo, |
| 12 | // consider deprecating these fields in favor of using ServerOptions and ServerInfo directly. |
| 13 | name: string |
| 14 | version: string |
| 15 | capabilities?: ServerCapabilities |
| 16 | instructions?: string |
| 17 | |
| 18 | transport?: McpTransportType | McpTransportType[] |
| 19 | sseEndpoint?: string |
| 20 | messagesEndpoint?: string |
| 21 | mcpEndpoint?: string |
| 22 | /** |
| 23 | * @deprecated Use `app.setGlobalPrefix()` for global api prefix. Use apiPrefix to attach a prefix to the handshake. |
| 24 | */ |
| 25 | globalApiPrefix?: never |
| 26 | apiPrefix?: string |
| 27 | guards?: Type<CanActivate>[] |
| 28 | decorators?: ClassDecorator[] |
| 29 | sse?: { |
| 30 | pingEnabled?: boolean |
| 31 | pingIntervalMs?: number |
| 32 | } |
| 33 | streamableHttp?: { |
| 34 | enableJsonResponse?: boolean |
| 35 | sessionIdGenerator?: () => string |
| 36 | /** |
| 37 | * @experimental: The current implementation does not fully comply with the MCP Specification. |
| 38 | */ |
| 39 | statelessMode?: boolean |
| 40 | } |
| 41 | /** |
| 42 | * Custom provider for MCP tool monitoring. |
| 43 | * Must provide `MCP_TOOL_MONITOR` token implementing `McpToolMonitor`. |
| 44 | * Defaults to a no-op adapter if not provided. |
| 45 | */ |
| 46 | toolMonitorProvider?: Provider |
| 47 | } |
| 48 | |
| 49 | // Async variant omits transport since controllers are not auto-registered in forRootAsync |
| 50 | export type McpAsyncOptions = Omit<McpOptions, 'transport'> |
| 51 | |
| 52 | export interface McpOptionsFactory { |
| 53 | createMcpOptions: () => Promise<McpAsyncOptions> | McpAsyncOptions |
| 54 | } |
| 55 | |
| 56 | export interface McpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { |
| 57 | useExisting?: Type<McpOptionsFactory> |
| 58 | useClass?: Type<McpOptionsFactory> |
| 59 | useFactory?: (...args: any[]) => Promise<McpAsyncOptions> | McpAsyncOptions |
| 60 | inject?: any[] |
| 61 | extraProviders?: any[] // allow user to provide additional providers in async mode |
| 62 | } |
| 63 |