/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Server } from './server.js'; import type { Config } from './types/config.js'; import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { z } from 'zod'; import type { CDPRelay } from './cdp-relay.js'; import type { BrowserContextFactory } from './browserContextFactory.js'; import type { FullConfig } from './config.js'; import type { Connection } from './connection.js'; /** * Custom tool definition interface */ export interface CustomTool { name: string; title: string; description: string; inputSchema: z.Schema; capability: string; type?: 'readOnly' | 'destructive'; handler: (params: any) => Promise<{ content?: Array<{ type: 'text' | 'image'; text?: string; data?: string; mimeType?: string; }>; isError?: boolean; }>; } /** * Custom resource definition interface */ export interface CustomResource { uri: string; name: string; description?: string; mimeType?: string; handler: () => Promise<{ contents: Array<{ uri: string; mimeType?: string; text?: string; blob?: string; }>; }>; } /** * Custom prompt definition interface */ export interface CustomPrompt { name: string; description?: string; arguments?: Record; handler: (args: any) => Promise<{ messages: Array<{ role: 'user' | 'assistant'; content: { type: 'text' | 'image'; text?: string; data?: string; mimeType?: string; }; }>; }>; } /** * Shadow items configuration - hide specific standard tools/prompts/resources * Supports wildcard patterns using '*' (e.g., "browser_*", "*_test", "*middle*") */ export interface ShadowItems { tools?: string[]; prompts?: string[]; resources?: string[]; } /** * Server builder options */ export interface ServerBuilderOptions { config?: Config; cdpRelay?: CDPRelay; shadowItems?: ShadowItems; } /** * Enhanced server with custom components */ export declare class EnhancedServer extends Server { private _customTools; private _customResources; private _customPrompts; private _shadowItems; constructor(config: FullConfig, options?: { cdpRelay?: CDPRelay; shadowItems?: ShadowItems; }); getCustomTools(): CustomTool[]; getCustomResources(): CustomResource[]; getCustomPrompts(): CustomPrompt[]; getShadowItems(): ShadowItems; addCustomTool(tool: CustomTool): void; addCustomResource(resource: CustomResource): void; addCustomPrompt(prompt: CustomPrompt): void; setShadowItems(shadowItems: ShadowItems): void; /** * Override createConnection to use enhanced connection */ createConnection(transport: Transport): Promise; /** * Create enhanced connection with custom components */ createEnhancedConnection(browserContextFactory: BrowserContextFactory, transport: Transport): Promise; } /** * Server builder for creating servers with custom tools, resources, and prompts */ export declare class ServerBuilder { private _config; private _customTools; private _customResources; private _customPrompts; private _shadowItems; private _cdpRelay?; /** * Set server configuration */ config(config: Config): ServerBuilder; /** * Set CDP relay */ cdpRelay(cdpRelay: CDPRelay): ServerBuilder; /** * Set shadow items to hide standard tools/prompts/resources */ shadowItems(shadowItems: ShadowItems): ServerBuilder; /** * Add a custom tool */ addTool(tool: CustomTool): ServerBuilder; /** * Add multiple custom tools */ addTools(tools: CustomTool[]): ServerBuilder; /** * Add a custom resource */ addResource(resource: CustomResource): ServerBuilder; /** * Add multiple custom resources */ addResources(resources: CustomResource[]): ServerBuilder; /** * Add a custom prompt */ addPrompt(prompt: CustomPrompt): ServerBuilder; /** * Add multiple custom prompts */ addPrompts(prompts: CustomPrompt[]): ServerBuilder; /** * Build the enhanced server */ build(): Promise; } /** * Create a new server builder */ export declare function createServerBuilder(options?: ServerBuilderOptions): ServerBuilder; /** * Utility function to create a simple tool */ export declare function createTool(name: string, description: string, inputSchema: z.Schema, handler: CustomTool['handler'], options?: { title?: string; capability?: string; type?: 'readOnly' | 'destructive'; }): CustomTool; /** * Utility function to create a simple resource */ export declare function createResource(uri: string, name: string, handler: CustomResource['handler'], options?: { description?: string; mimeType?: string; }): CustomResource; /** * Utility function to create a simple prompt */ export declare function createPrompt(name: string, handler: CustomPrompt['handler'], options?: { description?: string; arguments?: Record; }): CustomPrompt;