/** * MCP Server Implementation * * Provides a standardized server for Chrome Control specifically designed for * integration with AI Large Language Models (LLMs) through the Model Context * Protocol (MCP). * * This module implements the core MCP server functionality that powers the Chrome Control * system. It handles tool registration, execution, and communication with LLM platforms * through the MCP protocol. * * @module mcp-server * @preferred * * @example * ```typescript * import { McpServer, createTool } from './mcp-server.js'; * import { z } from 'zod'; * * // Create a new MCP server * const server = new McpServer(); * * // Create and register a simple tool * const helloTool = createTool( * 'chrome_hello', * z.object({ name: z.string().optional() }), * async (params) => { * return { * content: [ * { type: 'text', text: `Hello, ${params.name || 'World'}!` } * ] * }; * }, * { description: 'Say hello to someone' } * ); * * // Register the tool with the server * server.registerTool(helloTool); * * // Start the server * await server.start(); * ``` */ import { z } from 'zod'; import { Tool } from './types/tool.js'; /** * Configuration interface for the MCP Server * * Defines the configuration options that can be provided when creating * a new MCP server instance. These options control the server's behavior * and metadata. * * @public */ export interface McpServerConfig { /** * The name of the MCP server * * This name is used in MCP protocol communications and documentation. */ name: string; /** * The version of the MCP server * * Should follow semantic versioning (e.g., "1.4.0"). */ version: string; /** * A brief description of the MCP server * * Explains the purpose and capabilities of the server. */ description: string; /** * URL to the server's documentation or homepage */ homepage: string; /** * The license under which the server is distributed * * Typically "MIT" for Chrome Control. */ license: string; /** * Enable debug mode for additional logging * * When true, the server will output more detailed logs for debugging purposes. */ debug?: boolean; } /** * MCP Server for Chrome Control * * Provides a standardized server for browser automation through MCP, * specifically optimized for LLM integration. This class is the main entry point * for creating and managing an MCP server that exposes browser automation * capabilities to LLMs. * * The server handles tool registration, request processing, and response formatting * according to the MCP protocol specification. It communicates with LLM platforms * through standard input/output streams. * * @example * ```typescript * // Create a new server * const server = new McpServer(); * * // Register tools * registerTools(server); * * // Start the server * await server.start(); * ``` * * @public */ export declare class McpServer { private tools; private config; private sdkServer; private transport; /** * Create a new MCP server * @param config Server configuration */ constructor(config?: Partial); /** * Register a single tool with the server * @param tool Tool to register * @returns The server instance for chaining */ registerTool(tool: Tool): McpServer; /** * Register multiple tools with the server * @param tools Array of tools to register * @returns The server instance for chaining */ registerTools(tools: Tool[]): McpServer; /** * Start the MCP server * @returns Promise that resolves when the server is started */ start(): Promise; /** * Stop the MCP server */ stop(): void; } /** * Creates a Tool instance for use with the MCP server * * This factory function provides a convenient way to create properly typed tool * objects that can be registered with the MCP server. It ensures that all required * fields are present and correctly typed. * * @template T - The Zod schema type used for parameter validation * * @param name - Unique name for the tool (should be prefixed with "chrome_") * @param schema - Zod schema used to validate parameters * @param handler - Async function that implements the tool's functionality * @param options - Tool metadata including description * * @returns A properly typed Tool instance ready for registration * * @example * ```typescript * // Create a navigation tool * const navigateTool = createTool( * 'chrome_navigate', * z.object({ url: z.string() }), * async (params) => { * // Navigation implementation * return { * content: [ * { type: 'text', text: `Navigated to ${params.url}` } * ] * }; * }, * { description: 'Navigate to a URL' } * ); * ``` * * @public */ export declare function createTool(name: string, schema: T, handler: (params: z.infer) => Promise<{ content: Array<{ type: string; text: string | { src: string; alt: string; }; }>; }>, options: { description: string; }): Tool; //# sourceMappingURL=mcp-server.d.ts.map