import { RequestHandler } from 'express'; /** * API Key Authentication * * Simple authentication for basic scenarios. * Perfect for service-to-service communication or development. */ export interface APIKeyConfig { /** * Array of valid API keys * Can be plain strings or hashed values */ keys: string[]; /** * If true, keys are stored as SHA-256 hashes (recommended) */ hashed?: boolean; /** * Header name to extract API key from * Default: 'X-API-Key' */ headerName?: string; /** * Also accept API key in query parameter? * Default: false (not recommended for production) */ allowQueryParam?: boolean; /** * Query parameter name * Default: 'api_key' */ queryParamName?: string; /** * Custom key validation */ customValidation?: (key: string) => Promise | boolean; } /** * Create API Key authentication middleware * * @example * ```typescript * const server = createServer({...}); * * // Simple API key auth * server.app.use('/mcp', createAPIKeyAuth({ * keys: [ * process.env.API_KEY_1!, * process.env.API_KEY_2!, * ], * headerName: 'X-API-Key', * })); * * server.start(); * * // Client usage: * // curl -H "X-API-Key: your-api-key" https://mcp.example.com/mcp/tools * ``` */ export declare function createAPIKeyAuth(config: APIKeyConfig): RequestHandler; /** * Generate a secure API key * * @example * ```typescript * const apiKey = generateAPIKey(); * console.log('API Key:', apiKey); * // Save to .env: API_KEY_1=sk_... * ``` */ export declare function generateAPIKey(prefix?: string): string; /** * Hash an API key (SHA-256) * Use this to store hashed keys instead of plain text * * @example * ```typescript * const apiKey = 'sk_abc123...'; * const hashed = hashAPIKey(apiKey); * // Store hashed in database * * // In config: * createAPIKeyAuth({ * keys: [hashed], * hashed: true, * }); * ``` */ export declare function hashAPIKey(key: string): string; /** * Validate API key format */ export declare function isValidAPIKeyFormat(key: string, prefix?: string): boolean; /** * Create API key with metadata (advanced) */ export interface APIKeyWithMetadata { key: string; hashed: string; name: string; createdAt: Date; expiresAt?: Date; scopes?: string[]; } export declare function generateAPIKeyWithMetadata(options: { name: string; prefix?: string; expiresIn?: number; scopes?: string[]; }): APIKeyWithMetadata; /** * Validate API key with metadata (expiration, scopes) */ export declare function validateAPIKeyWithMetadata(key: string, metadata: Omit, requiredScopes?: string[]): { valid: boolean; reason?: string; }; //# sourceMappingURL=api-key.d.ts.map