UNPKG

openai-assistants-mcp

Version:

OpenAI Assistants MCP Server - A Model Context Protocol server providing OpenAI Assistants API tools and resources. Features comprehensive assistant management, thread operations, message handling, and run execution with seamless stdio transport for Claud

150 lines 4.84 kB
/** * Transport Adapters for Thin Deployment Adapters * * This module provides shared transport-specific logic that can be used * by thin deployment adapters to handle protocol-specific concerns while * delegating all business logic to the BaseMCPHandler. */ import { MCPRequest, MCPResponse, MCPError } from '../types/index.js'; /** * Transport adapter interface for deployment-specific implementations */ export interface TransportAdapter { /** Handle transport-specific request preprocessing */ preprocessRequest?(request: MCPRequest): Promise<MCPRequest>; /** Handle transport-specific response postprocessing */ postprocessResponse?(response: MCPResponse): Promise<MCPResponse>; /** Handle transport-specific error formatting */ formatError?(error: MCPError, requestId: string | number | null): MCPResponse; } /** * Cloudflare Workers Transport Adapter * Handles HTTP-specific optimizations for Cloudflare Workers */ export declare class CloudflareWorkerTransportAdapter implements TransportAdapter { preprocessRequest(request: MCPRequest): Promise<MCPRequest>; postprocessResponse(response: MCPResponse): Promise<MCPResponse>; formatError(error: MCPError, requestId: string | number | null): MCPResponse; } /** * HTTP Transport Adapter for Cloudflare Workers * Handles HTTP-specific request/response processing */ export declare class HTTPTransportAdapter { /** * Extract API key from URL path */ extractApiKeyFromPath(pathname: string): { apiKey: string | null; error: MCPResponse | null; }; /** * Parse and validate JSON-RPC request from HTTP body */ parseRequest(request: Request): Promise<{ mcpRequest: MCPRequest | null; error: MCPResponse | null; }>; /** * Create HTTP Response with CORS headers */ createResponse(data: any, status?: number): Response; /** * Create CORS preflight response */ createCORSResponse(): Response; /** * Create method not allowed response */ createMethodNotAllowedResponse(): Response; /** * Create error response with enhanced error details */ createErrorResponse(error: any, requestId?: string | number | null): Response; } /** * Stdio Transport Helper Class * Provides stdio-specific utilities for NPM package deployment */ declare class StdioTransportHelper { private debug; constructor(debug?: boolean); /** * Setup error handling for the process */ setupErrorHandling(): void; /** * Setup stdio interface with readline */ setupStdioInterface(handleInput: (line: string) => Promise<void>): void; /** * Parse and validate JSON-RPC request from stdio line */ parseRequest(line: string): { mcpRequest: MCPRequest | null; error: MCPResponse | null; }; /** * Send response via stdout */ sendResponse(response: MCPResponse): void; /** * Send error response */ sendErrorResponse(id: string | number | null, code: number, message: string, data?: any): void; /** * Create error response */ createErrorResponse(id: string | number | null, code: number, message: string, data?: any): MCPResponse; /** * Create initialize response */ createInitializeResponse(id: string | number, serverName: string, serverVersion: string): MCPResponse; /** * Create initialized notification */ createInitializedNotification(): any; /** * Validate API key from environment */ validateApiKey(): { apiKey: string | null; error: MCPResponse | null; }; /** * Debug logging */ logDebug(...args: any[]): void; /** * Error logging */ logError(...args: any[]): void; } /** * Stdio Transport Adapter that implements the TransportAdapter interface */ export declare class StdioTransportAdapter extends StdioTransportHelper implements TransportAdapter { preprocessRequest(request: MCPRequest): Promise<MCPRequest>; postprocessResponse(response: MCPResponse): Promise<MCPResponse>; formatError(error: MCPError, requestId: string | number | null): MCPResponse; } /** * Alias for backward compatibility */ export declare const ProxyTransportAdapter: typeof CloudflareWorkerTransportAdapter; export declare const LocalDevTransportAdapter: typeof StdioTransportAdapter; /** * Shared request routing logic */ export declare class RequestRouter { /** * Route request to appropriate method */ static getMethodType(method: string): 'initialize' | 'mcp' | 'unknown'; /** * Check if server is initialized for MCP requests */ static requiresInitialization(method: string): boolean; } export {}; //# sourceMappingURL=transport-adapters.d.ts.map