#!/usr/bin/env node /** * @name RemoteMCPServer * @description Streamable HTTP entrypoint for remote SAP MCP deployments. */ import * as http from 'http'; import { type SapMcpConfig } from '../../config-runtime/src/env.js'; import { type RemoteAuthConfig } from './auth/index.js'; import { type PremiumCapabilityType } from '../../premium/src/index.js'; import { type RemoteRateLimitConfig } from './rate-limiter.js'; declare const WIZARD_NPM_COMMAND = "npm exec --yes --package @oobe-protocol-labs/sap-mcp-server -- sap-mcp-config wizard"; /** * @name PublicLogoAsset * @description Resolved public logo asset response metadata for browser and crawler icon routes. */ export interface PublicLogoAsset { contentType: 'image/png' | 'image/svg+xml' | 'image/webp' | 'image/x-icon'; contentLength: number; body?: Buffer; } /** * @name PublicMarkdownAsset * @description Resolved public documentation markdown asset served by the hosted docs site. */ export interface PublicMarkdownAsset { contentType: 'text/markdown; charset=utf-8'; contentLength: number; body?: string; } /** * @name RemoteMCPConfig * @description Resolved runtime configuration for the remote MCP HTTP server. */ export interface RemoteMCPConfig { port: number; host: string; corsOrigins?: string[]; auth: RemoteAuthConfig; stateless: boolean; rateLimit: RemoteRateLimitConfig; sessions?: RemoteSessionConfig; concurrency?: RemoteConcurrencyConfig; http?: RemoteHttpTuningConfig; paymentDiscovery?: PublicPaymentDiscovery; paymentPriceRange?: PublicPaymentPriceRange; } /** * @name RemoteSessionConfig * @description Bounds stateful Streamable HTTP MCP sessions so crawlers and idle agents cannot exhaust memory. */ export interface RemoteSessionConfig { maxStatefulSessions: number; idleTtlMs: number; absoluteTtlMs: number; cleanupIntervalMs: number; } /** * @name RemoteConcurrencyConfig * @description Bounds concurrently executing MCP requests while preserving fast failure under overload. */ export interface RemoteConcurrencyConfig { maxInFlightRequests: number; } /** * @name RemoteHttpTuningConfig * @description Node HTTP server socket and header timeout settings for reverse-proxied streaming deployments. */ export interface RemoteHttpTuningConfig { requestTimeoutMs: number; headersTimeoutMs: number; keepAliveTimeoutMs: number; maxRequestsPerSocket: number; } /** * @name A2AAgentCard * @description Public discovery document returned for A2A-compatible orchestrators. */ export interface A2AAgentCard { name: string; description: string; url: string; version: string; protocol: { primary: 'mcp'; transport: 'streamable-http'; endpoint: string; }; capabilities: { streaming: boolean; tools: boolean; resources: boolean; prompts: boolean; authenticated: boolean; }; authentication: { schemes: readonly ('Bearer' | 'x402' | 'none')[]; required: boolean; }; defaultInputModes: readonly ['application/json']; defaultOutputModes: readonly ['application/json', 'text/event-stream']; skills: ReadonlyArray<{ id: string; name: string; description: string; tags: readonly string[]; }>; setup: { wizard: WizardInstallDescriptor; }; } /** * @name WizardInstallDescriptor * @description Public hosted metadata that tells agents and users how to install the local SAP MCP wizard. */ export interface WizardInstallDescriptor { name: 'SAP MCP Wizard'; version: string; packageName: '@oobe-protocol-labs/sap-mcp-server'; hostedMcpUrl: string; configDirectory: '~/.config/mcp-sap'; requiredFor: readonly string[]; endpoints: { descriptor: string; downloads: string; installScript: string; mcp: string; toolCatalog: string; }; commands: { runWizard: string; showConfig: string; showProfile: string; installX402PaidCallAddon: string; runX402PaidCall: string; }; security: { keypairBytesExposed: false; modifiesSolanaCliKeypair: false; signerLocation: 'user-machine-or-external-signer'; }; } /** * @name PublicServerInfo * @description Public, secret-free metadata for the hosted SAP MCP deployment. */ export interface PublicServerInfo { name: string; title: string; displayName: string; display_name: string; description: string; version: string; homepage: string; websiteUrl: string; website_url: string; icon: string; iconUrl: string; icon_url: string; image: string; logo: string; icons: ReadonlyArray<{ src: string; mimeType: 'image/png'; sizes: readonly ['512x512']; }>; status: 'online'; protocol: { primary: 'mcp'; transport: 'streamable-http'; protocolVersion: '2025-06-18'; }; endpoints: { landing: string; mcp: string; health: string; serverInfo: string; docs: string; txSubmit?: string; pricing?: string; openApi?: string; premiumCatalog?: string; premiumStreams?: string; premiumWebhooks?: string; premiumHealth?: string; premiumActivate?: string; premiumStreamBase?: string; premiumWebhookRegister?: string; x402Discovery?: string; smitheryConfigSchema?: string; smitheryServerCard: string; payShProvider?: string; agentCard: string; wizardDescriptor?: string; wizardDownloads?: string; wizardInstallScript?: string; toolCatalog: string; favicon: string; faviconIco: string; }; downloads?: { release: string; desktopWizard: { macosArm64Dmg: string; windowsX64Setup: string; linuxX64TarGz: string; }; }; capabilities: { tools: boolean; resources: boolean; prompts: boolean; streaming: boolean; payments?: readonly ['x402', 'pay.sh']; userControlledSigning: boolean; }; authentication: { schemes: readonly ('Bearer' | 'x402' | 'none')[]; bearerRequired: boolean; }; payments?: PublicPaymentDiscovery; security: { keypairBytesExposed: false; storesUserKeypairs: false; rpcSecretsExposed: false; wizardConfigDirectory?: '~/.config/mcp-sap'; }; docs?: { npm: 'https://www.npmjs.com/package/@oobe-protocol-labs/sap-mcp-server'; github: 'https://github.com/OOBE-PROTOCOL/sap-mcp'; userDocs: 'https://github.com/OOBE-PROTOCOL/sap-mcp/tree/main/USER_DOCS'; }; } /** * @name MarketplaceConfigurationMetadata * @description Public setup hints for MCP marketplaces and agent runtimes. */ export interface MarketplaceConfigurationMetadata { required: false; schemaUrl: string; configSchema: unknown; recommendedMode: 'free-discovery'; paidToolModes: readonly ['x402-native-client', 'local-sap-payments-bridge']; instructions: string; setupCommand: typeof WIZARD_NPM_COMMAND; localBridge: { serverName: 'sap_payments'; readinessTool: 'sap_payments_readiness'; paidCallTool: 'sap_payments_call_paid_tool'; }; } /** * @name StaticServerCard * @description Smithery-compatible static MCP server card served from /.well-known/mcp/server-card.json. */ export interface StaticServerCard { serverInfo: { name: string; displayName: string; display_name: string; title: string; version: string; description: string; homepage: string; websiteUrl: string; website_url: string; icon: string; iconUrl: string; icon_url: string; image: string; logo: string; icons: ReadonlyArray<{ src: string; mimeType: 'image/png'; sizes: readonly ['512x512']; }>; }; name: string; displayName: string; display_name: string; title: string; version: string; description: string; homepage: string; websiteUrl: string; website_url: string; icon: string; iconUrl: string; icon_url: string; image: string; logo: string; icons: ReadonlyArray<{ src: string; mimeType: 'image/png'; sizes: readonly ['512x512']; }>; authentication: { required: boolean; schemes: readonly ('none' | 'x402' | 'Bearer')[]; }; configuration: MarketplaceConfigurationMetadata; transport: { type: 'streamable-http'; url: string; }; tools: readonly unknown[]; resources: readonly unknown[]; resourceTemplates: readonly unknown[]; prompts: readonly unknown[]; } /** * @name PublicPaymentDiscovery * @description Secret-free payment coordinates for x402/pay.sh discovery surfaces. */ export interface PublicPaymentDiscovery { provider: 'x402' | 'pay-sh'; network: string; asset: string; assetSymbol: 'USDC'; payTo: string; seller: { name: 'OOBE Protocol'; payTo: string; }; facilitator?: { role: 'x402-svm-fee-payer'; publicKey: string; }; headers: { paymentRequired: 'PAYMENT-REQUIRED'; paymentSignature: 'PAYMENT-SIGNATURE'; paymentResponse: 'PAYMENT-RESPONSE'; }; } /** * @name PublicPaymentPriceRange * @description Public-safe hosted payment price range for discovery documents. */ export interface PublicPaymentPriceRange { minUsd: number; maxUsd: number; } /** * @name PublicPaymentStats * @description Aggregated, public-safe hosted payment metrics rendered on the landing page. */ export interface PublicPaymentStats { totalVolumeUsd: number; totalSettlements: number; totalPaymentRequests: number; totalChallengesReturned: number; totalVerifiedPayments: number; totalVerificationFailures: number; totalEligibilityBlocks: number; totalFailedSettlements: number; uniqueRemoteCallers: number; uniqueUserAgents: number; lastSettlementAt?: string; ledgerAvailable: boolean; } /** * @name X402DiscoveryDocument * @description x402scan-compatible discovery fan-out document for paid hosted resources. */ export interface X402DiscoveryDocument { version: 1; resources: string[]; payments?: PublicPaymentDiscovery; instructions: string; } /** * @name parseApiKeys * @description Parses comma-separated `apiKey=userId` entries from environment configuration. */ export declare function parseApiKeys(raw: string | undefined): Map; /** * @name defaultRemoteConfig * @description Builds remote-server configuration from SAP config plus remote-specific environment values. */ export declare function defaultRemoteConfig(appConfig: SapMcpConfig): RemoteMCPConfig; /** * @name resolvePublicDocsMarkdown * @description Resolves safe hosted documentation markdown requests under /docs and /docs/user. */ export declare function resolvePublicDocsMarkdown(method: string | undefined, pathname: string): PublicMarkdownAsset | undefined; /** * @name resolvePublicLogoAsset * @description Resolves public icon/social image routes, including HEAD-safe favicon responses for crawlers. */ export declare function resolvePublicLogoAsset(method: string | undefined, pathname: string): PublicLogoAsset | undefined; /** * @name readPublicPaymentStats * @description Reads cached public-safe payment totals from the append-only usage ledger. */ export declare function readPublicPaymentStats(now?: number): PublicPaymentStats; /** * @name buildPublicServerInfo * @description Builds secret-free public metadata for humans, crawlers, and agent discovery. */ export declare function buildPublicServerInfo(req: http.IncomingMessage, config: RemoteMCPConfig, appConfig?: SapMcpConfig): PublicServerInfo; /** * @name buildPublicToolCatalogDocument * @description Builds the secret-free hosted runtime tool catalog used by wizard, UI, and agent discovery. */ export declare function buildPublicToolCatalogDocument(req: http.IncomingMessage, config: RemoteMCPConfig, appConfig: SapMcpConfig): Promise>; /** * @name buildMarketplaceConfigurationMetadata * @description Builds public Smithery/marketplace configuration hints for non-custodial x402 usage. */ export declare function buildMarketplaceConfigurationMetadata(req: http.IncomingMessage, config: RemoteMCPConfig): MarketplaceConfigurationMetadata; /** * @name buildPremiumDiscoveryDocument * @description Builds public premium stream/webhook/plugin contracts for agent runtimes and marketplaces. */ export declare function buildPremiumDiscoveryDocument(req: http.IncomingMessage, config: RemoteMCPConfig, type?: Extract): Record; /** * @name readSmitheryConfigSchema * @description Reads the published Smithery JSON schema from the packaged root. */ export declare function readSmitheryConfigSchema(): unknown; /** * @name buildStaticServerCard * @description Builds the static server card consumed by registries that need metadata outside initialize. */ export declare function buildStaticServerCard(req: http.IncomingMessage, config: RemoteMCPConfig, appConfig: SapMcpConfig): Promise; /** * @name buildPublicPayShProviderYaml * @description Builds a public pay.sh provider catalog for the hosted SAP MCP endpoint without RPC secrets or signer paths. */ export declare function buildPublicPayShProviderYaml(req: http.IncomingMessage, config: RemoteMCPConfig, appConfig: SapMcpConfig): string; /** * @name buildOpenApiSpec * @description OpenAPI 3.1 spec for x402scan discovery. Describes the /mcp endpoint * with x-payment-info so x402scan can discover and register the API. */ export declare function buildOpenApiSpec(req: http.IncomingMessage, config: RemoteMCPConfig): Record; /** * @name buildX402DiscoveryDocument * @description Builds the compatibility discovery document consumed by x402scan. */ export declare function buildX402DiscoveryDocument(req: http.IncomingMessage, config: RemoteMCPConfig): X402DiscoveryDocument; /** * @name buildLandingHtml * @description Builds professional public HTML metadata for root and `/mcp` URL previews. */ export declare function buildLandingHtml(req: http.IncomingMessage, config: RemoteMCPConfig, endpoint?: 'root' | 'mcp'): string; /** * @name buildDocsHtml * @description Builds the hosted SAP MCP documentation shell powered by Docsify. */ export declare function buildDocsHtml(req: http.IncomingMessage, config: RemoteMCPConfig): string; /** * @name buildA2AAgentCard * @description Builds the public A2A-compatible agent-card document for remote discovery. */ export declare function buildA2AAgentCard(req: http.IncomingMessage, config: RemoteMCPConfig): A2AAgentCard; /** * @name buildWizardInstallDescriptor * @description Builds the public wizard installation descriptor used by agents when local SAP MCP config is missing. */ export declare function buildWizardInstallDescriptor(req: http.IncomingMessage, config: RemoteMCPConfig): WizardInstallDescriptor; /** * @name buildWizardInstallScript * @description Builds a small shell launcher that downloads the npm package and starts the wizard. */ export declare function buildWizardInstallScript(req: http.IncomingMessage, config: RemoteMCPConfig): string; /** * @name RemoteMCPServer * @description Remote MCP server backed by the official Streamable HTTP transport. */ export declare class RemoteMCPServer { private readonly config; private readonly appConfig; private readonly authManager; private readonly rateLimiter; private readonly requestLimiter; private readonly statefulSessions; private readonly sessionConfig; private readonly httpTuning; private sessionCleanupInterval?; private httpServer?; private monetizationGate?; private premiumMemoryManager?; constructor(config?: RemoteMCPConfig); /** * @name start * @description Starts the remote MCP endpoint, health check, and A2A discovery routes. */ start(): Promise; /** * @name stop * @description Gracefully closes the MCP transport and HTTP listener. */ stop(): Promise; /** * @name validateAuthConfig * @description Fails startup when configured remote authentication is incomplete. */ private validateAuthConfig; /** * @name handleStatefulMcpRequest * @description Routes a stateful MCP request to the session transport created by initialize. */ private handleStatefulMcpRequest; /** * @name validateStatefulPaidRequest * @description Fails paid tool calls before x402 verification when the MCP session is missing or unknown. */ private validateStatefulPaidRequest; /** * @name resolveStatefulTransport * @description Returns the transport for an existing session or creates one for an initialize request. */ private resolveStatefulTransport; /** * @name createStatefulSessionTransport * @description Creates one MCP server and Streamable HTTP transport for a single initialized session. */ private createStatefulSessionTransport; private startSessionCleanup; private pruneStatefulSessions; private closeStatefulSession; /** * @name applyCors * @description Applies configured CORS headers and handles preflight requests. */ private applyCors; } /** * @name startRemoteMcpServerProcess * @description Starts the remote MCP HTTP server and installs process signal handlers for CLI/PM2 execution. */ export declare function startRemoteMcpServerProcess(): Promise; export {}; //# sourceMappingURL=server.d.ts.map