Skip to main content
Glama
cli.ts3.99 kB
import { Command } from 'commander'; import type { CLIArgs } from './config/loader.js'; /** * Parse command line arguments */ export function parseArgs(argv: string[] = process.argv): CLIArgs { const program = new Command(); program .name('openapi-mcp') .description('Turn any OpenAPI or Postman spec into an MCP server') .version('1.0.0') .option('--spec-url <url>', 'URL to fetch spec from') .option('--spec-file <file>', 'Path to local spec file') .option('--format <format>', 'Spec format: openapi or postman (auto-detected if not specified)') .option('--upstream-url <url>', 'Base URL of the upstream API') .option('-p, --port <port>', 'Port to listen on', parseInt) .option('-h, --host <host>', 'Host to bind to') .option('-c, --config <file>', 'Path to config file') .option('--log-level <level>', 'Log level (debug, info, warn, error)') .option('--log-format <format>', 'Log format (json, pretty)') .option('--include-tools <patterns>', 'Include tools matching glob patterns (comma-separated)') .option('--exclude-tools <patterns>', 'Exclude tools matching glob patterns (comma-separated)') .option('--exclude-methods <methods>', 'Exclude HTTP methods (comma-separated, e.g., DELETE,PATCH)') .option('--include-tags <tags>', 'Include only operations with these tags (comma-separated)') .option('--no-tool-warning', 'Suppress tool count warnings'); program.parse(argv); const opts = program.opts<{ specUrl?: string; specFile?: string; format?: string; upstreamUrl?: string; port?: number; host?: string; config?: string; logLevel?: string; logFormat?: string; includeTools?: string; excludeTools?: string; excludeMethods?: string; includeTags?: string; toolWarning?: boolean; }>(); return { specUrl: opts.specUrl, specFile: opts.specFile, format: opts.format, upstreamUrl: opts.upstreamUrl, port: opts.port, host: opts.host, config: opts.config, logLevel: opts.logLevel, logFormat: opts.logFormat, includeTools: opts.includeTools, excludeTools: opts.excludeTools, excludeMethods: opts.excludeMethods, includeTags: opts.includeTags, toolWarning: opts.toolWarning, }; } /** * Print startup banner */ export function printBanner(): void { const banner = ` ╔═══════════════════════════════════════════════════════════╗ ║ openapi-mcp-ts ║ ║ Turn any OpenAPI spec into an MCP server ║ ╚═══════════════════════════════════════════════════════════╝ `; process.stdout.write(banner); } /** * Print help for common issues */ export function printHelp(): void { const help = ` Usage: openapi-mcp --spec-url <url> --upstream-url <url> Examples: # Start with OpenAPI spec (Petstore API) openapi-mcp --spec-url https://petstore.swagger.io/v3/openapi.json --upstream-url https://petstore.swagger.io/v3 # Use local OpenAPI spec file openapi-mcp --spec-file ./openapi.yaml --upstream-url https://api.example.com # Use Postman collection openapi-mcp --spec-file ./collection.json --format postman --upstream-url https://api.example.com # With config file openapi-mcp --config ./config.yaml Environment Variables: SPEC_URL - Spec URL (OpenAPI or Postman collection) SPEC_FORMAT - Spec format: openapi or postman (auto-detected if not set) UPSTREAM_URL - Upstream API base URL PORT - Server port (default: 8080) LOG_LEVEL - Log level (debug, info, warn, error) LOG_FORMAT - Log format (json, pretty) For more information, visit: https://github.com/procoders/openapi-mcp-ts `; process.stdout.write(help); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/procoders/openapi-mcp-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server