Skip to content

Add inline stdio command support to mcpc connect#173

Open
jancurn wants to merge 1 commit intomainfrom
claude/design-config-handling-lHFK3
Open

Add inline stdio command support to mcpc connect#173
jancurn wants to merge 1 commit intomainfrom
claude/design-config-handling-lHFK3

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented Apr 15, 2026

Summary

This PR adds support for spawning local stdio MCP servers directly via mcpc connect without requiring a config file. Users can now pass an inline command either as a quoted string or via the -- separator.

Fixes #163

Key Changes

  • Inline command parsing: Added shellSplit() utility to parse shell-style command strings with support for single/double quotes and backslash escapes (no variable expansion)
  • Command target support: Extended parseServerArg() to recognize multi-token strings as inline stdio commands (e.g., "npx -y @scope/server-fs /tmp")
  • Session matching for commands: Implemented matchSessionByTarget() and pickAvailableSessionName() in new session-matching.ts module to match and reuse sessions based on exact command+args+env equality
  • Auto-generated session names: Extended generateSessionName() to derive names from command basenames (e.g., npx@npx, node@node), with numeric suffixes always appended for inline commands (@npx-1, @npx-2, etc.)
  • CLI argument extraction: Added extractInlineCommandTokens() to intercept -- separator before Commander parses argv, preventing it from treating post--- tokens as options
  • Flag validation: Inline commands reject incompatible flags (--profile, --header, --x402) and cannot be combined with a server URL argument
  • Comprehensive testing: Added 420+ lines of unit tests for session matching logic and 130+ lines of e2e tests covering both heuristic (quoted string) and -- separator forms

Implementation Details

  • Session reuse for inline commands requires exact match on command binary, arguments, and environment variables (unlike URL-based sessions which match on normalized URL + profile + header keys)
  • The -- form allows commands with spaces without quoting: mcpc connect @session -- npx -y @scope/server /path
  • The heuristic form requires quoting the entire command string: mcpc connect "npx -y @scope/server /path"
  • No shell variable expansion is performed on inline commands — the shell is the only expansion layer
  • Session matching logic extracted to pure functions for testability without CLI dependencies

https://claude.ai/code/session_017oZBCyhwnNg455eZjE7sQ7

Lets users spawn a stdio MCP server directly from `mcpc connect` without
writing a config file. Two surface forms:

  mcpc connect "npx -y @modelcontextprotocol/server-filesystem /tmp"
  mcpc connect @stdio -- node dist/stdio.js

The heuristic form treats any positional arg containing whitespace (and
not ending in .json/.yaml) as a shell-split command. The `--` form is
the explicit escape hatch for single-word binaries or paths with spaces.

Session names auto-generate from the command basename with an always-on
numeric suffix (e.g. @npx-1, @Node-1). Identical re-runs reuse the
existing session via exact match on command + args + env. Auth flags
(--header, --profile, --no-profile, --x402) are rejected with a clear
error since they only apply to HTTP servers.

Per design discussion in #163, env-var substitution is NOT applied to
inline command tokens — the user's shell handles ${VAR} expansion.

Also extracts session-matching and name-suffix-picking into a pure
src/lib/session-matching.ts module so they can be unit-tested without
pulling in chalk/CLI deps.
@jancurn jancurn force-pushed the claude/design-config-handling-lHFK3 branch from 0f1983f to 8eb3cd9 Compare April 15, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --command/--arg/--env flags to connect stdio servers without a config file

3 participants