/** * Types for the simplified MCP server API. * These types define the high-level API that hides McpServer, Transport, and Express details. */ import type { EnvironmentName } from '../../environments.js'; import type { CreditsOption } from './paywall.types.js'; import type { ZodType } from 'zod'; /** * Configuration for a tool. */ export interface McpToolConfig { /** Human-readable title for the tool */ title?: string; /** Description of what the tool does */ description: string; /** Zod schema for input arguments (will be converted to JSON Schema internally) */ inputSchema?: ZodType; /** JSON Schema for output (optional) */ outputSchema?: Record; } /** * Configuration for a resource. */ export interface McpResourceConfig { /** Human-readable title for the resource */ title?: string; /** Description of the resource */ description?: string; /** MIME type of the resource content */ mimeType?: string; } /** * Configuration for a prompt. */ export interface McpPromptConfig { /** Human-readable title for the prompt */ title?: string; /** Description of the prompt */ description?: string; /** Arguments the prompt accepts (ZodRawShape or ZodType) */ argsSchema?: any; } /** * Options for tool/resource/prompt registration. */ export interface McpRegistrationOptions { /** Credits to charge per call (default: 1). Can be a fixed value or a function that receives context with args and result. */ credits?: CreditsOption | number; /** What to do if credit redemption fails */ onRedeemError?: 'ignore' | 'propagate'; } /** * Handler function for a tool. */ export type ToolHandler = (args: TArgs, context?: ToolContext) => Promise | TResult; /** * Handler function for a resource. */ export type ResourceHandler = (uri: URL, variables: Record, context?: ResourceContext) => Promise | TResult; /** * Handler function for a prompt. */ export type PromptHandler = (args: Record, context?: PromptContext) => Promise | TResult; /** * Context passed to tool handlers. */ export interface ToolContext { /** Request ID for tracking */ requestId?: string; /** Credits available/charged */ credits?: bigint; /** Raw MCP extra context */ extra?: any; } /** * Context passed to resource handlers. */ export interface ResourceContext { /** Request ID for tracking */ requestId?: string; /** Credits available/charged */ credits?: bigint; /** Raw MCP extra context */ extra?: any; } /** * Context passed to prompt handlers. */ export interface PromptContext { /** Request ID for tracking */ requestId?: string; /** Credits available/charged */ credits?: bigint; /** Raw MCP extra context */ extra?: any; } /** * Configuration for starting the MCP server. */ export interface McpServerConfig { /** Port to listen on */ port: number; /** Plan ID the server charges against (required) */ planId: string; /** Agent ID (DID) for Nevermined — optional, informational only */ agentId?: string; /** Human-readable server name */ serverName: string; /** Base URL of the server (default: http://localhost:\{port\}) */ baseUrl?: string; /** Host to bind to (default: 0.0.0.0) */ host?: string; /** Nevermined environment (default: from Payments instance) */ environment?: EnvironmentName; /** Server version (default: 1.0.0) */ version?: string; /** Server description */ description?: string; /** CORS origins (default: *) */ corsOrigins?: string | string[]; /** Enable OAuth discovery endpoints (default: true) */ enableOAuthDiscovery?: boolean; /** Enable client registration (default: true) */ enableClientRegistration?: boolean; /** Enable health check endpoint (default: true) */ enableHealthCheck?: boolean; /** Enable server info endpoint (default: true) */ enableServerInfo?: boolean; /** Callback when server starts */ onStart?: (info: ServerInfo) => void; /** Callback for logging */ onLog?: (message: string, level?: 'info' | 'warn' | 'error') => void; } /** * Information about a running server. */ export interface ServerInfo { /** Base URL of the server */ baseUrl: string; /** Port the server is listening on */ port: number; /** List of registered tools */ tools: string[]; /** List of registered resources */ resources: string[]; /** List of registered prompts */ prompts: string[]; } /** * Result of starting the server. */ export interface McpServerResult { /** Server info */ info: ServerInfo; /** Stop the server gracefully */ stop: () => Promise; } /** * Internal registration entry for a tool. */ export interface ToolRegistration { name: string; config: McpToolConfig; handler: ToolHandler; options: McpRegistrationOptions; } /** * Internal registration entry for a resource. */ export interface ResourceRegistration { name: string; uriOrTemplate: string; config: McpResourceConfig; handler: ResourceHandler; options: McpRegistrationOptions; } /** * Internal registration entry for a prompt. */ export interface PromptRegistration { name: string; config: McpPromptConfig; handler: PromptHandler; options: McpRegistrationOptions; } //# sourceMappingURL=server.types.d.ts.map