import { SemanticLayerCompiler, SecurityContext } from '../server/index.js'; import { MCPPrompt } from '../server/ai/mcp-prompts.js'; import { McpAppConfig } from './utils.js'; export type { McpAppConfig }; export { type MCPPrompt }; export declare const MCP_APP_RESOURCE_URI = "ui://drizzle-cube/visualization.html"; export declare const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app"; /** Get the bundled MCP App HTML, optionally with locale config injected. Returns empty string if not yet built. */ export declare function getMcpAppHtml(config?: McpAppConfig): string; export type JsonRpcId = string | number | null | undefined; export interface JsonRpcRequest { jsonrpc: '2.0'; id?: JsonRpcId; method: string; params?: unknown; } export interface JsonRpcResponse { jsonrpc: '2.0'; id: JsonRpcId; result?: unknown; error?: { code: number; message: string; data?: unknown; }; } export interface McpDispatchContext { semanticLayer: SemanticLayerCompiler; extractSecurityContext: (req: any, res: any) => SecurityContext | Promise; rawRequest: unknown; rawResponse: unknown; negotiatedProtocol?: string | null; resources?: MCPResource[]; prompts?: MCPPrompt[]; /** * Pre-resolved instructions string returned in the `initialize` result * (`InitializeResult.instructions` per MCP spec). When omitted, falls * back to `getDefaultMcpInstructions()`. Adapters resolve this from the * `MCPOptions.instructions` resolver before calling `dispatchMcpMethod`. */ instructions?: string; /** Enable MCP App visualization for load tool */ appEnabled?: boolean; /** Locale configuration for the MCP App (only used when appEnabled is true) */ appConfig?: McpAppConfig; /** Optional name for the MCP serverInfo.name field. Defaults to 'drizzle-cube'. */ serverName?: string; } export interface MCPResource { uri: string; name: string; description: string; mimeType: string; text: string; } export type MCPPromptResolver = MCPPrompt[] | ((defaults: MCPPrompt[]) => MCPPrompt[]); export type MCPResourceResolver = MCPResource[] | ((defaults: MCPResource[]) => MCPResource[]); export type MCPInstructionsResolver = string | ((defaults: string) => string); export interface ProtocolNegotiation { ok: boolean; negotiated: string | null; supported: string[]; } export declare const SUPPORTED_MCP_PROTOCOLS: string[]; export declare const DEFAULT_MCP_PROTOCOL = "2025-11-25"; export declare function negotiateProtocol(headers: Record): ProtocolNegotiation; export declare function wantsEventStream(accept: string | null | undefined): boolean; /** * MCP Session ID header name (per 2025-11-25 spec) */ export declare const MCP_SESSION_ID_HEADER = "mcp-session-id"; /** * MCP Protocol Version header name (per 2025-11-25 spec) */ export declare const MCP_PROTOCOL_VERSION_HEADER = "mcp-protocol-version"; /** * Validate the Accept header per MCP 2025-11-25 spec. * Client MUST include both `application/json` and `text/event-stream` as supported content types. * * @returns true if valid, false if invalid */ export declare function validateAcceptHeader(accept: string | null | undefined): boolean; export interface OriginValidationOptions { /** * List of allowed origins (e.g., ['http://localhost:3000', 'https://myapp.com']) * If not provided, defaults to localhost origins only */ allowedOrigins?: string[]; /** * If true, allows requests without an Origin header (non-browser clients) * @default true */ allowMissingOrigin?: boolean; } /** * Validate the Origin header per MCP 2025-11-25 spec. * Servers MUST validate Origin to prevent DNS rebinding attacks. * If Origin is present and invalid, MUST respond with 403 Forbidden. * * @returns { valid: true } if allowed, or { valid: false, reason: string } if blocked */ export declare function validateOriginHeader(origin: string | null | undefined, options?: OriginValidationOptions): { valid: true; } | { valid: false; reason: string; }; /** * Extract a Bearer token from an Authorization header. * Returns the token string if present and well-formed, or null otherwise. */ export declare function extractBearerToken(authHeader: string | null | undefined): string | null; /** * Build a WWW-Authenticate challenge header value per MCP / RFC 9728. * Points the client to the Protected Resource Metadata document so it can * discover the authorization server and begin the OAuth 2.1 flow. */ export declare function buildWwwAuthenticateChallenge(resourceMetadataUrl: string): string; export declare function serializeSseEvent(payload: unknown, eventId?: string, retryMs?: number): string; export declare function buildJsonRpcError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcResponse; export declare function buildJsonRpcResult(id: JsonRpcId, result: unknown): JsonRpcResponse; export declare function parseJsonRpc(body: unknown): JsonRpcRequest | null; export declare function dispatchMcpMethod(method: string, params: unknown, ctx: McpDispatchContext): Promise; export declare function jsonRpcError(code: number, message: string, data?: unknown): Error & { code: number; data?: unknown; }; export declare function normalizeHeader(value: string | string[] | undefined): string | null; export declare function isNotification(request: JsonRpcRequest): boolean; export declare function primeEventId(): string; export declare function buildToolList(options?: { appEnabled?: boolean; }): { name: string; description: string; inputSchema: Record; _meta?: unknown; }[]; export declare function getDefaultResources(): MCPResource[]; export declare function getDefaultPrompts(): MCPPrompt[]; /** * Default instructions string returned in `InitializeResult.instructions`. * Re-exported here so adapter consumers don't need to reach into `server/ai`. */ export declare function getDefaultInstructions(): string; export declare function resolveMcpPrompts(prompts?: MCPPromptResolver): MCPPrompt[]; export declare function resolveMcpResources(resources?: MCPResourceResolver): MCPResource[]; /** * Resolve the MCP instructions string for the `initialize` response. * * - `undefined` → returns the built-in defaults. * - `string` → replaces the defaults entirely. * - `(defaults) => string` → derive from / extend the defaults (e.g. append * project-specific guidance like custom cube semantics). */ export declare function resolveMcpInstructions(instructions?: MCPInstructionsResolver): string; export declare function buildMcpSchemaResource(semanticLayer: SemanticLayerCompiler): MCPResource; export declare function buildMcpResources(semanticLayer: SemanticLayerCompiler, resources?: MCPResourceResolver): MCPResource[];