Build CLI scripts alongside MCP servers for terminal environments. Scripts provide file I/O, batch processing, caching, and richer output formats that remote MCP servers cannot offer. Includes templates for TypeScript scripts and SCRIPTS.md. Use when: creating MCP server companion scripts, adding batch processing to MCP tools, saving MCP results to files, building CLI wrappers for APIs, or troubleshooting "context too large", "no file access", or batch input handling.
/plugin marketplace add jezweb/claude-skills/plugin install jezweb-tooling-skills@jezweb/claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdrules/mcp-cli-scripts.mdtemplates/SCRIPTS-TEMPLATE.mdtemplates/script-template.tsStatus: Production Ready Last Updated: 2025-12-27 Dependencies: tsx (dev dependency) Latest Versions: tsx@4.19.2
When building MCP servers, also create companion CLI scripts that provide the same (and often extended) functionality for use with Claude Code in terminal environments.
| Aspect | Remote MCP (Claude.ai) | CLI Scripts (Claude Code) |
|---|---|---|
| Context | Results flow through model context window | Results stay local, only relevant parts shared |
| File System | No access | Full read/write access |
| Batch Operations | One call at a time | Can process files of inputs |
| Caching | Stateless | Can cache results locally |
| Output | JSON to model | JSON, CSV, table, file, or stdout |
| Chaining | Model orchestrates | Scripts can pipe/chain directly |
mcp-{name}/
├── src/
│ └── index.ts # MCP server (for Claude.ai, remote clients)
├── scripts/
│ ├── {tool-name}.ts # One script per tool
│ ├── {another-tool}.ts
│ └── _shared.ts # Shared auth/config helpers (optional)
├── SCRIPTS.md # Documents available scripts for Claude Code
├── package.json
└── README.md
Each script does one thing well, matching an MCP tool but with extended capabilities.
Scripts output JSON to stdout for easy parsing. Claude Code can read and use the results.
// Good - structured output
console.log(JSON.stringify({ success: true, data: result }, null, 2));
// Avoid - unstructured text (unless --format text requested)
console.log("Found 5 results:");
CLI scripts can offer features that don't make sense for remote MCP:
// Input/Output files
--input data.csv // Batch process from file
--output results.json // Save results to file
--append // Append to existing file
// Caching
--cache // Use local cache
--cache-ttl 3600 // Cache for 1 hour
--no-cache // Force fresh request
// Output formats
--format json|csv|table // Different output formats
--quiet // Suppress non-essential output
--verbose // Extra debugging info
// Batch operations
--batch // Process multiple items
--concurrency 5 // Parallel processing limit
Use consistent patterns across all scripts:
# Standard patterns
--input <file> # Read input from file
--output <file> # Write output to file
--format <type> # Output format
--profile <name> # Auth profile (for multi-account)
--verbose # Debug output
--help # Show usage
Scripts should be directly executable:
#!/usr/bin/env npx tsx
/**
* Brief description of what this script does
*
* Usage:
* npx tsx scripts/tool-name.ts <required-arg>
* npx tsx scripts/tool-name.ts --option value
*
* Examples:
* npx tsx scripts/tool-name.ts 12345
* npx tsx scripts/tool-name.ts --input batch.csv --output results.json
*/
✅ Use #!/usr/bin/env npx tsx shebang (not node or ts-node)
✅ Output JSON to stdout by default
✅ Use consistent argument patterns across all scripts
✅ Document scripts in SCRIPTS.md
✅ Handle errors with structured JSON: { success: false, error: "..." }
❌ Use console.log() for prose output (use structured JSON)
❌ Use different argument patterns per script
❌ Forget to document the script in SCRIPTS.md
❌ Use node or ts-node in shebang (tsx handles ESM+TypeScript)
Use CLI scripts when:
Use MCP tools when:
If you want to share logic between MCP and scripts, extract to a core module:
src/
├── core/
│ ├── lookup.ts # Pure function, no I/O assumptions
│ └── index.ts # Export all core functions
├── mcp/
│ └── index.ts # MCP handlers, import from core
└── cli/
└── lookup.ts # CLI wrapper, import from core
However, keeping them separate is also fine - the scripts may evolve to have capabilities the MCP can't support, and that's okay.
script-template.ts: Complete TypeScript script template with argument parsing, JSON output, and file I/O patterns.
# Copy to your project
cp ~/.claude/skills/mcp-cli-scripts/templates/script-template.ts scripts/new-tool.ts
SCRIPTS-TEMPLATE.md: Template for documenting available scripts in an MCP server repo.
# Copy to your project
cp ~/.claude/skills/mcp-cli-scripts/templates/SCRIPTS-TEMPLATE.md SCRIPTS.md
mcp-cli-scripts.md: Correction rules for script files. Copy to .claude/rules/ in projects:
cp ~/.claude/skills/mcp-cli-scripts/rules/mcp-cli-scripts.md .claude/rules/
Required:
Add to package.json:
{
"devDependencies": {
"tsx": "^4.19.2"
}
}
{
"devDependencies": {
"tsx": "^4.19.2"
}
}
scripts/ directory in MCP server projectnpx tsx scripts/tool-name.ts --helpThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.