Skip to content

Commit be418ad

Browse files
committed
fix stdin
1 parent 1aa51ed commit be418ad

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@ Input Schema:
186186
# With inline JSON
187187
$ mcp-cli github/search_repositories '{"query": "mcp server", "per_page": 5}'
188188

189-
# From stdin (pipe)
190-
$ echo '{"query": "mcp"}' | mcp-cli github/search_repositories
191-
192189
# JSON output for scripting
193190
$ mcp-cli github/search_repositories '{"query": "mcp"}' --json | jq '.content[0].text'
191+
192+
# Chain Calls and outputs
193+
$ echo '{"path": "./README.md"}' | mcp-cli filesystem/read_file
194+
194195
```
195196
196-
#### Complex JSON with Quotes
197+
#### Complex Commands
197198
198199
For JSON arguments containing single quotes, special characters, or long text, use **stdin** to avoid shell escaping issues:
199200
@@ -212,6 +213,9 @@ cat args.json | mcp-cli server/tool
212213

213214
# Using jq to build complex JSON
214215
jq -n '{query: "mcp", filters: ["active", "starred"]}' | mcp-cli github/search
216+
217+
# Find all TypeScript files and read the first one
218+
mcp-cli filesystem/search_files '{"path": "src/", "pattern": "*.ts"}' --json | jq -r '.content[0].text' | head -1 | xargs -I {} sh -c 'mcp-cli filesystem/read_file "{\"path\": \"{}\"}"'
215219
```
216220
217221
**Why stdin?** Shell interpretation of `{}`, quotes, and special characters requires careful escaping. Stdin bypasses shell parsing entirely, making it reliable for any JSON content.
@@ -322,6 +326,9 @@ $ echo '{"query": "mcp"}' | mcp-cli github/search_repositories
322326
mcp-cli server/tool <<EOF
323327
{"content": "Text with 'single quotes' and \"double quotes\""}
324328
EOF
329+
330+
# Complex Command chaining with xargs and jq
331+
mcp-cli filesystem/search_files '{"path": "src/", "pattern": "*.ts"}' --json | jq -r '.content[0].text' | head -1 | xargs -I {} sh -c 'mcp-cli filesystem/read_file "{\"path\": \"{}\"}"'
325332
```
326333
327334
### Rules

SKILL.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ EOF
5757

5858
# Or pipe from a file/command
5959
cat args.json | mcp-cli server/tool
60+
61+
# Complex Command chaining with xargs and jq
62+
mcp-cli filesystem/search_files '{"path": "src/", "pattern": "*.ts"}' --json | jq -r '.content[0].text' | head -1 | xargs -I {} sh -c 'mcp-cli filesystem/read_file "{\"path\": \"{}\"}"'
6063
```
6164

6265

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ function parseArgs(args: string[]): ParsedArgs {
104104
if (positional.length > 1) {
105105
result.command = 'call';
106106
result.args = positional.slice(1).join(' ');
107+
} else if (!process.stdin.isTTY) {
108+
// If stdin has data (piped input), treat as call command
109+
result.command = 'call';
107110
} else {
108111
result.command = 'info';
109112
}

0 commit comments

Comments
 (0)