@nevermined-io/payments 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/mcp/core/auth.d.ts +2 -2
- package/dist/mcp/core/auth.d.ts.map +1 -1
- package/dist/mcp/core/auth.js +29 -18
- package/dist/mcp/core/auth.js.map +1 -1
- package/dist/mcp/core/paywall.d.ts.map +1 -1
- package/dist/mcp/core/paywall.js +10 -6
- package/dist/mcp/core/paywall.js.map +1 -1
- package/dist/mcp/core/server-manager.d.ts.map +1 -1
- package/dist/mcp/core/server-manager.js +6 -4
- package/dist/mcp/core/server-manager.js.map +1 -1
- package/dist/mcp/http/client-registration.d.ts.map +1 -1
- package/dist/mcp/http/client-registration.js +4 -2
- package/dist/mcp/http/client-registration.js.map +1 -1
- package/dist/mcp/http/oauth-metadata.d.ts.map +1 -1
- package/dist/mcp/http/oauth-metadata.js +2 -1
- package/dist/mcp/http/oauth-metadata.js.map +1 -1
- package/dist/mcp/index.d.ts +12 -5
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +46 -23
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types/http.types.d.ts +2 -2
- package/dist/mcp/types/http.types.d.ts.map +1 -1
- package/dist/mcp/types/http.types.js.map +1 -1
- package/dist/mcp/types/paywall.types.d.ts +6 -2
- package/dist/mcp/types/paywall.types.d.ts.map +1 -1
- package/dist/mcp/types/paywall.types.js.map +1 -1
- package/dist/mcp/types/server.types.d.ts +4 -2
- package/dist/mcp/types/server.types.d.ts.map +1 -1
- package/dist/mcp/types/server.types.js.map +1 -1
- package/dist/payments.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-registration.js","sourceRoot":"","sources":["../../../src/mcp/http/client-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CA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oBAAoB,CAAA;IAE/F,iBAAiB;IACjB,MAAM,QAAQ,GAA+B;QAC3C,SAAS,EAAE,QAAQ;QACnB,mBAAmB,EAAE,QAAQ;QAC7B,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,YAAY;QAChD,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QACnE,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC,oBAAoB,CAAC;QAC1D,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC,MAAM,CAAC;QAClD,0BAA0B,EAAE,UAAU;KACvC,CAAA;IAED,mCAAmC;IACnC,IAAI,WAAW,EAAE,CAAC;QAChB,QAAQ,CAAC,aAAa,GAAG,oBAAoB,EAAE,CAAA;QAC/C,QAAQ,CAAC,wBAAwB,GAAG,CAAC,CAAA,CAAC,wBAAwB;IAChE,CAAC;IAED,kCAAkC;IAClC,IAAI,OAAO,CAAC,UAAU;QAAE,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;IAChE,IAAI,OAAO,CAAC,QAAQ;QAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAC1D,IAAI,OAAO,CAAC,QAAQ;QAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAE1D,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["/**\n * OAuth Dynamic Client Registration handler (RFC 7591).\n * Handles client registration requests for MCP OAuth flows.\n */\nimport { randomBytes } from 'crypto'\nimport type {\n OAuthConfig,\n ClientRegistrationRequest,\n ClientRegistrationResponse,\n} from '../types/http.types.js'\n\n/**\n * Default scopes for client registration.\n */\nconst DEFAULT_SCOPES = ['openid', 'profile', 'credits', 'mcp:read', 'mcp:write', 'mcp:tools']\n\n/**\n * Validation error for client registration.\n */\nexport class ClientRegistrationError extends Error {\n public readonly errorCode: string\n public readonly statusCode: number\n\n constructor(errorCode: string, message: string, statusCode = 400) {\n super(message)\n this.name = 'ClientRegistrationError'\n this.errorCode = errorCode\n this.statusCode = statusCode\n }\n\n /**\n * Get the error response body.\n */\n toJSON(): { error: string; error_description: string } {\n return {\n error: this.errorCode,\n error_description: this.message,\n }\n }\n}\n\n/**\n * Check if a request body is an OAuth Dynamic Client Registration request.\n *\n * @param body - The request body to check\n * @returns True if the body looks like a client registration request\n */\nexport function isClientRegistrationRequest(body: unknown): body is ClientRegistrationRequest {\n if (!body || typeof body !== 'object') return false\n\n const obj = body as Record<string, unknown>\n return !!(\n obj.redirect_uris ||\n obj.grant_types ||\n obj.token_endpoint_auth_method ||\n obj.response_types ||\n obj.client_name\n )\n}\n\n/**\n * Validate a client registration request.\n *\n * @param request - The client registration request\n * @throws ClientRegistrationError if validation fails\n */\nexport function validateClientRegistrationRequest(request: ClientRegistrationRequest): void {\n // redirect_uris is required and must be a non-empty array\n if (\n !request.redirect_uris ||\n !Array.isArray(request.redirect_uris) ||\n request.redirect_uris.length === 0\n ) {\n throw new ClientRegistrationError(\n 'invalid_request',\n 'redirect_uris is required and must be a non-empty array',\n )\n }\n\n // Validate each redirect_uri is a valid URL\n for (const uri of request.redirect_uris) {\n try {\n new URL(uri)\n } catch {\n throw new ClientRegistrationError('invalid_redirect_uri', `Invalid redirect_uri: ${uri}`)\n }\n }\n\n // Validate grant_types if provided\n const validGrantTypes = ['authorization_code', 'refresh_token', 'client_credentials']\n if (request.grant_types) {\n for (const grantType of request.grant_types) {\n if (!validGrantTypes.includes(grantType)) {\n throw new ClientRegistrationError(\n 'invalid_client_metadata',\n `Unsupported grant_type: ${grantType}`,\n )\n }\n }\n }\n\n // Validate response_types if provided\n const validResponseTypes = ['code', 'token']\n if (request.response_types) {\n for (const responseType of request.response_types) {\n if (!validResponseTypes.includes(responseType)) {\n throw new ClientRegistrationError(\n 'invalid_client_metadata',\n `Unsupported response_type: ${responseType}`,\n )\n }\n }\n }\n\n // Validate token_endpoint_auth_method if provided\n const validAuthMethods = ['none', 'client_secret_basic', 'client_secret_post']\n if (\n request.token_endpoint_auth_method &&\n !validAuthMethods.includes(request.token_endpoint_auth_method)\n ) {\n throw new ClientRegistrationError(\n 'invalid_client_metadata',\n `Unsupported token_endpoint_auth_method: ${request.token_endpoint_auth_method}`,\n )\n }\n}\n\n/**\n * Generate a cryptographically secure client secret.\n *\n * @returns A base64url-encoded random string\n */\nfunction generateClientSecret(): string {\n return randomBytes(32).toString('base64url')\n}\n\n/**\n * Process a client registration request and generate a response.\n *\n * @param request - The validated client registration request\n * @param config - OAuth configuration\n * @returns Client registration response\n *\n * @example\n * ```typescript\n * const response = await processClientRegistration(\n * { redirect_uris: ['http://localhost:3000/callback'], client_name: 'My App' },\n * { agentId: 'agent_123', baseUrl: 'http://localhost:5001', environment: 'staging_sandbox' }\n * )\n * ```\n */\nexport async function processClientRegistration(\n request: ClientRegistrationRequest,\n config: OAuthConfig,\n): Promise<ClientRegistrationResponse> {\n // Validate the request\n validateClientRegistrationRequest(request)\n\n // client_id = the configured agentId when present (stable for this server);\n // agentId is optional under the plan-centric model, so when it's absent we\n // issue a generated client_id for OAuth dynamic registration.\n const issuedAt = Math.floor(Date.now() / 1000)\n const clientId = config.agentId ?? `nvm-mcp-client-${issuedAt}-${randomBytes(8).toString('hex')}`\n\n // Determine auth method and if secret is needed\n const authMethod = request.token_endpoint_auth_method || 'none'\n const needsSecret = authMethod === 'client_secret_basic' || authMethod === 'client_secret_post'\n\n // Build response\n const response: ClientRegistrationResponse = {\n client_id: clientId,\n client_id_issued_at: issuedAt,\n client_name: request.client_name || 'MCP Client',\n redirect_uris: request.redirect_uris,\n scope: request.scope || (config.scopes || DEFAULT_SCOPES).join(' '),\n grant_types: request.grant_types || ['authorization_code'],\n response_types: request.response_types || ['code'],\n token_endpoint_auth_method: authMethod,\n }\n\n // Generate client_secret if needed\n if (needsSecret) {\n response.client_secret = generateClientSecret()\n response.client_secret_expires_at = 0 // 0 means never expires\n }\n\n // Add optional fields if provided\n if (request.client_uri) response.client_uri = request.client_uri\n if (request.logo_uri) response.logo_uri = request.logo_uri\n if (request.contacts) response.contacts = request.contacts\n\n return response\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-metadata.d.ts","sourceRoot":"","sources":["../../../src/mcp/http/oauth-metadata.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC1E,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,yBAAyB,EACzB,4BAA4B,EAC5B,2BAA2B,EAC3B,iBAAiB,EAClB,MAAM,wBAAwB,CAAA;AAiD/B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAC7B,SAAS,CAGX;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,WAAW,GAAG,yBAAyB,CAY7F;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,WAAW,GAClB,4BAA4B,CAiB9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,WAAW,GAAG,2BAA2B,CAiBjG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,CAqB7E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GACA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,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C,EAAE,MAAM,CAAA;CACrB,GACA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CA8BA"}
|
|
@@ -218,7 +218,8 @@ export function buildServerInfoResponse(config, options) {
|
|
|
218
218
|
token_endpoint: oauthUrls.tokenUri,
|
|
219
219
|
jwks_uri: oauthUrls.jwksUri,
|
|
220
220
|
registration_endpoint: `${config.baseUrl}/register`,
|
|
221
|
-
client_id
|
|
221
|
+
// agentId is optional under the plan-centric model; omit client_id when absent.
|
|
222
|
+
...(config.agentId ? { client_id: config.agentId } : {}),
|
|
222
223
|
scopes: scopes,
|
|
223
224
|
},
|
|
224
225
|
tools: config.tools || [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-metadata.js","sourceRoot":"","sources":["../../../src/mcp/http/oauth-metadata.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAwB,MAAM,uBAAuB,CAAA;AAU1E;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,WAAmB,EAAE,UAAkB;IAC7D,0BAA0B;IAC1B,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAE7C,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,gBAAgB,EAAE,GAAG,QAAQ,kBAAkB;QAC/C,QAAQ,EAAE,GAAG,OAAO,cAAc;Q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AAC,CAAA;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,cAAc,CAAC,CAAA;IAEnD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,UAAU,IAAI,YAAY;QACvC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO;QACpC,WAAW,EACT,OAAO,EAAE,WAAW,IAAI,kEAAkE;QAC5F,SAAS,EAAE;YACT,GAAG,EAAE,GAAG,MAAM,CAAC,OAAO,MAAM;YAC5B,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,SAAS;YAClC,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,WAAW;SACvC;QACD,KAAK,EAAE;YACL,6BAA6B,EAAE,GAAG,MAAM,CAAC,OAAO,yCAAyC;YACzF,2BAA2B,EAAE,GAAG,MAAM,CAAC,OAAO,uCAAuC;YACrF,oBAAoB,EAAE,GAAG,MAAM,CAAC,OAAO,mCAAmC;YAC1E,sBAAsB,EAAE,SAAS,CAAC,gBAAgB;YAClD,cAAc,EAAE,SAAS,CAAC,QAAQ;YAClC,QAAQ,EAAE,SAAS,CAAC,OAAO;YAC3B,qBAAqB,EAAE,GAAG,MAAM,CAAC,OAAO,WAAW;YACnD,SAAS,EAAE,MAAM,CAAC,OAAO;YACzB,MAAM,EAAE,MAAM;SACf;QACD,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;QACjC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;KAC9B,CAAA;AACH,CAAC","sourcesContent":["/**\n * Pure functions to generate OAuth 2.1 metadata responses.\n * These generators produce the JSON payloads for OAuth discovery endpoints\n * without any framework dependencies, making them reusable across different HTTP servers.\n */\nimport { Environments, type EnvironmentName } from '../../environments.js'\nimport type {\n OAuthUrls,\n OAuthConfig,\n ProtectedResourceMetadata,\n McpProtectedResourceMetadata,\n AuthorizationServerMetadata,\n OidcConfiguration,\n} from '../types/http.types.js'\n\n/**\n * Build OAuth URLs from frontend and backend URLs.\n * - issuer and authorizationUri use the frontend (user-facing)\n * - tokenUri, jwksUri, userinfoUri use the backend (API)\n *\n * @param frontendUrl - The frontend URL (e.g., https://nevermined.app)\n * @param backendUrl - The backend URL (e.g., https://api.sandbox.nevermined.app)\n * @returns OAuth URLs configuration\n */\nfunction buildOAuthUrls(frontendUrl: string, backendUrl: string): OAuthUrls {\n // Remove trailing slashes\n const frontend = frontendUrl.replace(/\\/$/, '')\n const backend = backendUrl.replace(/\\/$/, '')\n\n return {\n issuer: frontend,\n authorizationUri: `${frontend}/oauth/authorize`,\n tokenUri: `${backend}/oauth/token`,\n jwksUri: `${backend}/.well-known/jwks.json`,\n userinfoUri: `${backend}/oauth/userinfo`,\n }\n}\n\n/**\n * Get OAuth URLs for an environment.\n * Uses frontend and backend URLs from Environments configuration.\n *\n * @param environment - The Nevermined environment name\n * @returns OAuth URLs configuration\n */\nfunction getOAuthUrlsForEnvironment(environment: EnvironmentName): OAuthUrls {\n const envConfig = Environments[environment] || Environments.sandbox\n return buildOAuthUrls(envConfig.frontend, envConfig.backend)\n}\n\n/**\n * Default scopes supported by Nevermined MCP servers.\n */\nconst DEFAULT_SCOPES: readonly string[] = [\n 'openid',\n 'profile',\n 'credits',\n 'mcp:read',\n 'mcp:write',\n 'mcp:tools',\n]\n\n/**\n * Get OAuth URLs for a given environment with optional overrides.\n *\n * @param environment - The Nevermined environment name\n * @param overrides - Optional partial overrides for specific URLs\n * @returns Complete OAuth URLs configuration\n */\nexport function getOAuthUrls(\n environment: EnvironmentName,\n overrides?: Partial<OAuthUrls>,\n): OAuthUrls {\n const baseUrls = getOAuthUrlsForEnvironment(environment)\n return { ...baseUrls, ...overrides }\n}\n\n/**\n * Build Protected Resource Metadata (RFC 9728).\n * This metadata tells OAuth clients about the protected resource.\n *\n * @param config - OAuth configuration\n * @returns Protected Resource Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildProtectedResourceMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * // Returns: { resource: 'http://localhost:5001', authorization_servers: [...], ... }\n * ```\n */\nexport function buildProtectedResourceMetadata(config: OAuthConfig): ProtectedResourceMetadata {\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n // oauthUrls calculated but not used in this metadata (kept for future use)\n void getOAuthUrls(config.environment, config.oauthUrls)\n\n return {\n resource: config.baseUrl,\n authorization_servers: [config.baseUrl],\n scopes_supported: scopes,\n bearer_methods_supported: ['header'],\n resource_documentation: `${config.baseUrl}/`,\n }\n}\n\n/**\n * Build MCP-specific Protected Resource Metadata.\n * Extends the base metadata with MCP capabilities information.\n *\n * @param config - OAuth configuration\n * @returns MCP Protected Resource Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildMcpProtectedResourceMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox',\n * tools: ['hello_world', 'weather']\n * })\n * ```\n */\nexport function buildMcpProtectedResourceMetadata(\n config: OAuthConfig,\n): McpProtectedResourceMetadata {\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n // oauthUrls calculated but not used in this metadata (kept for future use)\n void getOAuthUrls(config.environment, config.oauthUrls)\n\n return {\n resource: `${config.baseUrl}/mcp`,\n authorization_servers: [config.baseUrl],\n scopes_supported: scopes,\n scopes_required: scopes,\n bearer_methods_supported: ['header'],\n resource_documentation: `${config.baseUrl}/`,\n mcp_capabilities: {\n tools: config.tools || [],\n protocol_version: config.protocolVersion || '2024-11-05',\n },\n }\n}\n\n/**\n * Build OAuth Authorization Server Metadata (RFC 8414).\n * This metadata describes the OAuth authorization server configuration.\n *\n * @param config - OAuth configuration\n * @returns Authorization Server Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildAuthorizationServerMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * ```\n */\nexport function buildAuthorizationServerMetadata(config: OAuthConfig): AuthorizationServerMetadata {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n\n return {\n issuer: oauthUrls.issuer,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n registration_endpoint: `${config.baseUrl}/register`,\n jwks_uri: oauthUrls.jwksUri,\n response_types_supported: ['code'],\n grant_types_supported: ['authorization_code', 'refresh_token'],\n code_challenge_methods_supported: ['S256'],\n scopes_supported: scopes,\n token_endpoint_auth_methods_supported: ['client_secret_post'],\n subject_types_supported: ['public'],\n }\n}\n\n/**\n * Build OpenID Connect Discovery Metadata.\n * Provides OIDC-compatible configuration for clients that expect OpenID Connect.\n *\n * @param config - OAuth configuration\n * @returns OIDC Configuration response object\n *\n * @example\n * ```typescript\n * const metadata = buildOidcConfiguration({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * ```\n */\nexport function buildOidcConfiguration(config: OAuthConfig): OidcConfiguration {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n const allScopes = scopes.includes('openid') ? scopes : ['openid', ...scopes]\n\n return {\n issuer: oauthUrls.issuer,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n jwks_uri: oauthUrls.jwksUri,\n userinfo_endpoint: oauthUrls.userinfoUri,\n registration_endpoint: `${config.baseUrl}/register`,\n response_types_supported: ['code'],\n grant_types_supported: ['authorization_code', 'refresh_token'],\n code_challenge_methods_supported: ['S256'],\n token_endpoint_auth_methods_supported: ['none', 'client_secret_post'],\n subject_types_supported: ['public'],\n id_token_signing_alg_values_supported: ['RS256', 'HS256'],\n scopes_supported: allScopes,\n claims_supported: ['sub', 'iss', 'aud', 'exp', 'iat', 'name', 'email'],\n }\n}\n\n/**\n * Build server info response for the root endpoint.\n *\n * @param config - OAuth configuration\n * @param options - Additional options for the server info\n * @returns Server info response object\n */\nexport function buildServerInfoResponse(\n config: OAuthConfig,\n options?: {\n version?: string\n description?: string\n },\n): {\n name: string\n version: string\n description: string\n endpoints: Record<string, string>\n oauth: Record<string, any>\n tools: string[]\n resources: string[]\n prompts: string[]\n} {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n\n return {\n name: config.serverName || 'MCP Server',\n version: options?.version || '1.0.0',\n description:\n options?.description || 'MCP server with Nevermined OAuth integration via Streamable HTTP',\n endpoints: {\n mcp: `${config.baseUrl}/mcp`,\n health: `${config.baseUrl}/health`,\n register: `${config.baseUrl}/register`,\n },\n oauth: {\n authorization_server_metadata: `${config.baseUrl}/.well-known/oauth-authorization-server`,\n protected_resource_metadata: `${config.baseUrl}/.well-known/oauth-protected-resource`,\n openid_configuration: `${config.baseUrl}/.well-known/openid-configuration`,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n jwks_uri: oauthUrls.jwksUri,\n registration_endpoint: `${config.baseUrl}/register`,\n client_id: config.agentId,\n scopes: scopes,\n },\n tools: config.tools || [],\n resources: config.resources || [],\n prompts: config.prompts || [],\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"oauth-metadata.js","sourceRoot":"","sources":["../../../src/mcp/http/oauth-metadata.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAwB,MAAM,uBAAuB,CAAA;AAU1E;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,WAAmB,EAAE,UAAkB;IAC7D,0BAA0B;IAC1B,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAE7C,OAAO;QACL,MAAM,EAAE,QAA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ators produce the JSON payloads for OAuth discovery endpoints\n * without any framework dependencies, making them reusable across different HTTP servers.\n */\nimport { Environments, type EnvironmentName } from '../../environments.js'\nimport type {\n OAuthUrls,\n OAuthConfig,\n ProtectedResourceMetadata,\n McpProtectedResourceMetadata,\n AuthorizationServerMetadata,\n OidcConfiguration,\n} from '../types/http.types.js'\n\n/**\n * Build OAuth URLs from frontend and backend URLs.\n * - issuer and authorizationUri use the frontend (user-facing)\n * - tokenUri, jwksUri, userinfoUri use the backend (API)\n *\n * @param frontendUrl - The frontend URL (e.g., https://nevermined.app)\n * @param backendUrl - The backend URL (e.g., https://api.sandbox.nevermined.app)\n * @returns OAuth URLs configuration\n */\nfunction buildOAuthUrls(frontendUrl: string, backendUrl: string): OAuthUrls {\n // Remove trailing slashes\n const frontend = frontendUrl.replace(/\\/$/, '')\n const backend = backendUrl.replace(/\\/$/, '')\n\n return {\n issuer: frontend,\n authorizationUri: `${frontend}/oauth/authorize`,\n tokenUri: `${backend}/oauth/token`,\n jwksUri: `${backend}/.well-known/jwks.json`,\n userinfoUri: `${backend}/oauth/userinfo`,\n }\n}\n\n/**\n * Get OAuth URLs for an environment.\n * Uses frontend and backend URLs from Environments configuration.\n *\n * @param environment - The Nevermined environment name\n * @returns OAuth URLs configuration\n */\nfunction getOAuthUrlsForEnvironment(environment: EnvironmentName): OAuthUrls {\n const envConfig = Environments[environment] || Environments.sandbox\n return buildOAuthUrls(envConfig.frontend, envConfig.backend)\n}\n\n/**\n * Default scopes supported by Nevermined MCP servers.\n */\nconst DEFAULT_SCOPES: readonly string[] = [\n 'openid',\n 'profile',\n 'credits',\n 'mcp:read',\n 'mcp:write',\n 'mcp:tools',\n]\n\n/**\n * Get OAuth URLs for a given environment with optional overrides.\n *\n * @param environment - The Nevermined environment name\n * @param overrides - Optional partial overrides for specific URLs\n * @returns Complete OAuth URLs configuration\n */\nexport function getOAuthUrls(\n environment: EnvironmentName,\n overrides?: Partial<OAuthUrls>,\n): OAuthUrls {\n const baseUrls = getOAuthUrlsForEnvironment(environment)\n return { ...baseUrls, ...overrides }\n}\n\n/**\n * Build Protected Resource Metadata (RFC 9728).\n * This metadata tells OAuth clients about the protected resource.\n *\n * @param config - OAuth configuration\n * @returns Protected Resource Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildProtectedResourceMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * // Returns: { resource: 'http://localhost:5001', authorization_servers: [...], ... }\n * ```\n */\nexport function buildProtectedResourceMetadata(config: OAuthConfig): ProtectedResourceMetadata {\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n // oauthUrls calculated but not used in this metadata (kept for future use)\n void getOAuthUrls(config.environment, config.oauthUrls)\n\n return {\n resource: config.baseUrl,\n authorization_servers: [config.baseUrl],\n scopes_supported: scopes,\n bearer_methods_supported: ['header'],\n resource_documentation: `${config.baseUrl}/`,\n }\n}\n\n/**\n * Build MCP-specific Protected Resource Metadata.\n * Extends the base metadata with MCP capabilities information.\n *\n * @param config - OAuth configuration\n * @returns MCP Protected Resource Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildMcpProtectedResourceMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox',\n * tools: ['hello_world', 'weather']\n * })\n * ```\n */\nexport function buildMcpProtectedResourceMetadata(\n config: OAuthConfig,\n): McpProtectedResourceMetadata {\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n // oauthUrls calculated but not used in this metadata (kept for future use)\n void getOAuthUrls(config.environment, config.oauthUrls)\n\n return {\n resource: `${config.baseUrl}/mcp`,\n authorization_servers: [config.baseUrl],\n scopes_supported: scopes,\n scopes_required: scopes,\n bearer_methods_supported: ['header'],\n resource_documentation: `${config.baseUrl}/`,\n mcp_capabilities: {\n tools: config.tools || [],\n protocol_version: config.protocolVersion || '2024-11-05',\n },\n }\n}\n\n/**\n * Build OAuth Authorization Server Metadata (RFC 8414).\n * This metadata describes the OAuth authorization server configuration.\n *\n * @param config - OAuth configuration\n * @returns Authorization Server Metadata response object\n *\n * @example\n * ```typescript\n * const metadata = buildAuthorizationServerMetadata({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * ```\n */\nexport function buildAuthorizationServerMetadata(config: OAuthConfig): AuthorizationServerMetadata {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n\n return {\n issuer: oauthUrls.issuer,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n registration_endpoint: `${config.baseUrl}/register`,\n jwks_uri: oauthUrls.jwksUri,\n response_types_supported: ['code'],\n grant_types_supported: ['authorization_code', 'refresh_token'],\n code_challenge_methods_supported: ['S256'],\n scopes_supported: scopes,\n token_endpoint_auth_methods_supported: ['client_secret_post'],\n subject_types_supported: ['public'],\n }\n}\n\n/**\n * Build OpenID Connect Discovery Metadata.\n * Provides OIDC-compatible configuration for clients that expect OpenID Connect.\n *\n * @param config - OAuth configuration\n * @returns OIDC Configuration response object\n *\n * @example\n * ```typescript\n * const metadata = buildOidcConfiguration({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * environment: 'staging_sandbox'\n * })\n * ```\n */\nexport function buildOidcConfiguration(config: OAuthConfig): OidcConfiguration {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n const allScopes = scopes.includes('openid') ? scopes : ['openid', ...scopes]\n\n return {\n issuer: oauthUrls.issuer,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n jwks_uri: oauthUrls.jwksUri,\n userinfo_endpoint: oauthUrls.userinfoUri,\n registration_endpoint: `${config.baseUrl}/register`,\n response_types_supported: ['code'],\n grant_types_supported: ['authorization_code', 'refresh_token'],\n code_challenge_methods_supported: ['S256'],\n token_endpoint_auth_methods_supported: ['none', 'client_secret_post'],\n subject_types_supported: ['public'],\n id_token_signing_alg_values_supported: ['RS256', 'HS256'],\n scopes_supported: allScopes,\n claims_supported: ['sub', 'iss', 'aud', 'exp', 'iat', 'name', 'email'],\n }\n}\n\n/**\n * Build server info response for the root endpoint.\n *\n * @param config - OAuth configuration\n * @param options - Additional options for the server info\n * @returns Server info response object\n */\nexport function buildServerInfoResponse(\n config: OAuthConfig,\n options?: {\n version?: string\n description?: string\n },\n): {\n name: string\n version: string\n description: string\n endpoints: Record<string, string>\n oauth: Record<string, any>\n tools: string[]\n resources: string[]\n prompts: string[]\n} {\n const oauthUrls = getOAuthUrls(config.environment, config.oauthUrls)\n const scopes = config.scopes || [...DEFAULT_SCOPES]\n\n return {\n name: config.serverName || 'MCP Server',\n version: options?.version || '1.0.0',\n description:\n options?.description || 'MCP server with Nevermined OAuth integration via Streamable HTTP',\n endpoints: {\n mcp: `${config.baseUrl}/mcp`,\n health: `${config.baseUrl}/health`,\n register: `${config.baseUrl}/register`,\n },\n oauth: {\n authorization_server_metadata: `${config.baseUrl}/.well-known/oauth-authorization-server`,\n protected_resource_metadata: `${config.baseUrl}/.well-known/oauth-protected-resource`,\n openid_configuration: `${config.baseUrl}/.well-known/openid-configuration`,\n authorization_endpoint: oauthUrls.authorizationUri,\n token_endpoint: oauthUrls.tokenUri,\n jwks_uri: oauthUrls.jwksUri,\n registration_endpoint: `${config.baseUrl}/register`,\n // agentId is optional under the plan-centric model; omit client_id when absent.\n ...(config.agentId ? { client_id: config.agentId } : {}),\n scopes: scopes,\n },\n tools: config.tools || [],\n resources: config.resources || [],\n prompts: config.prompts || [],\n }\n}\n"]}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
*
|
|
18
18
|
* // Configure MCP integration
|
|
19
19
|
* payments.mcp.configure({
|
|
20
|
-
*
|
|
20
|
+
* planId: process.env.NVM_PLAN_ID!, // required
|
|
21
|
+
* agentId: process.env.NVM_AGENT_ID, // optional
|
|
21
22
|
* serverName: 'my-mcp-server'
|
|
22
23
|
* })
|
|
23
24
|
*
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
* // Start a managed server with all OAuth endpoints
|
|
34
35
|
* const { baseUrl, stop } = await payments.mcp.startServer({
|
|
35
36
|
* port: 5001,
|
|
36
|
-
*
|
|
37
|
+
* planId: process.env.NVM_PLAN_ID!, // required
|
|
38
|
+
* agentId: process.env.NVM_AGENT_ID, // optional
|
|
37
39
|
* serverName: 'my-mcp-server',
|
|
38
40
|
* tools: ['hello_world']
|
|
39
41
|
* })
|
|
@@ -48,7 +50,8 @@
|
|
|
48
50
|
* // Create OAuth router
|
|
49
51
|
* const router = payments.mcp.createRouter({
|
|
50
52
|
* baseUrl: 'http://localhost:5001',
|
|
51
|
-
*
|
|
53
|
+
* planId: 'plan_123', // required
|
|
54
|
+
* agentId: 'agent_123', // optional
|
|
52
55
|
* serverName: 'my-mcp-server'
|
|
53
56
|
* })
|
|
54
57
|
*
|
|
@@ -85,7 +88,9 @@ export interface ExtendedMcpConfig extends McpConfig {
|
|
|
85
88
|
export interface CreateRouterOptions {
|
|
86
89
|
/** Base URL of the MCP server */
|
|
87
90
|
baseUrl: string;
|
|
88
|
-
/**
|
|
91
|
+
/** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */
|
|
92
|
+
planId?: string;
|
|
93
|
+
/** Agent ID (optional; OAuth client_id / informational only) */
|
|
89
94
|
agentId?: string;
|
|
90
95
|
/** Server name */
|
|
91
96
|
serverName?: string;
|
|
@@ -114,7 +119,9 @@ export interface StartServerOptions {
|
|
|
114
119
|
host?: string;
|
|
115
120
|
/** Base URL (defaults to http://localhost:\{port\}) */
|
|
116
121
|
baseUrl?: string;
|
|
117
|
-
/**
|
|
122
|
+
/** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */
|
|
123
|
+
planId?: string;
|
|
124
|
+
/** Agent ID (optional; OAuth client_id / informational only) */
|
|
118
125
|
agentId?: string;
|
|
119
126
|
/** Server name */
|
|
120
127
|
serverName?: string;
|
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAQzD,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAEV,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACd,SAAS,EACV,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,YAAY,EACV,cAAc,EACd,aAAa,EACb,cAAc,EACd,SAAS,EACT,cAAc,EACd,UAAU,GACX,MAAM,0BAA0B,CAAA;AAEjC,YAAY,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,2BAA2B,EAC3B,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAGvF,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,eA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|
|
|
4
4
|
import { PaywallAuthenticator } from './core/auth.js';
|
|
5
5
|
import { CreditsContextProvider } from './core/credits-context.js';
|
|
6
6
|
import { createServerManager } from './core/server-manager.js';
|
|
7
|
+
import { ERROR_CODES, createRpcError } from './utils/errors.js';
|
|
7
8
|
// Re-export utilities
|
|
8
9
|
export { buildExtraFromHttpHeaders, buildExtraFromHttpRequest } from './utils/extra.js';
|
|
9
10
|
// Re-export HTTP module components for advanced usage
|
|
@@ -22,7 +23,7 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
22
23
|
const paywallDecorator = new PaywallDecorator(paymentsService, authenticator, creditsContext);
|
|
23
24
|
// Extended configuration storage
|
|
24
25
|
let extendedConfig = {
|
|
25
|
-
|
|
26
|
+
planId: '',
|
|
26
27
|
serverName: 'mcp-server',
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
@@ -34,8 +35,9 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
34
35
|
* @example
|
|
35
36
|
* ```typescript
|
|
36
37
|
* payments.mcp.configure({
|
|
37
|
-
*
|
|
38
|
+
* planId: 'plan_123', // required
|
|
38
39
|
* serverName: 'my-mcp-server',
|
|
40
|
+
* agentId: 'agent_123', // optional
|
|
39
41
|
* baseUrl: 'http://localhost:5001',
|
|
40
42
|
* environment: 'staging_sandbox',
|
|
41
43
|
* tools: ['hello_world', 'weather']
|
|
@@ -49,12 +51,19 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
49
51
|
};
|
|
50
52
|
// Also configure the paywall decorator
|
|
51
53
|
paywallDecorator.configure({
|
|
54
|
+
planId: options.planId,
|
|
52
55
|
agentId: options.agentId,
|
|
53
56
|
serverName: options.serverName,
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
59
|
function withPaywall(handler, options) {
|
|
57
60
|
const opts = options ?? { kind: 'tool', name: 'unnamed' };
|
|
61
|
+
// Fail fast at registration time: a planId must be resolvable from the
|
|
62
|
+
// per-tool option or the server-level config. Otherwise a misconfiguration
|
|
63
|
+
// would only surface on the first tool call.
|
|
64
|
+
if (!opts.planId && !extendedConfig.planId) {
|
|
65
|
+
throw createRpcError(ERROR_CODES.Misconfiguration, 'Server misconfiguration: missing planId');
|
|
66
|
+
}
|
|
58
67
|
return paywallDecorator.protect(handler, opts);
|
|
59
68
|
}
|
|
60
69
|
/**
|
|
@@ -66,9 +75,9 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
66
75
|
*/
|
|
67
76
|
async function authenticateMeta(extra, options = {}, method) {
|
|
68
77
|
const cfg = extendedConfig;
|
|
69
|
-
const agentId = cfg.agentId ||
|
|
78
|
+
const agentId = cfg.agentId || undefined;
|
|
70
79
|
const serverName = cfg.serverName || 'mcp-server';
|
|
71
|
-
return authenticator.authenticateMeta(extra, { planId: options?.planId }, agentId, serverName, method);
|
|
80
|
+
return authenticator.authenticateMeta(extra, { planId: options?.planId ?? cfg.planId }, agentId, serverName, method);
|
|
72
81
|
}
|
|
73
82
|
/**
|
|
74
83
|
* Attach paywall protection to an MCP server.
|
|
@@ -97,6 +106,28 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
97
106
|
},
|
|
98
107
|
};
|
|
99
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolve the effective agentId/serverName/environment for an OAuth transport
|
|
111
|
+
* from per-call options layered over the server-level config, and configure
|
|
112
|
+
* the paywall so tools protected via withPaywall settle on the resolved plan
|
|
113
|
+
* (per-call option wins over a prior configure()). Shared by
|
|
114
|
+
* createRouter/createApp/startServer.
|
|
115
|
+
*
|
|
116
|
+
* agentId is optional under the plan-centric model (informational/OAuth
|
|
117
|
+
* client_id only); the OAuth router omits client_id when it's absent. planId
|
|
118
|
+
* is the paywall's concern — the OAuth transports below do not consume it.
|
|
119
|
+
*/
|
|
120
|
+
function resolveTransportConfig(options) {
|
|
121
|
+
const agentId = options.agentId || extendedConfig.agentId;
|
|
122
|
+
const serverName = options.serverName || extendedConfig.serverName || 'mcp-server';
|
|
123
|
+
configure({
|
|
124
|
+
planId: options.planId ?? extendedConfig.planId,
|
|
125
|
+
agentId,
|
|
126
|
+
serverName,
|
|
127
|
+
});
|
|
128
|
+
const environment = extendedConfig.environment || paymentsService.environmentName || 'staging_sandbox';
|
|
129
|
+
return { agentId, serverName, environment };
|
|
130
|
+
}
|
|
100
131
|
/**
|
|
101
132
|
* Create an Express router with OAuth 2.1 endpoints.
|
|
102
133
|
* Use this when you already have an Express app and want to add OAuth support.
|
|
@@ -108,6 +139,7 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
108
139
|
* ```typescript
|
|
109
140
|
* const router = payments.mcp.createRouter({
|
|
110
141
|
* baseUrl: 'http://localhost:5001',
|
|
142
|
+
* planId: 'plan_123', // required
|
|
111
143
|
* serverName: 'my-mcp-server',
|
|
112
144
|
* tools: ['hello_world']
|
|
113
145
|
* })
|
|
@@ -116,17 +148,13 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
116
148
|
* ```
|
|
117
149
|
*/
|
|
118
150
|
function createRouter(options) {
|
|
119
|
-
const agentId = options
|
|
120
|
-
if (!agentId) {
|
|
121
|
-
throw new Error('agentId is required. Either pass it in options or call configure() first.');
|
|
122
|
-
}
|
|
123
|
-
const environment = extendedConfig.environment || paymentsService.environmentName || 'staging_sandbox';
|
|
151
|
+
const { agentId, serverName, environment } = resolveTransportConfig(options);
|
|
124
152
|
return createOAuthRouter({
|
|
125
153
|
payments: paymentsService,
|
|
126
154
|
baseUrl: options.baseUrl,
|
|
127
155
|
agentId,
|
|
128
156
|
environment,
|
|
129
|
-
serverName
|
|
157
|
+
serverName,
|
|
130
158
|
tools: options.tools || extendedConfig.tools || [],
|
|
131
159
|
scopes: extendedConfig.scopes,
|
|
132
160
|
enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,
|
|
@@ -151,6 +179,7 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
151
179
|
* ```typescript
|
|
152
180
|
* const app = payments.mcp.createApp({
|
|
153
181
|
* baseUrl: 'http://localhost:5001',
|
|
182
|
+
* planId: 'plan_123', // required
|
|
154
183
|
* serverName: 'my-mcp-server'
|
|
155
184
|
* })
|
|
156
185
|
*
|
|
@@ -161,17 +190,13 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
161
190
|
* ```
|
|
162
191
|
*/
|
|
163
192
|
function createApp(options) {
|
|
164
|
-
const agentId = options
|
|
165
|
-
if (!agentId) {
|
|
166
|
-
throw new Error('agentId is required. Either pass it in options or call configure() first.');
|
|
167
|
-
}
|
|
168
|
-
const environment = extendedConfig.environment || paymentsService.environmentName || 'staging_sandbox';
|
|
193
|
+
const { agentId, serverName, environment } = resolveTransportConfig(options);
|
|
169
194
|
return createMcpApp({
|
|
170
195
|
payments: paymentsService,
|
|
171
196
|
baseUrl: options.baseUrl,
|
|
172
197
|
agentId,
|
|
173
198
|
environment,
|
|
174
|
-
serverName
|
|
199
|
+
serverName,
|
|
175
200
|
tools: options.tools || extendedConfig.tools || [],
|
|
176
201
|
scopes: extendedConfig.scopes,
|
|
177
202
|
enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,
|
|
@@ -193,6 +218,7 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
193
218
|
* ```typescript
|
|
194
219
|
* const { baseUrl, stop } = await payments.mcp.startServer({
|
|
195
220
|
* port: 5001,
|
|
221
|
+
* planId: process.env.NVM_PLAN_ID!, // required
|
|
196
222
|
* serverName: 'my-mcp-server',
|
|
197
223
|
* tools: ['hello_world', 'weather']
|
|
198
224
|
* })
|
|
@@ -204,12 +230,8 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
204
230
|
* ```
|
|
205
231
|
*/
|
|
206
232
|
async function startServer(options) {
|
|
207
|
-
const agentId = options
|
|
208
|
-
if (!agentId) {
|
|
209
|
-
throw new Error('agentId is required. Either pass it in options or call configure() first.');
|
|
210
|
-
}
|
|
233
|
+
const { agentId, serverName, environment } = resolveTransportConfig(options);
|
|
211
234
|
const baseUrl = options.baseUrl || `http://localhost:${options.port}`;
|
|
212
|
-
const environment = extendedConfig.environment || paymentsService.environmentName || 'staging_sandbox';
|
|
213
235
|
return startManagedServer({
|
|
214
236
|
payments: paymentsService,
|
|
215
237
|
port: options.port,
|
|
@@ -217,7 +239,7 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
217
239
|
baseUrl,
|
|
218
240
|
agentId,
|
|
219
241
|
environment,
|
|
220
|
-
serverName
|
|
242
|
+
serverName,
|
|
221
243
|
tools: options.tools || extendedConfig.tools || [],
|
|
222
244
|
scopes: extendedConfig.scopes,
|
|
223
245
|
enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,
|
|
@@ -320,7 +342,8 @@ export function buildMcpIntegration(paymentsService) {
|
|
|
320
342
|
* // Then start the server
|
|
321
343
|
* const { info, stop } = await payments.mcp.start({
|
|
322
344
|
* port: 5001,
|
|
323
|
-
*
|
|
345
|
+
* planId: 'plan_123', // required
|
|
346
|
+
* agentId: 'did:nv:...', // optional
|
|
324
347
|
* serverName: 'my-mcp-server'
|
|
325
348
|
* })
|
|
326
349
|
*
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AA4DA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAoB,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AA+ChF,sBAAsB;AACtB,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAmBvF,sDAAsD;AACtD,OAAO,EACL,YAAY,EACZ,8BAA8B,EAC9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AAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACpF,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,cAAc,CACrB,IAAY,EACZ,MAAuB,EACvB,OAA4B,EAC5B,OAAgC;QAEhC,gBAAgB,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,KAAK,UAAU,KAAK,CAAC,MAAuB;QAC1C,OAAO,gBAAgB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK,UAAU,IAAI;QACjB,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,aAAa,CAAC,IAAI,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO;QACL,4CAA4C;QAC5C,SAAS;QACT,WAAW;QACX,MAAM;QACN,gBAAgB;QAEhB,0CAA0C;QAC1C,YAAY;QACZ,SAAS;QACT,WAAW;QAEX,YAAY;QACZ,SAAS;QAET,8CAA8C;QAC9C,YAAY;QACZ,gBAAgB;QAChB,cAAc;QACd,KAAK;QACL,IAAI;KACL,CAAA;AACH,CAAC","sourcesContent":["/**\n * MCP (Model Context Protocol) integration module for Nevermined Payments.\n *\n * This module provides everything needed to build monetizable MCP servers:\n * - Paywall protection for tools, resources, and prompts\n * - OAuth 2.1 discovery and client registration endpoints\n * - Managed HTTP server or router for existing Express apps\n *\n * @example Basic usage with withPaywall\n * ```typescript\n * import { Payments } from '@nevermined-io/payments'\n *\n * const payments = Payments.getInstance({\n * nvmApiKey: process.env.NVM_API_KEY!,\n * environment: 'staging_sandbox'\n * })\n *\n * // Configure MCP integration\n * payments.mcp.configure({\n * agentId: process.env.NVM_AGENT_ID!,\n * serverName: 'my-mcp-server'\n * })\n *\n * // Protect a tool handler\n * const protectedHandler = payments.mcp.withPaywall(\n * myToolHandler,\n * { kind: 'tool', name: 'my_tool', credits: 1n }\n * )\n * ```\n *\n * @example Complete server with OAuth\n * ```typescript\n * // Start a managed server with all OAuth endpoints\n * const { baseUrl, stop } = await payments.mcp.startServer({\n * port: 5001,\n * agentId: process.env.NVM_AGENT_ID!,\n * serverName: 'my-mcp-server',\n * tools: ['hello_world']\n * })\n * ```\n *\n * @example Using router with existing Express app\n * ```typescript\n * import express from 'express'\n *\n * const app = express()\n *\n * // Create OAuth router\n * const router = payments.mcp.createRouter({\n * baseUrl: 'http://localhost:5001',\n * agentId: 'agent_123',\n * serverName: 'my-mcp-server'\n * })\n *\n * app.use(router)\n * app.listen(5001)\n * ```\n */\nimport type { Payments } from '../payments.js'\nimport type { EnvironmentName } from '../environments.js'\nimport { createOAuthRouter } from './http/oauth-router.js'\nimport { createMcpApp, startManagedServer } from './http/managed-server.js'\nimport { PaywallDecorator } from './core/paywall.js'\nimport { PaywallAuthenticator } from './core/auth.js'\nimport { CreditsContextProvider } from './core/credits-context.js'\nimport { McpServerManager, createServerManager } from './core/server-manager.js'\nimport type {\n McpToolConfig,\n McpResourceConfig,\n McpPromptConfig,\n McpRegistrationOptions,\n ToolHandler,\n ResourceHandler,\n PromptHandler,\n McpServerConfig,\n McpServerResult,\n} from './types/server.types.js'\nimport type {\n PaywallOptions,\n ToolOptions,\n ResourceOptions,\n PromptOptions,\n PaywallContext,\n McpConfig,\n} from './types/paywall.types.js'\nimport type { HttpServerResult } from './types/http.types.js'\n\n// Re-export types\nexport type {\n CreditsContext,\n CreditsOption,\n PaywallOptions,\n McpConfig,\n PaywallContext,\n AuthResult,\n} from './types/paywall.types.js'\n\nexport type {\n OAuthUrls,\n OAuthConfig,\n HttpRouterConfig,\n HttpServerConfig,\n HttpServerResult,\n ProtectedResourceMetadata,\n McpProtectedResourceMetadata,\n AuthorizationServerMetadata,\n OidcConfiguration,\n ClientRegistrationRequest,\n ClientRegistrationResponse,\n ServerInfoResponse,\n} from './types/http.types.js'\n\n// Re-export utilities\nexport { buildExtraFromHttpHeaders, buildExtraFromHttpRequest } from './utils/extra.js'\n\n// Re-export simplified API types\nexport type {\n McpToolConfig,\n McpResourceConfig,\n McpPromptConfig,\n McpRegistrationOptions,\n ToolHandler,\n ResourceHandler,\n PromptHandler,\n McpServerConfig,\n McpServerResult,\n ServerInfo,\n ToolContext,\n ResourceContext,\n PromptContext,\n} from './types/server.types.js'\n\n// Re-export HTTP module components for advanced usage\nexport {\n getOAuthUrls,\n buildProtectedResourceMetadata,\n buildMcpProtectedResourceMetadata,\n buildAuthorizationServerMetadata,\n buildOidcConfiguration,\n buildServerInfoResponse,\n createOAuthRouter,\n createCorsMiddleware,\n createJsonMiddleware,\n createRequireAuthMiddleware,\n createHttpLoggingMiddleware,\n startManagedServer,\n createMcpApp,\n ClientRegistrationError,\n} from './http/index.js'\n\n/**\n * Extended MCP configuration including HTTP server options.\n */\nexport interface ExtendedMcpConfig extends McpConfig {\n /** Base URL for the server (required for HTTP features) */\n baseUrl?: string\n /** Nevermined environment */\n environment?: EnvironmentName\n /** Tools exposed by this server */\n tools?: string[]\n /** Custom OAuth scopes */\n scopes?: string[]\n}\n\n/**\n * Options for creating the OAuth router.\n */\nexport interface CreateRouterOptions {\n /** Base URL of the MCP server */\n baseUrl: string\n /** Agent ID (client_id) */\n agentId?: string\n /** Server name */\n serverName?: string\n /** Tools exposed by this server */\n tools?: string[]\n /** Enable OAuth discovery endpoints */\n enableOAuthDiscovery?: boolean\n /** Enable client registration */\n enableClientRegistration?: boolean\n /** Enable health check */\n enableHealthCheck?: boolean\n /** Enable server info */\n enableServerInfo?: boolean\n /** Server version */\n version?: string\n /** Server description */\n description?: string\n}\n\n/**\n * Options for starting the managed server.\n */\nexport interface StartServerOptions {\n /** Port to listen on */\n port: number\n /** Host to bind to */\n host?: string\n /** Base URL (defaults to http://localhost:\\{port\\}) */\n baseUrl?: string\n /** Agent ID (uses configured agentId if not provided) */\n agentId?: string\n /** Server name */\n serverName?: string\n /** Tools exposed by this server */\n tools?: string[]\n /** Enable OAuth discovery endpoints */\n enableOAuthDiscovery?: boolean\n /** Enable client registration */\n enableClientRegistration?: boolean\n /** Enable health check */\n enableHealthCheck?: boolean\n /** Enable server info */\n enableServerInfo?: boolean\n /** Server version */\n version?: string\n /** Server description */\n description?: string\n /** Callback when server starts */\n onStart?: (result: HttpServerResult) => void\n /** Logging callback */\n onLog?: (message: string, level?: 'info' | 'warn' | 'error') => void\n}\n\n/**\n * Build MCP integration with modular architecture.\n * This function creates the complete MCP API surface including\n * paywall protection, OAuth endpoints, and HTTP server management.\n *\n * @param paymentsService - The Payments instance\n * @returns MCP integration API\n */\nexport function buildMcpIntegration(paymentsService: Payments) {\n const authenticator = new PaywallAuthenticator(paymentsService)\n const creditsContext = new CreditsContextProvider()\n const paywallDecorator = new PaywallDecorator(paymentsService, authenticator, creditsContext)\n\n // Extended configuration storage\n let extendedConfig: ExtendedMcpConfig = {\n agentId: '',\n serverName: 'mcp-server',\n }\n\n /**\n * Configure the MCP integration.\n * This sets up the agent ID, server name, and optional HTTP settings.\n *\n * @param options - Configuration options\n *\n * @example\n * ```typescript\n * payments.mcp.configure({\n * agentId: 'agent_123',\n * serverName: 'my-mcp-server',\n * baseUrl: 'http://localhost:5001',\n * environment: 'staging_sandbox',\n * tools: ['hello_world', 'weather']\n * })\n * ```\n */\n function configure(options: ExtendedMcpConfig): void {\n extendedConfig = {\n ...extendedConfig,\n ...options,\n }\n // Also configure the paywall decorator\n paywallDecorator.configure({\n agentId: options.agentId,\n serverName: options.serverName,\n })\n }\n\n /**\n * Wrap a handler with paywall protection.\n * The wrapped handler will validate authentication and burn credits.\n */\n function withPaywall<TArgs = any>(\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options: ToolOptions | PromptOptions,\n ): (args: TArgs, extra?: any) => Promise<any>\n function withPaywall<TArgs = any>(\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n ): (args: TArgs, extra?: any) => Promise<any>\n function withPaywall(\n handler: (\n uri: URL,\n variables: Record<string, string | string[]>,\n extra?: any,\n context?: PaywallContext,\n ) => Promise<any> | any,\n options: ResourceOptions,\n ): (uri: URL, variables: Record<string, string | string[]>, extra?: any) => Promise<any>\n function withPaywall(handler: any, options?: ToolOptions | PromptOptions | ResourceOptions): any {\n const opts =\n (options as PaywallOptions | undefined) ?? ({ kind: 'tool', name: 'unnamed' } as any)\n return (paywallDecorator.protect as any)(handler, opts)\n }\n\n /**\n * Authenticate meta MCP operations (initialize, tools/list, etc.).\n *\n * @param extra - The extra parameter from MCP\n * @param method - The MCP method being called\n * @returns Authentication result\n */\n async function authenticateMeta(extra: any, options: {planId?: string} = {}, method: string) {\n const cfg = extendedConfig\n const agentId = cfg.agentId || ''\n const serverName = cfg.serverName || 'mcp-server'\n return authenticator.authenticateMeta(extra, { planId: options?.planId }, agentId, serverName, method)\n }\n\n /**\n * Attach paywall protection to an MCP server.\n * Returns a registrar with protected register methods.\n *\n * @param server - The MCP server instance\n * @returns Protected registrar\n */\n function attach(server: {\n registerTool: (name: string, config: any, handler: any) => void\n registerResource: (name: string, template: any, config: any, handler: any) => void\n registerPrompt: (name: string, config: any, handler: any) => void\n }) {\n return {\n registerTool<TArgs = any>(\n name: string,\n config: any,\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options?: Omit<ToolOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, { kind: 'tool', name, ...(options || {}) })\n server.registerTool(name, config, protectedHandler)\n },\n registerResource(\n name: string,\n template: any,\n config: any,\n handler: (\n uri: URL,\n variables: Record<string, string | string[]>,\n extra?: any,\n context?: PaywallContext,\n ) => Promise<any> | any,\n options?: Omit<ResourceOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, {\n kind: 'resource',\n name,\n ...(options || {}),\n })\n server.registerResource(name, template, config, protectedHandler)\n },\n registerPrompt<TArgs = any>(\n name: string,\n config: any,\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options?: Omit<PromptOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, { kind: 'prompt', name, ...(options || {}) })\n server.registerPrompt(name, config, protectedHandler)\n },\n }\n }\n\n /**\n * Create an Express router with OAuth 2.1 endpoints.\n * Use this when you already have an Express app and want to add OAuth support.\n *\n * @param options - Router configuration\n * @returns Express Router\n *\n * @example\n * ```typescript\n * const router = payments.mcp.createRouter({\n * baseUrl: 'http://localhost:5001',\n * serverName: 'my-mcp-server',\n * tools: ['hello_world']\n * })\n *\n * app.use(router)\n * ```\n */\n function createRouter(options: CreateRouterOptions) {\n const agentId = options.agentId || extendedConfig.agentId\n if (!agentId) {\n throw new Error('agentId is required. Either pass it in options or call configure() first.')\n }\n\n const environment =\n extendedConfig.environment || (paymentsService as any).environmentName || 'staging_sandbox'\n\n return createOAuthRouter({\n payments: paymentsService,\n baseUrl: options.baseUrl,\n agentId,\n environment,\n serverName: options.serverName || extendedConfig.serverName || 'mcp-server',\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n })\n }\n\n /**\n * Create an Express app pre-configured with OAuth discovery endpoints.\n * Use this when you want more control over the app before starting.\n *\n * Note: Authentication is handled by withPaywall() on each tool,\n * not by HTTP middleware.\n *\n * @param options - App configuration\n * @returns Configured Express app with OAuth endpoints\n *\n * @example\n * ```typescript\n * const app = payments.mcp.createApp({\n * baseUrl: 'http://localhost:5001',\n * serverName: 'my-mcp-server'\n * })\n *\n * // Add your MCP handler - auth via withPaywall() on each tool\n * app.post('/mcp', mcpHandler)\n *\n * app.listen(5001)\n * ```\n */\n function createApp(options: Omit<CreateRouterOptions, 'agentId'> & { agentId?: string }) {\n const agentId = options.agentId || extendedConfig.agentId\n if (!agentId) {\n throw new Error('agentId is required. Either pass it in options or call configure() first.')\n }\n\n const environment =\n extendedConfig.environment || (paymentsService as any).environmentName || 'staging_sandbox'\n\n return createMcpApp({\n payments: paymentsService,\n baseUrl: options.baseUrl,\n agentId,\n environment,\n serverName: options.serverName || extendedConfig.serverName || 'mcp-server',\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n })\n }\n\n /**\n * Start a managed HTTP server with OAuth 2.1 support.\n * This creates a complete Express server with all OAuth endpoints pre-configured.\n *\n * @param options - Server configuration\n * @returns Server result with control methods\n *\n * @example\n * ```typescript\n * const { baseUrl, stop } = await payments.mcp.startServer({\n * port: 5001,\n * serverName: 'my-mcp-server',\n * tools: ['hello_world', 'weather']\n * })\n *\n * console.log(`Server running at ${baseUrl}`)\n *\n * // Later: gracefully stop\n * await stop()\n * ```\n */\n async function startServer(options: StartServerOptions): Promise<HttpServerResult> {\n const agentId = options.agentId || extendedConfig.agentId\n if (!agentId) {\n throw new Error('agentId is required. Either pass it in options or call configure() first.')\n }\n\n const baseUrl = options.baseUrl || `http://localhost:${options.port}`\n const environment =\n extendedConfig.environment || (paymentsService as any).environmentName || 'staging_sandbox'\n\n return startManagedServer({\n payments: paymentsService,\n port: options.port,\n host: options.host,\n baseUrl,\n agentId,\n environment,\n serverName: options.serverName || extendedConfig.serverName || 'mcp-server',\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n onStart: options.onStart,\n onLog: options.onLog,\n })\n }\n\n /**\n * Get the current configuration.\n *\n * @returns Current MCP configuration\n */\n function getConfig(): ExtendedMcpConfig {\n return { ...extendedConfig }\n }\n\n // =============================================================================\n // SIMPLIFIED API - High-level API that hides McpServer, Transport, and Express\n // =============================================================================\n\n // Server manager for simplified API\n let serverManager: McpServerManager | null = null\n\n /**\n * Get or create the server manager.\n */\n function getServerManager(): McpServerManager {\n if (!serverManager) {\n serverManager = createServerManager(paymentsService)\n }\n return serverManager\n }\n\n /**\n * Register a tool with the simplified API.\n * Must be called before start().\n *\n * @param name - Tool name\n * @param config - Tool configuration\n * @param handler - Tool handler function\n * @param options - Registration options (credits, etc.)\n *\n * @example\n * ```typescript\n * payments.mcp.registerTool(\n * 'hello_world',\n * {\n * description: 'Returns a hello world message',\n * inputSchema: { name: { type: 'string' } }\n * },\n * async (args: { name: string }, context?: ToolContext) => ({\n * content: [{ type: 'text', text: `Hello, ${args.name}!` }]\n * }),\n * { credits: 1, onRedeemError: 'ignore' }\n * )\n * ```\n */\n function registerTool<Args = any>(\n name: string,\n config: McpToolConfig,\n handler: ToolHandler<Args>,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerTool(name, config, handler, options)\n }\n\n /**\n * Register a resource with the simplified API.\n * Must be called before start().\n *\n * @param name - Resource name\n * @param uriOrTemplate - Resource URI (string) or template\n * @param config - Resource metadata configuration\n * @param handler - Resource handler function\n * @param options - Registration options (credits, etc.)\n */\n function registerResource(\n name: string,\n uriOrTemplate: string,\n config: McpResourceConfig,\n handler: ResourceHandler,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerResource(name, uriOrTemplate, config, handler, options)\n }\n\n /**\n * Register a prompt with the simplified API.\n * Must be called before start().\n * Matches the signature of MCP SDK registerPrompt.\n *\n * @param name - Prompt name\n * @param config - Prompt configuration\n * @param handler - Prompt handler function\n * @param options - Registration options (credits, etc.)\n */\n function registerPrompt<Args = any>(\n name: string,\n config: McpPromptConfig,\n handler: PromptHandler<Args>,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerPrompt(name, config, handler, options)\n }\n\n /**\n * Start the MCP server with the simplified API.\n * This creates and starts everything: McpServer, Express, OAuth endpoints, etc.\n *\n * @param config - Server configuration\n * @returns Server result with stop() method\n *\n * @example\n * ```typescript\n * // Register tools first\n * payments.mcp.registerTool('hello', { description: '...' }, handler)\n *\n * // Then start the server\n * const { info, stop } = await payments.mcp.start({\n * port: 5001,\n * agentId: 'did:nv:...',\n * serverName: 'my-mcp-server'\n * })\n *\n * console.log(`Server running at ${info.baseUrl}`)\n *\n * // Later: stop gracefully\n * await stop()\n * ```\n */\n async function start(config: McpServerConfig): Promise<McpServerResult> {\n return getServerManager().start(config)\n }\n\n /**\n * Stop the MCP server.\n * This is a convenience method - you can also use the stop() from start()'s result.\n */\n async function stop(): Promise<void> {\n if (serverManager) {\n await serverManager.stop()\n }\n }\n\n return {\n // Core paywall functionality (advanced API)\n configure,\n withPaywall,\n attach,\n authenticateMeta,\n\n // HTTP/OAuth functionality (advanced API)\n createRouter,\n createApp,\n startServer,\n\n // Utilities\n getConfig,\n\n // Simplified API (recommended for most users)\n registerTool,\n registerResource,\n registerPrompt,\n start,\n stop,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AA+DA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAoB,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AA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AAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,gBAAgB,CACvB,IAAY,EACZ,aAAqB,EACrB,MAAyB,EACzB,OAAwB,EACxB,OAAgC;QAEhC,gBAAgB,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACpF,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,cAAc,CACrB,IAAY,EACZ,MAAuB,EACvB,OAA4B,EAC5B,OAAgC;QAEhC,gBAAgB,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACnE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,KAAK,UAAU,KAAK,CAAC,MAAuB;QAC1C,OAAO,gBAAgB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK,UAAU,IAAI;QACjB,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,aAAa,CAAC,IAAI,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO;QACL,4CAA4C;QAC5C,SAAS;QACT,WAAW;QACX,MAAM;QACN,gBAAgB;QAEhB,0CAA0C;QAC1C,YAAY;QACZ,SAAS;QACT,WAAW;QAEX,YAAY;QACZ,SAAS;QAET,8CAA8C;QAC9C,YAAY;QACZ,gBAAgB;QAChB,cAAc;QACd,KAAK;QACL,IAAI;KACL,CAAA;AACH,CAAC","sourcesContent":["/**\n * MCP (Model Context Protocol) integration module for Nevermined Payments.\n *\n * This module provides everything needed to build monetizable MCP servers:\n * - Paywall protection for tools, resources, and prompts\n * - OAuth 2.1 discovery and client registration endpoints\n * - Managed HTTP server or router for existing Express apps\n *\n * @example Basic usage with withPaywall\n * ```typescript\n * import { Payments } from '@nevermined-io/payments'\n *\n * const payments = Payments.getInstance({\n * nvmApiKey: process.env.NVM_API_KEY!,\n * environment: 'staging_sandbox'\n * })\n *\n * // Configure MCP integration\n * payments.mcp.configure({\n * planId: process.env.NVM_PLAN_ID!, // required\n * agentId: process.env.NVM_AGENT_ID, // optional\n * serverName: 'my-mcp-server'\n * })\n *\n * // Protect a tool handler\n * const protectedHandler = payments.mcp.withPaywall(\n * myToolHandler,\n * { kind: 'tool', name: 'my_tool', credits: 1n }\n * )\n * ```\n *\n * @example Complete server with OAuth\n * ```typescript\n * // Start a managed server with all OAuth endpoints\n * const { baseUrl, stop } = await payments.mcp.startServer({\n * port: 5001,\n * planId: process.env.NVM_PLAN_ID!, // required\n * agentId: process.env.NVM_AGENT_ID, // optional\n * serverName: 'my-mcp-server',\n * tools: ['hello_world']\n * })\n * ```\n *\n * @example Using router with existing Express app\n * ```typescript\n * import express from 'express'\n *\n * const app = express()\n *\n * // Create OAuth router\n * const router = payments.mcp.createRouter({\n * baseUrl: 'http://localhost:5001',\n * planId: 'plan_123', // required\n * agentId: 'agent_123', // optional\n * serverName: 'my-mcp-server'\n * })\n *\n * app.use(router)\n * app.listen(5001)\n * ```\n */\nimport type { Payments } from '../payments.js'\nimport type { EnvironmentName } from '../environments.js'\nimport { createOAuthRouter } from './http/oauth-router.js'\nimport { createMcpApp, startManagedServer } from './http/managed-server.js'\nimport { PaywallDecorator } from './core/paywall.js'\nimport { PaywallAuthenticator } from './core/auth.js'\nimport { CreditsContextProvider } from './core/credits-context.js'\nimport { McpServerManager, createServerManager } from './core/server-manager.js'\nimport { ERROR_CODES, createRpcError } from './utils/errors.js'\nimport type {\n McpToolConfig,\n McpResourceConfig,\n McpPromptConfig,\n McpRegistrationOptions,\n ToolHandler,\n ResourceHandler,\n PromptHandler,\n McpServerConfig,\n McpServerResult,\n} from './types/server.types.js'\nimport type {\n PaywallOptions,\n ToolOptions,\n ResourceOptions,\n PromptOptions,\n PaywallContext,\n McpConfig,\n} from './types/paywall.types.js'\nimport type { HttpServerResult } from './types/http.types.js'\n\n// Re-export types\nexport type {\n CreditsContext,\n CreditsOption,\n PaywallOptions,\n McpConfig,\n PaywallContext,\n AuthResult,\n} from './types/paywall.types.js'\n\nexport type {\n OAuthUrls,\n OAuthConfig,\n HttpRouterConfig,\n HttpServerConfig,\n HttpServerResult,\n ProtectedResourceMetadata,\n McpProtectedResourceMetadata,\n AuthorizationServerMetadata,\n OidcConfiguration,\n ClientRegistrationRequest,\n ClientRegistrationResponse,\n ServerInfoResponse,\n} from './types/http.types.js'\n\n// Re-export utilities\nexport { buildExtraFromHttpHeaders, buildExtraFromHttpRequest } from './utils/extra.js'\n\n// Re-export simplified API types\nexport type {\n McpToolConfig,\n McpResourceConfig,\n McpPromptConfig,\n McpRegistrationOptions,\n ToolHandler,\n ResourceHandler,\n PromptHandler,\n McpServerConfig,\n McpServerResult,\n ServerInfo,\n ToolContext,\n ResourceContext,\n PromptContext,\n} from './types/server.types.js'\n\n// Re-export HTTP module components for advanced usage\nexport {\n getOAuthUrls,\n buildProtectedResourceMetadata,\n buildMcpProtectedResourceMetadata,\n buildAuthorizationServerMetadata,\n buildOidcConfiguration,\n buildServerInfoResponse,\n createOAuthRouter,\n createCorsMiddleware,\n createJsonMiddleware,\n createRequireAuthMiddleware,\n createHttpLoggingMiddleware,\n startManagedServer,\n createMcpApp,\n ClientRegistrationError,\n} from './http/index.js'\n\n/**\n * Extended MCP configuration including HTTP server options.\n */\nexport interface ExtendedMcpConfig extends McpConfig {\n /** Base URL for the server (required for HTTP features) */\n baseUrl?: string\n /** Nevermined environment */\n environment?: EnvironmentName\n /** Tools exposed by this server */\n tools?: string[]\n /** Custom OAuth scopes */\n scopes?: string[]\n}\n\n/**\n * Options for creating the OAuth router.\n */\nexport interface CreateRouterOptions {\n /** Base URL of the MCP server */\n baseUrl: string\n /** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */\n planId?: string\n /** Agent ID (optional; OAuth client_id / informational only) */\n agentId?: string\n /** Server name */\n serverName?: string\n /** Tools exposed by this server */\n tools?: string[]\n /** Enable OAuth discovery endpoints */\n enableOAuthDiscovery?: boolean\n /** Enable client registration */\n enableClientRegistration?: boolean\n /** Enable health check */\n enableHealthCheck?: boolean\n /** Enable server info */\n enableServerInfo?: boolean\n /** Server version */\n version?: string\n /** Server description */\n description?: string\n}\n\n/**\n * Options for starting the managed server.\n */\nexport interface StartServerOptions {\n /** Port to listen on */\n port: number\n /** Host to bind to */\n host?: string\n /** Base URL (defaults to http://localhost:\\{port\\}) */\n baseUrl?: string\n /** Payment plan ID — configures the paywall plan for this server (falls back to configure()) */\n planId?: string\n /** Agent ID (optional; OAuth client_id / informational only) */\n agentId?: string\n /** Server name */\n serverName?: string\n /** Tools exposed by this server */\n tools?: string[]\n /** Enable OAuth discovery endpoints */\n enableOAuthDiscovery?: boolean\n /** Enable client registration */\n enableClientRegistration?: boolean\n /** Enable health check */\n enableHealthCheck?: boolean\n /** Enable server info */\n enableServerInfo?: boolean\n /** Server version */\n version?: string\n /** Server description */\n description?: string\n /** Callback when server starts */\n onStart?: (result: HttpServerResult) => void\n /** Logging callback */\n onLog?: (message: string, level?: 'info' | 'warn' | 'error') => void\n}\n\n/**\n * Build MCP integration with modular architecture.\n * This function creates the complete MCP API surface including\n * paywall protection, OAuth endpoints, and HTTP server management.\n *\n * @param paymentsService - The Payments instance\n * @returns MCP integration API\n */\nexport function buildMcpIntegration(paymentsService: Payments) {\n const authenticator = new PaywallAuthenticator(paymentsService)\n const creditsContext = new CreditsContextProvider()\n const paywallDecorator = new PaywallDecorator(paymentsService, authenticator, creditsContext)\n\n // Extended configuration storage\n let extendedConfig: ExtendedMcpConfig = {\n planId: '',\n serverName: 'mcp-server',\n }\n\n /**\n * Configure the MCP integration.\n * This sets up the agent ID, server name, and optional HTTP settings.\n *\n * @param options - Configuration options\n *\n * @example\n * ```typescript\n * payments.mcp.configure({\n * planId: 'plan_123', // required\n * serverName: 'my-mcp-server',\n * agentId: 'agent_123', // optional\n * baseUrl: 'http://localhost:5001',\n * environment: 'staging_sandbox',\n * tools: ['hello_world', 'weather']\n * })\n * ```\n */\n function configure(options: ExtendedMcpConfig): void {\n extendedConfig = {\n ...extendedConfig,\n ...options,\n }\n // Also configure the paywall decorator\n paywallDecorator.configure({\n planId: options.planId,\n agentId: options.agentId,\n serverName: options.serverName,\n })\n }\n\n /**\n * Wrap a handler with paywall protection.\n * The wrapped handler will validate authentication and burn credits.\n *\n * A `planId` must already be resolvable (per-tool `options.planId` or a\n * server-level one set via `configure()`/`start()`); otherwise this throws\n * at registration time. So register paywalled handlers *after* the plan is\n * configured — e.g. `configure({ planId })` (or `start({ planId })`, which\n * configures first) before `withPaywall()`/`attach`.\n */\n function withPaywall<TArgs = any>(\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options: ToolOptions | PromptOptions,\n ): (args: TArgs, extra?: any) => Promise<any>\n function withPaywall<TArgs = any>(\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n ): (args: TArgs, extra?: any) => Promise<any>\n function withPaywall(\n handler: (\n uri: URL,\n variables: Record<string, string | string[]>,\n extra?: any,\n context?: PaywallContext,\n ) => Promise<any> | any,\n options: ResourceOptions,\n ): (uri: URL, variables: Record<string, string | string[]>, extra?: any) => Promise<any>\n function withPaywall(handler: any, options?: ToolOptions | PromptOptions | ResourceOptions): any {\n const opts =\n (options as PaywallOptions | undefined) ?? ({ kind: 'tool', name: 'unnamed' } as any)\n // Fail fast at registration time: a planId must be resolvable from the\n // per-tool option or the server-level config. Otherwise a misconfiguration\n // would only surface on the first tool call.\n if (!opts.planId && !extendedConfig.planId) {\n throw createRpcError(ERROR_CODES.Misconfiguration, 'Server misconfiguration: missing planId')\n }\n return (paywallDecorator.protect as any)(handler, opts)\n }\n\n /**\n * Authenticate meta MCP operations (initialize, tools/list, etc.).\n *\n * @param extra - The extra parameter from MCP\n * @param method - The MCP method being called\n * @returns Authentication result\n */\n async function authenticateMeta(extra: any, options: { planId?: string } = {}, method: string) {\n const cfg = extendedConfig\n const agentId = cfg.agentId || undefined\n const serverName = cfg.serverName || 'mcp-server'\n return authenticator.authenticateMeta(\n extra,\n { planId: options?.planId ?? cfg.planId },\n agentId,\n serverName,\n method,\n )\n }\n\n /**\n * Attach paywall protection to an MCP server.\n * Returns a registrar with protected register methods.\n *\n * @param server - The MCP server instance\n * @returns Protected registrar\n */\n function attach(server: {\n registerTool: (name: string, config: any, handler: any) => void\n registerResource: (name: string, template: any, config: any, handler: any) => void\n registerPrompt: (name: string, config: any, handler: any) => void\n }) {\n return {\n registerTool<TArgs = any>(\n name: string,\n config: any,\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options?: Omit<ToolOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, { kind: 'tool', name, ...(options || {}) })\n server.registerTool(name, config, protectedHandler)\n },\n registerResource(\n name: string,\n template: any,\n config: any,\n handler: (\n uri: URL,\n variables: Record<string, string | string[]>,\n extra?: any,\n context?: PaywallContext,\n ) => Promise<any> | any,\n options?: Omit<ResourceOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, {\n kind: 'resource',\n name,\n ...(options || {}),\n })\n server.registerResource(name, template, config, protectedHandler)\n },\n registerPrompt<TArgs = any>(\n name: string,\n config: any,\n handler: (args: TArgs, extra?: any, context?: PaywallContext) => Promise<any> | any,\n options?: Omit<PromptOptions, 'kind' | 'name'>,\n ) {\n const protectedHandler = withPaywall(handler, { kind: 'prompt', name, ...(options || {}) })\n server.registerPrompt(name, config, protectedHandler)\n },\n }\n }\n\n /**\n * Resolve the effective agentId/serverName/environment for an OAuth transport\n * from per-call options layered over the server-level config, and configure\n * the paywall so tools protected via withPaywall settle on the resolved plan\n * (per-call option wins over a prior configure()). Shared by\n * createRouter/createApp/startServer.\n *\n * agentId is optional under the plan-centric model (informational/OAuth\n * client_id only); the OAuth router omits client_id when it's absent. planId\n * is the paywall's concern — the OAuth transports below do not consume it.\n */\n function resolveTransportConfig(options: {\n planId?: string\n agentId?: string\n serverName?: string\n }): { agentId?: string; serverName: string; environment: EnvironmentName } {\n const agentId = options.agentId || extendedConfig.agentId\n const serverName = options.serverName || extendedConfig.serverName || 'mcp-server'\n configure({\n planId: options.planId ?? extendedConfig.planId,\n agentId,\n serverName,\n })\n const environment: EnvironmentName =\n extendedConfig.environment || (paymentsService as any).environmentName || 'staging_sandbox'\n return { agentId, serverName, environment }\n }\n\n /**\n * Create an Express router with OAuth 2.1 endpoints.\n * Use this when you already have an Express app and want to add OAuth support.\n *\n * @param options - Router configuration\n * @returns Express Router\n *\n * @example\n * ```typescript\n * const router = payments.mcp.createRouter({\n * baseUrl: 'http://localhost:5001',\n * planId: 'plan_123', // required\n * serverName: 'my-mcp-server',\n * tools: ['hello_world']\n * })\n *\n * app.use(router)\n * ```\n */\n function createRouter(options: CreateRouterOptions) {\n const { agentId, serverName, environment } = resolveTransportConfig(options)\n\n return createOAuthRouter({\n payments: paymentsService,\n baseUrl: options.baseUrl,\n agentId,\n environment,\n serverName,\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n })\n }\n\n /**\n * Create an Express app pre-configured with OAuth discovery endpoints.\n * Use this when you want more control over the app before starting.\n *\n * Note: Authentication is handled by withPaywall() on each tool,\n * not by HTTP middleware.\n *\n * @param options - App configuration\n * @returns Configured Express app with OAuth endpoints\n *\n * @example\n * ```typescript\n * const app = payments.mcp.createApp({\n * baseUrl: 'http://localhost:5001',\n * planId: 'plan_123', // required\n * serverName: 'my-mcp-server'\n * })\n *\n * // Add your MCP handler - auth via withPaywall() on each tool\n * app.post('/mcp', mcpHandler)\n *\n * app.listen(5001)\n * ```\n */\n function createApp(options: Omit<CreateRouterOptions, 'agentId'> & { agentId?: string }) {\n const { agentId, serverName, environment } = resolveTransportConfig(options)\n\n return createMcpApp({\n payments: paymentsService,\n baseUrl: options.baseUrl,\n agentId,\n environment,\n serverName,\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n })\n }\n\n /**\n * Start a managed HTTP server with OAuth 2.1 support.\n * This creates a complete Express server with all OAuth endpoints pre-configured.\n *\n * @param options - Server configuration\n * @returns Server result with control methods\n *\n * @example\n * ```typescript\n * const { baseUrl, stop } = await payments.mcp.startServer({\n * port: 5001,\n * planId: process.env.NVM_PLAN_ID!, // required\n * serverName: 'my-mcp-server',\n * tools: ['hello_world', 'weather']\n * })\n *\n * console.log(`Server running at ${baseUrl}`)\n *\n * // Later: gracefully stop\n * await stop()\n * ```\n */\n async function startServer(options: StartServerOptions): Promise<HttpServerResult> {\n const { agentId, serverName, environment } = resolveTransportConfig(options)\n\n const baseUrl = options.baseUrl || `http://localhost:${options.port}`\n\n return startManagedServer({\n payments: paymentsService,\n port: options.port,\n host: options.host,\n baseUrl,\n agentId,\n environment,\n serverName,\n tools: options.tools || extendedConfig.tools || [],\n scopes: extendedConfig.scopes,\n enableOAuthDiscovery: options.enableOAuthDiscovery ?? true,\n enableClientRegistration: options.enableClientRegistration ?? true,\n enableHealthCheck: options.enableHealthCheck ?? true,\n enableServerInfo: options.enableServerInfo ?? true,\n version: options.version,\n description: options.description,\n onStart: options.onStart,\n onLog: options.onLog,\n })\n }\n\n /**\n * Get the current configuration.\n *\n * @returns Current MCP configuration\n */\n function getConfig(): ExtendedMcpConfig {\n return { ...extendedConfig }\n }\n\n // =============================================================================\n // SIMPLIFIED API - High-level API that hides McpServer, Transport, and Express\n // =============================================================================\n\n // Server manager for simplified API\n let serverManager: McpServerManager | null = null\n\n /**\n * Get or create the server manager.\n */\n function getServerManager(): McpServerManager {\n if (!serverManager) {\n serverManager = createServerManager(paymentsService)\n }\n return serverManager\n }\n\n /**\n * Register a tool with the simplified API.\n * Must be called before start().\n *\n * @param name - Tool name\n * @param config - Tool configuration\n * @param handler - Tool handler function\n * @param options - Registration options (credits, etc.)\n *\n * @example\n * ```typescript\n * payments.mcp.registerTool(\n * 'hello_world',\n * {\n * description: 'Returns a hello world message',\n * inputSchema: { name: { type: 'string' } }\n * },\n * async (args: { name: string }, context?: ToolContext) => ({\n * content: [{ type: 'text', text: `Hello, ${args.name}!` }]\n * }),\n * { credits: 1, onRedeemError: 'ignore' }\n * )\n * ```\n */\n function registerTool<Args = any>(\n name: string,\n config: McpToolConfig,\n handler: ToolHandler<Args>,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerTool(name, config, handler, options)\n }\n\n /**\n * Register a resource with the simplified API.\n * Must be called before start().\n *\n * @param name - Resource name\n * @param uriOrTemplate - Resource URI (string) or template\n * @param config - Resource metadata configuration\n * @param handler - Resource handler function\n * @param options - Registration options (credits, etc.)\n */\n function registerResource(\n name: string,\n uriOrTemplate: string,\n config: McpResourceConfig,\n handler: ResourceHandler,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerResource(name, uriOrTemplate, config, handler, options)\n }\n\n /**\n * Register a prompt with the simplified API.\n * Must be called before start().\n * Matches the signature of MCP SDK registerPrompt.\n *\n * @param name - Prompt name\n * @param config - Prompt configuration\n * @param handler - Prompt handler function\n * @param options - Registration options (credits, etc.)\n */\n function registerPrompt<Args = any>(\n name: string,\n config: McpPromptConfig,\n handler: PromptHandler<Args>,\n options?: McpRegistrationOptions,\n ): void {\n getServerManager().registerPrompt(name, config, handler, options)\n }\n\n /**\n * Start the MCP server with the simplified API.\n * This creates and starts everything: McpServer, Express, OAuth endpoints, etc.\n *\n * @param config - Server configuration\n * @returns Server result with stop() method\n *\n * @example\n * ```typescript\n * // Register tools first\n * payments.mcp.registerTool('hello', { description: '...' }, handler)\n *\n * // Then start the server\n * const { info, stop } = await payments.mcp.start({\n * port: 5001,\n * planId: 'plan_123', // required\n * agentId: 'did:nv:...', // optional\n * serverName: 'my-mcp-server'\n * })\n *\n * console.log(`Server running at ${info.baseUrl}`)\n *\n * // Later: stop gracefully\n * await stop()\n * ```\n */\n async function start(config: McpServerConfig): Promise<McpServerResult> {\n return getServerManager().start(config)\n }\n\n /**\n * Stop the MCP server.\n * This is a convenience method - you can also use the stop() from start()'s result.\n */\n async function stop(): Promise<void> {\n if (serverManager) {\n await serverManager.stop()\n }\n }\n\n return {\n // Core paywall functionality (advanced API)\n configure,\n withPaywall,\n attach,\n authenticateMeta,\n\n // HTTP/OAuth functionality (advanced API)\n createRouter,\n createApp,\n startServer,\n\n // Utilities\n getConfig,\n\n // Simplified API (recommended for most users)\n registerTool,\n registerResource,\n registerPrompt,\n start,\n stop,\n }\n}\n"]}
|
|
@@ -30,8 +30,8 @@ export type OAuthScope = (typeof DEFAULT_OAUTH_SCOPES)[number];
|
|
|
30
30
|
export interface OAuthConfig {
|
|
31
31
|
/** Base URL of the MCP server (e.g., http://localhost:5001) */
|
|
32
32
|
baseUrl: string;
|
|
33
|
-
/** Agent ID (client_id) for OAuth flows */
|
|
34
|
-
agentId
|
|
33
|
+
/** Agent ID (client_id) for OAuth flows — optional, informational only */
|
|
34
|
+
agentId?: string;
|
|
35
35
|
/** Nevermined environment to derive OAuth URLs */
|
|
36
36
|
environment: EnvironmentName;
|
|
37
37
|
/** Custom OAuth URLs (overrides environment defaults) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.types.d.ts","sourceRoot":"","sources":["../../../src/mcp/types/http.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,MAAM,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AS,EAAE,MAAM,CAAA;QACjB,MAAM,EAAE,MAAM,EAAE,CAAA;KACjB,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.types.js","sourceRoot":"","sources":["../../../src/mcp/types/http.types.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;CACH,CAAA","sourcesContent":["/**\n * Type definitions for MCP HTTP server and OAuth 2.1 integration.\n * These types configure the automatic OAuth endpoints and HTTP server functionality.\n */\nimport type { EnvironmentName } from '../../environments.js'\n\n/**\n * OAuth URLs configuration for Nevermined authorization server.\n * These URLs are used to build the OAuth discovery metadata.\n */\nexport interface OAuthUrls {\n /** The issuer identifier (e.g., https://nevermined.app) */\n issuer: string\n /** OAuth authorization endpoint URL */\n authorizationUri: string\n /** OAuth token endpoint URL */\n tokenUri: string\n /** JSON Web Key Set endpoint URL */\n jwksUri: string\n /** OpenID Connect userinfo endpoint URL */\n userinfoUri: string\n}\n\n/**\n * Scopes supported by the MCP OAuth integration.\n */\nexport const DEFAULT_OAUTH_SCOPES = [\n 'openid',\n 'profile',\n 'credits',\n 'mcp:read',\n 'mcp:write',\n 'mcp:tools',\n] as const\n\nexport type OAuthScope = (typeof DEFAULT_OAUTH_SCOPES)[number]\n\n/**\n * Configuration for OAuth endpoints and metadata.\n */\nexport interface OAuthConfig {\n /** Base URL of the MCP server (e.g., http://localhost:5001) */\n baseUrl: string\n /** Agent ID (client_id) for OAuth flows */\n agentId
|
|
1
|
+
{"version":3,"file":"http.types.js","sourceRoot":"","sources":["../../../src/mcp/types/http.types.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;CACH,CAAA","sourcesContent":["/**\n * Type definitions for MCP HTTP server and OAuth 2.1 integration.\n * These types configure the automatic OAuth endpoints and HTTP server functionality.\n */\nimport type { EnvironmentName } from '../../environments.js'\n\n/**\n * OAuth URLs configuration for Nevermined authorization server.\n * These URLs are used to build the OAuth discovery metadata.\n */\nexport interface OAuthUrls {\n /** The issuer identifier (e.g., https://nevermined.app) */\n issuer: string\n /** OAuth authorization endpoint URL */\n authorizationUri: string\n /** OAuth token endpoint URL */\n tokenUri: string\n /** JSON Web Key Set endpoint URL */\n jwksUri: string\n /** OpenID Connect userinfo endpoint URL */\n userinfoUri: string\n}\n\n/**\n * Scopes supported by the MCP OAuth integration.\n */\nexport const DEFAULT_OAUTH_SCOPES = [\n 'openid',\n 'profile',\n 'credits',\n 'mcp:read',\n 'mcp:write',\n 'mcp:tools',\n] as const\n\nexport type OAuthScope = (typeof DEFAULT_OAUTH_SCOPES)[number]\n\n/**\n * Configuration for OAuth endpoints and metadata.\n */\nexport interface OAuthConfig {\n /** Base URL of the MCP server (e.g., http://localhost:5001) */\n baseUrl: string\n /** Agent ID (client_id) for OAuth flows — optional, informational only */\n agentId?: string\n /** Nevermined environment to derive OAuth URLs */\n environment: EnvironmentName\n /** Custom OAuth URLs (overrides environment defaults) */\n oauthUrls?: Partial<OAuthUrls>\n /** Scopes supported by this server */\n scopes?: string[]\n /** Server name for MCP protocol */\n serverName?: string\n /** List of tool names exposed by this server */\n tools?: string[]\n /** List of resource names exposed by this server */\n resources?: string[]\n /** List of prompt names exposed by this server */\n prompts?: string[]\n /** MCP protocol version */\n protocolVersion?: string\n}\n\n/**\n * Configuration for the HTTP router.\n */\nexport interface HttpRouterConfig extends OAuthConfig {\n /** Enable OAuth discovery endpoints (/.well-known/*) */\n enableOAuthDiscovery?: boolean\n /** Enable dynamic client registration (/register) */\n enableClientRegistration?: boolean\n /** Enable health check endpoint (/health) */\n enableHealthCheck?: boolean\n /** Enable server info endpoint (/) */\n enableServerInfo?: boolean\n /** Custom CORS origins (default: '*') */\n corsOrigins?: string | string[]\n}\n\n/**\n * Configuration for the managed HTTP server.\n */\nexport interface HttpServerConfig extends HttpRouterConfig {\n /** Port to listen on */\n port: number\n /** Host to bind to (default: '0.0.0.0') */\n host?: string\n}\n\n/**\n * Result returned when starting the managed HTTP server.\n */\nexport interface HttpServerResult {\n /** The underlying HTTP server instance */\n server: import('http').Server\n /** The Express application instance */\n app: import('express').Application\n /** Stop the server gracefully */\n stop: () => Promise<void>\n /** The base URL of the running server */\n baseUrl: string\n /** The port the server is listening on */\n port: number\n}\n\n/**\n * OAuth Protected Resource Metadata response (RFC 9728).\n */\nexport interface ProtectedResourceMetadata {\n resource: string\n authorization_servers: string[]\n scopes_supported: string[]\n bearer_methods_supported: string[]\n resource_documentation?: string\n}\n\n/**\n * MCP-specific Protected Resource Metadata.\n */\nexport interface McpProtectedResourceMetadata extends ProtectedResourceMetadata {\n scopes_required?: string[]\n mcp_capabilities?: {\n tools?: string[]\n protocol_version?: string\n }\n}\n\n/**\n * OAuth Authorization Server Metadata response (RFC 8414).\n */\nexport interface AuthorizationServerMetadata {\n issuer: string\n authorization_endpoint: string\n token_endpoint: string\n registration_endpoint?: string\n jwks_uri: string\n response_types_supported: string[]\n grant_types_supported: string[]\n code_challenge_methods_supported: string[]\n scopes_supported: string[]\n token_endpoint_auth_methods_supported: string[]\n subject_types_supported: string[]\n}\n\n/**\n * OpenID Connect Discovery Metadata.\n */\nexport interface OidcConfiguration extends AuthorizationServerMetadata {\n userinfo_endpoint?: string\n id_token_signing_alg_values_supported?: string[]\n claims_supported?: string[]\n}\n\n/**\n * OAuth Dynamic Client Registration request (RFC 7591).\n */\nexport interface ClientRegistrationRequest {\n redirect_uris: string[]\n client_name?: string\n client_uri?: string\n logo_uri?: string\n scope?: string\n grant_types?: string[]\n response_types?: string[]\n token_endpoint_auth_method?: string\n contacts?: string[]\n}\n\n/**\n * OAuth Dynamic Client Registration response (RFC 7591).\n */\nexport interface ClientRegistrationResponse {\n client_id: string\n client_id_issued_at: number\n client_name?: string\n redirect_uris: string[]\n scope?: string\n grant_types?: string[]\n response_types?: string[]\n token_endpoint_auth_method?: string\n client_secret?: string\n client_secret_expires_at?: number\n client_uri?: string\n logo_uri?: string\n contacts?: string[]\n}\n\n/**\n * Server info response for the root endpoint.\n */\nexport interface ServerInfoResponse {\n name: string\n version: string\n description?: string\n endpoints: {\n mcp: string\n health?: string\n register?: string\n }\n oauth?: {\n authorization_server_metadata: string\n protected_resource_metadata: string\n openid_configuration: string\n authorization_endpoint: string\n token_endpoint: string\n jwks_uri: string\n registration_endpoint?: string\n client_id: string\n scopes: string[]\n }\n tools?: string[]\n resources?: string[]\n prompts?: string[]\n}\n"]}
|