Add inline stdio command support to mcpc connect#173
Open
Conversation
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.
0f1983f to
8eb3cd9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for spawning local stdio MCP servers directly via
mcpc connectwithout requiring a config file. Users can now pass an inline command either as a quoted string or via the--separator.Fixes #163
Key Changes
shellSplit()utility to parse shell-style command strings with support for single/double quotes and backslash escapes (no variable expansion)parseServerArg()to recognize multi-token strings as inline stdio commands (e.g.,"npx -y @scope/server-fs /tmp")matchSessionByTarget()andpickAvailableSessionName()in newsession-matching.tsmodule to match and reuse sessions based on exact command+args+env equalitygenerateSessionName()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.)extractInlineCommandTokens()to intercept--separator before Commander parses argv, preventing it from treating post---tokens as options--profile,--header,--x402) and cannot be combined with a server URL argument--separator formsImplementation Details
--form allows commands with spaces without quoting:mcpc connect @session -- npx -y @scope/server /pathmcpc connect "npx -y @scope/server /path"https://claude.ai/code/session_017oZBCyhwnNg455eZjE7sQ7