import { SocksProxyAgent } from 'socks-proxy-agent'; import { HttpsProxyAgent } from 'https-proxy-agent'; /** * WordPress API request parameters */ interface WordPressRequestParams { method: string; [key: string]: any; } /** * WordPress API response */ interface WordPressResponse { [key: string]: any; } declare const MCP_WORDPRESS_REMOTE_VERSION = "0.3.0"; /** * Centralized configuration for MCP WordPress Remote * All default values are defined here and can be overridden via environment variables */ declare const CONFIG: { readonly WP_API_URL: string; readonly OAUTH_ENABLED: boolean; readonly OAUTH_CALLBACK_PORT: number | undefined; readonly OAUTH_HOST: string; readonly WP_OAUTH_CLIENT_ID: string; readonly OAUTH_FLOW_TYPE: "authorization_code" | "implicit"; readonly OAUTH_USE_PKCE: boolean; readonly OAUTH_DYNAMIC_REGISTRATION: boolean; readonly OAUTH_AUTHORIZE_ENDPOINT: string; readonly OAUTH_TOKEN_ENDPOINT: string; readonly OAUTH_AUTHENTICATE_ENDPOINT: string; readonly OAUTH_RESOURCE_INDICATOR: boolean; readonly OAUTH_SCOPES: string; readonly OAUTH_TIMEOUT: 30000; readonly LOCK_TIMEOUT: 300000; readonly WP_MCP_CONFIG_DIR: string; readonly LOG_FILE: string | null; readonly WP_API_USERNAME: string | undefined; readonly WP_API_PASSWORD: string | undefined; readonly JWT_TOKEN: string | undefined; readonly WOO_CUSTOMER_KEY: string | undefined; readonly WOO_CUSTOMER_SECRET: string | undefined; readonly CUSTOM_HEADERS: string; readonly NODE_ENV: string; readonly USE_SYSTEM_PROXY: boolean; }; /** * Type-safe configuration access with JSDoc descriptions */ declare const getConfig: () => { /** WordPress site API endpoint */ wpApiUrl: string; /** Whether OAuth authentication is enabled */ oauthEnabled: boolean; /** Port for OAuth callback server (undefined for auto-detection on self-hosted sites) */ oauthCallbackPort: number | undefined; /** Hostname for OAuth callback */ oauthHost: string; /** WordPress OAuth client ID */ wpOAuthClientId: string; /** OAuth flow type (authorization_code recommended, implicit for legacy) */ oauthFlowType: "authorization_code" | "implicit"; /** Whether to use PKCE (required for OAuth 2.1) */ oauthUsePKCE: boolean; /** Whether to support dynamic client registration */ oauthDynamicRegistration: boolean; /** Whether to use resource indicators (RFC 8707) */ oauthResourceIndicator: boolean; /** Custom OAuth scopes (comma-separated) */ oauthScopes: string; /** OAuth operation timeout in milliseconds */ oauthTimeout: 30000; /** Lock operation timeout in milliseconds */ lockTimeout: 300000; /** Configuration directory path */ configDir: string; /** Log file path (null if not set) */ logFile: string | null; /** WordPress API username (legacy) */ wpApiUsername: string | undefined; /** WordPress API password (legacy) */ wpApiPassword: string | undefined; /** JWT token for authentication */ jwtToken: string | undefined; /** WooCommerce customer key */ wooCustomerKey: string | undefined; /** WooCommerce customer secret */ wooCustomerSecret: string | undefined; /** Custom headers for API requests */ customHeaders: string; /** Current environment */ nodeEnv: string; /** Whether to use system proxy (PAC files on macOS, env vars on all platforms) */ useSystemProxy: boolean; }; /** * Get default OAuth scopes */ declare function getDefaultOAuthScopes(): string[]; /** * Parse custom headers from environment variable * Supports both JSON format and comma-separated format * * JSON format: {"X-MCP-API-Key": "value", "X-Custom-Header": "value"} * Comma format: X-MCP-API-Key:value,X-Custom-Header:value */ declare function parseCustomHeaders(customHeadersString: string): Record; /** * Get parsed custom headers */ declare function getCustomHeaders(): Record; /** * Validation function for required configuration */ declare function validateConfig(): { isValid: boolean; errors: string[]; }; declare enum LogLevel { ERROR = 0, WARN = 1, INFO = 2, DEBUG = 3 } /** * Enhanced logging function with levels and categories * * @param message - The message to log * @param level - Log level (default: INFO) * @param category - Log category for filtering (default: 'GENERAL') * @param args - Additional arguments to log */ declare function log(message: string, level?: LogLevel, category?: string, ...args: any[]): void; /** * Convenience logging functions */ declare const logger: { error: (message: string, category?: string, ...args: any[]) => void; warn: (message: string, category?: string, ...args: any[]) => void; info: (message: string, category?: string, ...args: any[]) => void; debug: (message: string, category?: string, ...args: any[]) => void; auth: (message: string, level?: LogLevel, ...args: any[]) => void; oauth: (message: string, level?: LogLevel, ...args: any[]) => void; api: (message: string, level?: LogLevel, ...args: any[]) => void; config: (message: string, level?: LogLevel, ...args: any[]) => void; }; declare function wpRequest(requestData: any, useJsonRpc?: boolean, options?: { allowSessionRecovery?: boolean; }): Promise; /** * WordPress OAuth types and error definitions * Updated for MCP Authorization specification 2025-06-18 compliance */ /** * WordPress OAuth tokens structure */ interface WPTokens { access_token: string; token_type: string; expires_in?: number; scope?: string; obtained_at: number; refresh_token?: string; } /** * WordPress OAuth client information */ interface WPClientInfo { client_id: string; client_secret?: string; authorization_endpoint?: string; token_endpoint?: string; scope?: string; } /** * Token validation result */ interface TokenValidationResult { isValid: boolean; expiresIn?: number; error?: string; } /** * Custom OAuth error class */ declare class OAuthError extends Error { readonly code: string; readonly details?: any; constructor(message: string, code?: string, details?: any); } /** * Custom configuration error class */ declare class ConfigError extends Error { readonly field: string; readonly value?: any; constructor(message: string, field: string, value?: any); } /** * Custom authentication error class */ declare class AuthError extends Error { readonly method: string; readonly statusCode?: number; constructor(message: string, method: string, statusCode?: number); } /** * Custom API error class */ declare class APIError extends Error { readonly statusCode: number; readonly endpoint: string; readonly response?: any; constructor(message: string, statusCode: number, endpoint: string, response?: any); } /** * Error type guards */ declare function isOAuthError(error: any): error is OAuthError; declare function isConfigError(error: any): error is ConfigError; declare function isAuthError(error: any): error is AuthError; declare function isAPIError(error: any): error is APIError; /** * Fetch API utilities for MCP WordPress Remote * * Provides fetch polyfill setup for Node.js environments that don't have native fetch * and proxy-aware fetch for routing through system proxies (PAC files, env-based SOCKS/HTTP proxies) */ /** * Setup fetch polyfill for Node.js 18+ compatibility * * Checks if native fetch is available and loads node-fetch polyfill if needed. * This ensures compatibility across different Node.js versions. * Also initializes proxy support for system proxies (PAC files, env vars). */ declare function setupFetchPolyfill(): Promise; /** * Proxy-aware fetch that routes requests through system proxies when configured * * On macOS: Evaluates PAC file from system proxy settings to determine proxy per-URL * On Linux/other: Uses SOCKS_PROXY, HTTPS_PROXY, etc. environment variables * Falls back to direct connection if no proxy is configured or USE_SYSTEM_PROXY=false * * @param url - The URL to fetch * @param init - Optional fetch init options * @returns Promise resolving to the Response */ declare function proxyFetch(url: string, init?: RequestInit): Promise; /** * Get proxy status information for logging/debugging */ declare function getProxyInfo(): { configured: boolean; type: "pac" | "env" | "none"; }; /** * Check if fetch is available (either native or polyfilled) * * @returns true if fetch is available, false otherwise */ declare function isFetchAvailable(): boolean; /** * Get information about the current fetch implementation * * @returns Object with details about fetch availability and type */ declare function getFetchInfo(): { available: boolean; native: boolean; polyfilled: boolean; }; /** * Cross-platform proxy utilities for MCP WordPress Remote * * Supports: * - macOS: Automatic PAC file detection from system proxy settings * - macOS: System SOCKS proxy detection (AutoProxxy Tunnel All Traffic) * - All platforms: Environment variables (SOCKS_PROXY, HTTPS_PROXY, etc.) */ type ProxyAgent = SocksProxyAgent | HttpsProxyAgent; /** * Initialize proxy configuration (call once at startup) * Guards against concurrent initialization calls */ declare function initializeProxy(): Promise; /** * Get appropriate agent for a URL based on proxy configuration */ declare function getAgentForUrl(url: string): Promise; /** * Check if proxy is configured */ declare function isProxyConfigured(): boolean; /** * Get proxy configuration type for logging */ declare function getProxyType(): 'pac' | 'env' | 'none'; export { APIError, AuthError, CONFIG, ConfigError, LogLevel, MCP_WORDPRESS_REMOTE_VERSION, OAuthError, type TokenValidationResult, type WPClientInfo, type WPTokens, type WordPressRequestParams, type WordPressResponse, getAgentForUrl, getConfig, getCustomHeaders, getDefaultOAuthScopes, getFetchInfo, getProxyInfo, getProxyType, initializeProxy, isAPIError, isAuthError, isConfigError, isFetchAvailable, isOAuthError, isProxyConfigured, log, logger, parseCustomHeaders, proxyFetch, setupFetchPolyfill, validateConfig, wpRequest };