/** * Express Router for OAuth 2.1 endpoints. * Provides a pre-configured router with all OAuth discovery and registration endpoints * that can be mounted on any Express application. */ import { type Router, type Request, type Response, type NextFunction } from 'express'; import type { Payments } from '../../payments.js'; import type { HttpRouterConfig } from '../types/http.types.js'; /** * Options for creating the OAuth router. */ export interface OAuthRouterOptions extends HttpRouterConfig { /** Payments instance for authentication */ payments: Payments; /** Server version for info endpoint */ version?: string; /** Server description for info endpoint */ description?: string; /** Optional logging callback (no logs by default) */ onLog?: (message: string) => void; } /** * Create an Express router with OAuth 2.1 discovery and registration endpoints. * This router can be mounted on any Express application to add OAuth support. * * @param options - Router configuration options * @returns Express Router with OAuth endpoints * * @example * ```typescript * import express from 'express' * import { Payments } from '@nevermined-io/payments' * * const app = express() * const payments = Payments.getInstance({ nvmApiKey: '...', environment: 'staging_sandbox' }) * * // Create and mount the OAuth router * const oauthRouter = createOAuthRouter({ * payments, * baseUrl: 'http://localhost:5001', * agentId: 'agent_123', * environment: 'staging_sandbox', * serverName: 'my-mcp-server', * tools: ['hello_world'] * }) * * app.use(oauthRouter) * app.listen(5001) * ``` */ export declare function createOAuthRouter(options: OAuthRouterOptions): Router; /** * Apply CORS headers to an Express application. * This is a utility function for setting up CORS in MCP servers. * * @param origins - Allowed origins (default: '*') * @returns Express middleware for CORS */ export declare function createCorsMiddleware(origins?: string | string[]): (req: Request, res: Response, next: NextFunction) => void; /** * Create a JSON body parser middleware that ensures JSON responses. * This wraps express.json() and adds response formatting. * * @returns Express middleware for JSON parsing */ export declare function createJsonMiddleware(): (req: Request, res: Response, next: NextFunction) => void; /** * Create a middleware that requires a Bearer token in the Authorization header. * Returns HTTP 401 if the token is missing or malformed. * * This is a lightweight check that only verifies presence of a token. * Full validation (is the token valid? does the user have access?) is handled * by withPaywall() when a tool is actually called. * * @returns Express middleware for token requirement * * @example * ```typescript * const requireAuth = createRequireAuthMiddleware() * * // Protect MCP endpoints * app.post('/mcp', requireAuth, mcpHandler) * app.get('/mcp', requireAuth, sseHandler) * ``` */ export declare function createRequireAuthMiddleware(): (req: Request, res: Response, next: NextFunction) => void; /** * Create a middleware that logs all HTTP requests to endpoints. * Logs method, URL, IP address, and relevant headers. * * @param onLog - Optional logging callback. If not provided, does nothing. * @returns Express middleware for HTTP request logging * * @example * ```typescript * const logMiddleware = createHttpLoggingMiddleware((msg) => console.log(msg)) * app.use(logMiddleware) * ``` */ export declare function createHttpLoggingMiddleware(onLog?: (message: string) => void): (req: Request, res: Response, next: NextFunction) => void; //# sourceMappingURL=oauth-router.d.ts.map