$ show openclaw/mcporter
mcporter is a portable Model Context Protocol (MCP) runtime, CLI, and code-generation toolkit. It connects to configured MCP serversβover stdio, HTTP/SSE, or Chrome DevTools relayβand exposes their tools via a rich command-line interface (subcommands: list, call, resource, auth, config, serve, daemon, generate-cli, emit-ts, record, replay) and a programmatic API (createRuntime, createServerProxy). The architecture is modular: a config layer merges JSON/JSONC files and imports from common editor configs (Cursor, Claude, VS Code); a runtime layer manages transport connections with OAuth support, record/replay, and error classification; a daemon process pools keep-alive servers for low-latency reuse; and a codegen subsystem produces standalone CLIs or typed TypeScript clients from server schemas. The codebase is heavily tested (~150 test files, coverage β₯89.6%), follows modern TypeScript patterns, and supports protocol versions from 2024-10-07 to 2026-07-28. It is not a data pipeline or research projectβit is a production-grade developer tool for integrating MCP-powered agents and workflows.
The LLM identified 5 files worth highlighting for reuse:
Provides atomic file reads/writes with cross-process file locking (withFileLock), including stale-lock recovery, timeout, and Windows retry handling. The lock is reentrant and uses a local lock tail to avoid false timeouts. This module is self-contained and can be extracted to any project needing safe concurrent file access.
Implements analyzeConnectionError to categorize transport failures into typed buckets: auth, offline, HTTP-status, stdio-exit, and unknown. Returns a structured object with errorClass, isAuthError, isOfflineError, isHttpError, etc. The function is purely heuristic-based, takes an Error and config, and is reusable across any MCP client or similar HTTP/stdio proxy.
Defines createCallResult to parse MCP tool call responses into structured helpers: .text(), .markdown(), .json(), .images(), .content(). Handles text, JSON, image (base64), and structured content parts (audio, video, resource). The module is small and isolated, depending only on basic types, and can be reused in any MCP client to normalize tool output.
Exports serializeStable for deterministic JSON serialization: object keys sorted, Map/Set serialized as arrays, BigInt as strings, no whitespace. Used by the daemon to compute definition hashes. This pure utility has zero dependencies and can be lifted into any TypeScript project needing canonical JSON output.
Provides three implementations of the OAuthPersistence interface: DirectoryPersistence (file-based), VaultPersistence (encrypted vault), and CompositePersistence (fallback chain). Supports token generation tracking, store reconciliation, and selective clearing. The interface is well-defined and the implementations are self-contained, making them reusable for any OAuth token storage scenario.