Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1mcp app Agent Global Options

From Leeroopedia
Knowledge Sources
Domains CLI, Configuration
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete module that defines global CLI options—config, config-dir, log-level, log-file, product-telemetry flags, project-owner, and cli-session-cache-path—shared across all 1MCP command groups, each mapping to a `ONE_MCP_*` environment variable.

Description

The globalOptions object and withGlobalOptions function provide the central options contract for the 1MCP CLI. Every command group inherits these flags via yargs middleware so that configuration paths, logging behavior, telemetry collection, and session ownership are consistent across the entire command surface. The module uses a `WeakSet` guard to ensure options are registered exactly once per `Argv` instance, preventing duplicate parsing in nested command builders. A `coerceTelemetryBoolean` helper parses flexible boolean strings (`true`/`1`/`yes`/`false`/`0`/`no`), and the `product-telemetry-test-suppressed` option merges with the launcher suppression decision so a command-line `false` can never undo it.

Usage

Import this module when you need to:

  • Register global CLI options on a yargs command builder
  • Add a new command group that should inherit the standard config/log/telemetry flags
  • Access the `GlobalOptions` TypeScript interface for typed option access
  • Understand which `ONE_MCP_*` environment variable backs each CLI flag

Code Reference

Source Location

Signature

export const globalOptions = {
  'product-telemetry': { type: 'string'; coerce: coerceTelemetryBoolean; default: undefined };
  'product-telemetry-ci': { type: 'string'; coerce: coerceTelemetryBoolean; default: undefined };
  'product-telemetry-test-suppressed': { type: 'boolean'; hidden: true; default: undefined };
  'project-owner': { type: 'string'; default: undefined };
  config: { alias: 'c'; type: 'string'; default: undefined };
  'config-dir': { alias: 'd'; type: 'string'; default: undefined };
  'cli-session-cache-path': { type: 'string'; default: undefined };
  'log-level': { type: 'string'; choices: ['debug','info','warn','error']; default: undefined };
  'log-file': { type: 'string'; default: undefined };
} as const;

export function withGlobalOptions(yargs: Argv): Argv<GlobalOptions>;

export interface GlobalOptions {
  'product-telemetry'?: boolean;
  'product-telemetry-ci'?: boolean;
  'product-telemetry-test-suppressed'?: boolean;
  'project-owner'?: string;
  config?: string;
  'config-dir'?: string;
  'cli-session-cache-path'?: string;
  'log-level'?: 'debug' | 'info' | 'warn' | 'error';
  'log-file'?: string;
}

function coerceTelemetryBoolean(value: unknown): boolean | undefined;

Import

import { globalOptions, withGlobalOptions, GlobalOptions } from '@src/globalOptions.js';

I/O Contract

Inputs

Name Type Required Description
yargs Argv Yes The yargs instance to register global options on
ONE_MCP_CONFIG env string No Config file path (backing `--config`)
ONE_MCP_CONFIG_DIR env string No Config directory path (backing `--config-dir`)
ONE_MCP_LOG_LEVEL env string No Log level: debug/info/warn/error
ONE_MCP_LOG_FILE env string No Log file path
ONE_MCP_PRODUCT_TELEMETRY env string No Enable/disable product telemetry
ONE_MCP_PROJECT_OWNER env string No Override session ownership credential
ONE_MCP_CLI_SESSION_CACHE_PATH env string No CLI session cache path template with {pid}/{scope}

Outputs

Name Type Description
return Argv<GlobalOptions> yargs instance with global options registered and telemetry bootstrap middleware attached
middleware function `configureProductTelemetryBootstrap` applied as pre-parse middleware

Usage Examples

Registering Global Options on a Command Builder

import yargs from 'yargs';
import { withGlobalOptions } from '@src/globalOptions.js';

// Register global options once; nested commands inherit them
const parser = withGlobalOptions(yargs(process.argv.slice(2)))
  .command('serve', 'Start the 1MCP server', (y) => {
    // serve-specific options added here
    return y;
  })
  .parse();

Accessing Global Options in a Handler

import type { GlobalOptions } from '@src/globalOptions.js';

// In a command handler, global options are merged with command options
function handler(argv: GlobalOptions & { port: number }) {
  const configPath = argv.config;        // --config or ONE_MCP_CONFIG
  const configDir = argv['config-dir']; // --config-dir or ONE_MCP_CONFIG_DIR
  const logLevel = argv['log-level'];    // --log-level or ONE_MCP_LOG_LEVEL
  const telemetry = argv['product-telemetry']; // boolean | undefined
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment