import { BaseCommand } from '@salesforce/b2c-tooling-sdk/cli'; import type { ResolvedB2CConfig } from '@salesforce/b2c-tooling-sdk/config'; import { Services } from '../services.js'; import type { ProjectContextInput } from '../tools/project-context.js'; /** * oclif Command that starts the B2C DX MCP server. * * Uses oclif's single-command strategy - this IS the CLI, not a subcommand. * Extends BaseCommand from @salesforce/b2c-tooling-sdk which provides: * - Global flags for config, logging, and debugging * - Structured pino logging via `this.logger` * - Automatic dw.json loading via `this.resolvedConfig` * - Automatic telemetry initialization via `this.telemetry` * - `this.config` - package.json metadata and standard config paths */ /** Server instructions sent at initialize; clients show them to the model and Codex also indexes them for tool search. */ export declare const SERVER_INSTRUCTIONS: string; export default class McpServerCommand extends BaseCommand { static description: string; static examples: { description: string; command: string; }[]; static flags: { 'allow-non-ga-tools': import("@oclif/core/interfaces").BooleanFlag; toolsets: import("@oclif/core/interfaces").OptionFlag; tools: import("@oclif/core/interfaces").OptionFlag; 'docs-topics': import("@oclif/core/interfaces").OptionFlag; 'scapi-schemas': import("@oclif/core/interfaces").OptionFlag; server: import("@oclif/core/interfaces").OptionFlag; 'webdav-server': import("@oclif/core/interfaces").OptionFlag; 'code-version': import("@oclif/core/interfaces").OptionFlag; username: import("@oclif/core/interfaces").OptionFlag; password: import("@oclif/core/interfaces").OptionFlag; certificate: import("@oclif/core/interfaces").OptionFlag; passphrase: import("@oclif/core/interfaces").OptionFlag; selfsigned: import("@oclif/core/interfaces").BooleanFlag; verify: import("@oclif/core/interfaces").BooleanFlag; 'api-backend': import("@oclif/core/interfaces").OptionFlag<"ocapi" | "scapi" | "auto" | undefined, import("@oclif/core/interfaces").CustomOptions>; 'client-id': import("@oclif/core/interfaces").OptionFlag; 'client-secret': import("@oclif/core/interfaces").OptionFlag; 'auth-scope': import("@oclif/core/interfaces").OptionFlag; 'short-code': import("@oclif/core/interfaces").OptionFlag; 'tenant-id': import("@oclif/core/interfaces").OptionFlag; 'auth-methods': import("@oclif/core/interfaces").OptionFlag; 'user-auth': import("@oclif/core/interfaces").BooleanFlag; 'default-client': import("@oclif/core/interfaces").BooleanFlag; 'account-manager-host': import("@oclif/core/interfaces").OptionFlag; 'client-auth-method': import("@oclif/core/interfaces").OptionFlag<"basic" | "basic-unencoded" | "body" | undefined, import("@oclif/core/interfaces").CustomOptions>; 'jwt-cert': import("@oclif/core/interfaces").OptionFlag; 'jwt-key': import("@oclif/core/interfaces").OptionFlag; 'jwt-passphrase': import("@oclif/core/interfaces").OptionFlag; 'selfsigned-api': import("@oclif/core/interfaces").BooleanFlag; 'log-level': import("@oclif/core/interfaces").OptionFlag<"trace" | "debug" | "info" | "warn" | "error" | "silent" | undefined, import("@oclif/core/interfaces").CustomOptions>; debug: import("@oclif/core/interfaces").BooleanFlag; json: import("@oclif/core/interfaces").BooleanFlag; jsonl: import("@oclif/core/interfaces").BooleanFlag; lang: import("@oclif/core/interfaces").OptionFlag; config: import("@oclif/core/interfaces").OptionFlag; instance: import("@oclif/core/interfaces").OptionFlag; 'dotenv-file': import("@oclif/core/interfaces").OptionFlag; 'project-directory': import("@oclif/core/interfaces").OptionFlag; 'extra-query': import("@oclif/core/interfaces").OptionFlag; 'extra-body': import("@oclif/core/interfaces").OptionFlag; 'extra-headers': import("@oclif/core/interfaces").OptionFlag; 'scapi-base-url': import("@oclif/core/interfaces").OptionFlag; 'api-key': import("@oclif/core/interfaces").OptionFlag; project: import("@oclif/core/interfaces").OptionFlag; environment: import("@oclif/core/interfaces").OptionFlag; 'cloud-origin': import("@oclif/core/interfaces").OptionFlag; 'credentials-file': import("@oclif/core/interfaces").OptionFlag; 'mrt-backend': import("@oclif/core/interfaces").OptionFlag<"scapi" | "auto" | "legacy", import("@oclif/core/interfaces").CustomOptions>; }; /** Signal that triggered shutdown (if any) - used to exit process after finally() */ private shutdownSignal?; /** Promise that resolves when stdin closes (MCP client disconnects) */ private stdinClosePromise?; /** * Override finally() to wait for stdin close before stopping telemetry. * This ensures SERVER_STOPPED is sent before telemetry.stop() is called. */ protected finally(err: Error | undefined): Promise; /** * Loads configuration from flags, environment variables, and config files. * * Combines configuration from both InstanceCommand (B2C instance) and MrtCommand (MRT) * since this command supports both B2C instance tools and MRT tools. * * Uses SDK helper functions for flag extraction: * - extractInstanceFlags() - B2C instance flags (--server, --username, etc.) * - extractMrtFlags() - MRT flags (--api-key, --project, etc.) and loading options * * Configuration file selection (highest to lowest): * 1. Per-call configPath * 2. Startup --config / SFCC_CONFIG * 3. SFCC_CONFIG from the selected project's .env * 4. dw.json in the selected project directory, plus the shared default * dw.json from the tooling settings * * An explicit path (1-3) is used on its own; an empty one selects no dw.json. * * Values are then merged through the normal CLI resolver, including * environment, plugin, dw.json, ~/.mobify, and package.json sources. */ protected loadConfiguration(projectContext?: ProjectContextInput): Promise; /** * Loads configuration and creates a new Services instance. * * This method loads configuration files (dw.json, ~/.mobify) on each call, * allowing tools to pick up changes to configuration between invocations. * Flags remain the same (parsed once at startup). * * @returns A new Services instance with loaded configuration */ protected loadServices(projectContext?: ProjectContextInput): Promise; /** * Main entry point - starts the MCP server. * * Execution flow: * 1. BaseCommand.init() parses flags, loads config, and initializes telemetry * 2. Filter and validate toolsets (invalid ones are skipped with warning) * 3. Create B2CDxMcpServer instance with telemetry from BaseCommand * 4. Create Services via Services.fromResolvedConfig() using already-resolved config * 5. Register tools based on --toolsets and --tools flags * 6. Connect to stdio transport (JSON-RPC over stdin/stdout) * 7. Log startup message via structured logger * * @throws Never throws - invalid toolsets are filtered, not rejected * * BaseCommand provides: * - `this.flags` - Parsed flags including global flags (config, debug, log-level, etc.) * - `this.resolvedConfig` - Loaded dw.json configuration * - `this.logger` - Structured pino logger * - `this.telemetry` - Telemetry instance (auto-initialized from package.json config) * * oclif provides standard config paths via `this.config`: * - `this.config.configDir` - User config (~/.config/b2c) * - `this.config.dataDir` - User data (~/.local/share/b2c) - shared with b2c-cli for plugin discovery * - `this.config.cacheDir` - Cache (~/.cache/b2c) * These can be exposed to Services if needed for features like telemetry or caching. */ run(): Promise; /** Load --scapi-schemas once at startup; relative paths resolve from the project directory. */ private loadLocalScapiSchemas; /** Parse a project's .env without mutating the long-lived MCP process environment. */ private loadProjectEnvironment; }