import { MessageChannelServerTransport } from '@opentiny/next'; import { McpServer, ToolCallback, RegisteredTool, PromptCallback, RegisteredPrompt, ResourceMetadata, ResourceTemplate, RegisteredResource, ReadResourceCallback, RegisteredResourceTemplate, ReadResourceTemplateCallback } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z, ZodObject, ZodLiteral, ZodType, ZodOptional, ZodRawShape, ZodTypeDef } from 'zod'; import { Result, Request, Notification, Implementation, ToolAnnotations, ClientCapabilities, ElicitResult, ElicitRequest, ListRootsRequest, CreateMessageRequest, LoggingMessageNotification, ResourceUpdatedNotification, SubscribeRequest, UnsubscribeRequest, SetLevelRequest, ListResourcesRequest, RootsListChangedNotification } from '@modelcontextprotocol/sdk/types.js'; import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js'; import { RequestOptions, NotificationOptions, RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js'; type PromptArgsRawShape = { [k: string]: ZodType | ZodOptional>; }; type SendRequestT = Request; type SendNotificationT = Notification; type SendResultT = Result; /** * High-level Web MCP server that provides a simpler API for working with resources, tools, and prompts. * For advanced usage (like sending notifications or setting custom request handlers), use the underlying * Server instance available via the `server` property. */ export declare class WebMcpServer { readonly server: McpServer; transport: Transport | undefined; constructor(serverInfo?: Implementation, options?: ServerOptions); /** * Connects the server to a transport via the specified option. */ connect(options: Transport | string): Promise; /** * Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification). */ oninitialized?: () => void; /** * Callback for when the connection is closed for any reason. * * This is invoked when close() is called as well. */ onclose?: () => void; /** * Callback for when an error occurs. * * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band. */ onerror?: (error: Error) => void; /** * Closes the connection. */ close(): Promise; /** * Registers a tool with a config object and callback. */ registerTool(name: string, config: { title?: string; description?: string; inputSchema?: InputArgs; outputSchema?: OutputArgs; annotations?: ToolAnnotations; }, cb: ToolCallback): RegisteredTool; /** * Registers a prompt with a config object and callback. */ registerPrompt(name: string, config: { title?: string; description?: string; argsSchema?: Args; }, cb: PromptCallback): RegisteredPrompt; /** * Registers a resource with a config object and callback. * For static resources, use a URI string. For dynamic resources, use a ResourceTemplate. */ registerResource(name: string, uriOrTemplate: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; registerResource(name: string, uriOrTemplate: ResourceTemplate, config: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; /** * Checks if the server is connected to a transport. * @returns True if the server is connected */ isConnected(): boolean; /** * Sends a resource list changed event to the client, if connected. */ sendResourceListChanged(): void; /** * Sends a tool list changed event to the client, if connected. */ sendToolListChanged(): void; /** * Sends a prompt list changed event to the client, if connected. */ sendPromptListChanged(): void; /** * After initialization has completed, this will be populated with the client's reported capabilities. */ getClientCapabilities(): ClientCapabilities | undefined; /** * After initialization has completed, this will be populated with information about the client's name and version. */ getClientVersion(): Implementation | undefined; /** * Sends a ping to the client to check if it is still connected. */ ping(): Promise<{ _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; /** * Creates a LLM message to be sent to the client. */ createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<{ [x: string]: unknown; model: string; role: "user" | "assistant"; content: { type: "text"; text: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { type: "image"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { type: "audio"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; }; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; stopReason?: string | undefined; }>; /** * Elicits input from the client, such as a prompt or resource. */ elicitInput(params: ElicitRequest['params'], options?: RequestOptions): Promise; /** * Lists the root resources available to the client. */ listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<{ [x: string]: unknown; roots: { uri: string; name?: string | undefined; _meta?: Record | undefined; }[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; /** * Sends a logging message to the client. */ sendLoggingMessage(params: LoggingMessageNotification['params']): Promise; /** * Sends a resource updated notification to the client. */ sendResourceUpdated(params: ResourceUpdatedNotification['params']): Promise; /** * Sends a request and wait for a response. * * Do not use this method to emit notifications! Use notification() instead. */ request>(request: SendRequestT, resultSchema: T, options?: RequestOptions): Promise>; /** * Emits a notification, which is a one-way message that does not expect a response. */ notification(notification: SendNotificationT, options?: NotificationOptions): Promise; /** * Registers a handler to invoke when this protocol object receives a request with the given method. * * Note that this will replace any previous request handler for the same method. */ setRequestHandler; }>>(requestSchema: T, handler: (request: z.infer, extra: RequestHandlerExtra) => SendResultT | Promise): void; /** * Removes the request handler for the given method. */ removeRequestHandler(method: string): void; /** * Registers a handler to invoke when this protocol object receives a notification with the given method. * * Note that this will replace any previous notification handler for the same method. */ setNotificationHandler; }>>(notificationSchema: T, handler: (notification: z.infer) => void | Promise): void; /** * Removes the notification handler for the given method. */ removeNotificationHandler(method: string): void; /** * Registers a handler for the subscribe request. */ onSubscribe(handler: (request: SubscribeRequest, extra: RequestHandlerExtra) => SendResultT | Promise): void; /** * Registers a handler for the unsubscribe request. */ onUnsubscribe(handler: (request: UnsubscribeRequest, extra: RequestHandlerExtra) => SendResultT | Promise): void; /** * Registers a handler for the set log level request. */ onSetLogLevel(handler: (request: SetLevelRequest, extra: RequestHandlerExtra) => SendResultT | Promise): void; /** * Registers a handler for the list tools request. */ onListResources(handler: (request: ListResourcesRequest, extra: RequestHandlerExtra) => SendResultT | Promise): void; /** * Registers a handler for the roots list changed notification. */ onRootsListChanged(handler: (notification: RootsListChangedNotification) => void | Promise): void; /** * Close the transport for window.addEventListener('pagehide') */ onPagehide(event: PageTransitionEvent): Promise; } /** * Creates a new MessageChannelServerTransport instance. */ export declare const createMessageChannelServerTransport: (endpoint: string, globalObject?: object) => MessageChannelServerTransport; /** * Creates a pair of transports for communication between a server and client using MessageChannel. */ export declare const createMessageChannelPairTransport: () => [import('@opentiny/next').MessageChannelTransport, import('@opentiny/next').MessageChannelTransport]; /** * Checks if the transport is a MessageChannelServerTransport. */ export declare const isMessageChannelServerTransport: (transport: unknown) => transport is MessageChannelServerTransport; /** * Checks if the server is an instance of MCP Server. */ export declare const isMcpServer: (server: unknown) => server is McpServer; export {};