/** * MCP (Model Context Protocol) integration module for Nevermined Payments. * * This module provides everything needed to build monetizable MCP servers: * - Paywall protection for tools, resources, and prompts * - OAuth 2.1 discovery and client registration endpoints * - Managed HTTP server or router for existing Express apps * * @example Basic usage with withPaywall * ```typescript * import { Payments } from '@nevermined-io/payments' * * const payments = Payments.getInstance({ * nvmApiKey: process.env.NVM_API_KEY!, * environment: 'staging_sandbox' * }) * * // Configure MCP integration * payments.mcp.configure({ * planId: process.env.NVM_PLAN_ID!, // required * agentId: process.env.NVM_AGENT_ID, // optional * serverName: 'my-mcp-server' * }) * * // Protect a tool handler * const protectedHandler = payments.mcp.withPaywall( * myToolHandler, * { kind: 'tool', name: 'my_tool', credits: 1n } * ) * ``` * * @example Complete server with OAuth * ```typescript * // Start a managed server with all OAuth endpoints * const { baseUrl, stop } = await payments.mcp.startServer({ * port: 5001, * planId: process.env.NVM_PLAN_ID!, // required * agentId: process.env.NVM_AGENT_ID, // optional * serverName: 'my-mcp-server', * tools: ['hello_world'] * }) * ``` * * @example Using router with existing Express app * ```typescript * import express from 'express' * * const app = express() * * // Create OAuth router * const router = payments.mcp.createRouter({ * baseUrl: 'http://localhost:5001', * planId: 'plan_123', // required * agentId: 'agent_123', // optional * serverName: 'my-mcp-server' * }) * * app.use(router) * app.listen(5001) * ``` */ import type { Payments } from '../payments.js'; import type { EnvironmentName } from '../environments.js'; import type { McpToolConfig, McpResourceConfig, McpPromptConfig, McpRegistrationOptions, ToolHandler, ResourceHandler, PromptHandler, McpServerConfig, McpServerResult } from './types/server.types.js'; import type { ToolOptions, ResourceOptions, PromptOptions, PaywallContext, McpConfig } from './types/paywall.types.js'; import type { HttpServerResult } from './types/http.types.js'; export type { CreditsContext, CreditsOption, PaywallOptions, McpConfig, PaywallContext, AuthResult, } from './types/paywall.types.js'; export type { OAuthUrls, OAuthConfig, HttpRouterConfig, HttpServerConfig, HttpServerResult, ProtectedResourceMetadata, McpProtectedResourceMetadata, AuthorizationServerMetadata, OidcConfiguration, ClientRegistrationRequest, ClientRegistrationResponse, ServerInfoResponse, } from './types/http.types.js'; export { buildExtraFromHttpHeaders, buildExtraFromHttpRequest } from './utils/extra.js'; export type { McpToolConfig, McpResourceConfig, McpPromptConfig, McpRegistrationOptions, ToolHandler, ResourceHandler, PromptHandler, McpServerConfig, McpServerResult, ServerInfo, ToolContext, ResourceContext, PromptContext, } from './types/server.types.js'; export { getOAuthUrls, buildProtectedResourceMetadata, buildMcpProtectedResourceMetadata, buildAuthorizationServerMetadata, buildOidcConfiguration, buildServerInfoResponse, createOAuthRouter, createCorsMiddleware, createJsonMiddleware, createRequireAuthMiddleware, createHttpLoggingMiddleware, startManagedServer, createMcpApp, ClientRegistrationError, } from './http/index.js'; /** * Extended MCP configuration including HTTP server options. */ export interface ExtendedMcpConfig extends McpConfig { /** Base URL for the server (required for HTTP features) */ baseUrl?: string; /** Nevermined environment */ environment?: EnvironmentName; /** Tools exposed by this server */ tools?: string[]; /** Custom OAuth scopes */ scopes?: string[]; } /** * Options for creating the OAuth router. */ export interface CreateRouterOptions { /** Base URL of the MCP server */ baseUrl: string; /** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */ planId?: string; /** Agent ID (optional; OAuth client_id / informational only) */ agentId?: string; /** Server name */ serverName?: string; /** Tools exposed by this server */ tools?: string[]; /** Enable OAuth discovery endpoints */ enableOAuthDiscovery?: boolean; /** Enable client registration */ enableClientRegistration?: boolean; /** Enable health check */ enableHealthCheck?: boolean; /** Enable server info */ enableServerInfo?: boolean; /** Server version */ version?: string; /** Server description */ description?: string; } /** * Options for starting the managed server. */ export interface StartServerOptions { /** Port to listen on */ port: number; /** Host to bind to */ host?: string; /** Base URL (defaults to http://localhost:\{port\}) */ baseUrl?: string; /** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */ planId?: string; /** Agent ID (optional; OAuth client_id / informational only) */ agentId?: string; /** Server name */ serverName?: string; /** Tools exposed by this server */ tools?: string[]; /** Enable OAuth discovery endpoints */ enableOAuthDiscovery?: boolean; /** Enable client registration */ enableClientRegistration?: boolean; /** Enable health check */ enableHealthCheck?: boolean; /** Enable server info */ enableServerInfo?: boolean; /** Server version */ version?: string; /** Server description */ description?: string; /** Callback when server starts */ onStart?: (result: HttpServerResult) => void; /** Logging callback */ onLog?: (message: string, level?: 'info' | 'warn' | 'error') => void; } /** * Build MCP integration with modular architecture. * This function creates the complete MCP API surface including * paywall protection, OAuth endpoints, and HTTP server management. * * @param paymentsService - The Payments instance * @returns MCP integration API */ export declare function buildMcpIntegration(paymentsService: Payments): { configure: (options: ExtendedMcpConfig) => void; withPaywall: { (handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise | any, options: ToolOptions | PromptOptions): (args: TArgs, extra?: any) => Promise; (handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise | any): (args: TArgs, extra?: any) => Promise; (handler: (uri: URL, variables: Record, extra?: any, context?: PaywallContext) => Promise | any, options: ResourceOptions): (uri: URL, variables: Record, extra?: any) => Promise; }; attach: (server: { registerTool: (name: string, config: any, handler: any) => void; registerResource: (name: string, template: any, config: any, handler: any) => void; registerPrompt: (name: string, config: any, handler: any) => void; }) => { registerTool(name: string, config: any, handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise | any, options?: Omit): void; registerResource(name: string, template: any, config: any, handler: (uri: URL, variables: Record, extra?: any, context?: PaywallContext) => Promise | any, options?: Omit): void; registerPrompt(name: string, config: any, handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise | any, options?: Omit): void; }; authenticateMeta: (extra: any, options: { planId?: string; } | undefined, method: string) => Promise; createRouter: (options: CreateRouterOptions) => import("express").Router; createApp: (options: Omit & { agentId?: string; }) => import("express").Application; startServer: (options: StartServerOptions) => Promise; getConfig: () => ExtendedMcpConfig; registerTool: (name: string, config: McpToolConfig, handler: ToolHandler, options?: McpRegistrationOptions) => void; registerResource: (name: string, uriOrTemplate: string, config: McpResourceConfig, handler: ResourceHandler, options?: McpRegistrationOptions) => void; registerPrompt: (name: string, config: McpPromptConfig, handler: PromptHandler, options?: McpRegistrationOptions) => void; start: (config: McpServerConfig) => Promise; stop: () => Promise; }; //# sourceMappingURL=index.d.ts.map