mcp-cli-scripts
Install this skill
npx skills add jezweb/claude-skillsWorks across Claude Code, Cursor, Codex, Copilot & Antigravity
The mcp-cli-scripts pattern establishes a standard for augmenting Model Context Protocol servers with specialized command-line interfaces. By deploying companion scripts alongside an MCP server, developers provide Claude Code users with terminal-native capabilities that transcend standard chat-based interaction limits. These scripts support high-volume file processing, local caching, and piping mechanisms that standard MCP tools cannot accommodate due to their stateless design. Built on the tsx execution environment, these scripts maintain structured JSON output to ensure reliable parsing by AI agents. This directory structure encourages logic separation by moving core functionality into shared modules, allowing the same backend logic to serve both interactive web sessions via MCP and automated terminal workflows, effectively bridging the gap between conversational AI and local system administration tasks.
When to Use This Skill
- β’Processing large CSV or JSON datasets locally without token limits
- β’Chaining multiple data transformation steps in a shell pipe
- β’Running automated tasks that require persistent local state
- β’Exporting structured tool output directly to specific file formats
How to Invoke This Skill
Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:
- βRun the local CLI script for this tool
- βProcess this file using the companion script
- βExecute the tool directly in the terminal
- βUse the CLI version of this MCP tool
- βRun the script with these specific arguments
Pro Tips
- π‘Design your CLI scripts to be idempotent where possible, ensuring they can be re-run safely without unintended side effects.
- π‘Leverage the `_shared.ts` pattern for common functionalities like authentication and configuration, promoting consistency and reducing boilerplate across your scripts.
- π‘Integrate robust error handling and clear logging into your scripts to facilitate debugging and ensure reliable execution in various terminal environments.
What this skill does
- β’Execute TypeScript scripts directly via npx tsx shebangs
- β’Pipe structured JSON data between local shell processes
- β’Support local file system I/O for batch data operations
- β’Implement TTL-based local caching for performance
- β’Standardize argument parsing across multiple utility scripts
When not to use it
- βSimple one-off queries within the Claude web interface
- βSituations requiring purely conversational UI-based interaction
Example workflow
- Install tsx as a project dependency
- Extract business logic into a shared core module
- Create a script in the scripts/ folder using the template
- Register the tool in SCRIPTS.md for documentation
- Invoke the script from the terminal using npx tsx
Prerequisites
- βNode.js environment
- βtsx (TypeScript Execute) installed as a dev dependency
Pitfalls & limitations
- !Mixing prose output with JSON breaks agent parsing
- !Inconsistent argument naming creates confusion for Claude Code
- !Hardcoding absolute paths instead of using relative input flags
FAQ
How it compares
While manual scripts often use ad-hoc patterns, this structure forces a consistent interface of JSON-only output and standardized arguments, making your tools immediately discoverable and usable by Claude Code.
π Full skill instructions β original source: jezweb/claude-skills
**Status**: Production Ready
**Last Updated**: 2026-01-09
**Dependencies**: tsx (dev dependency)
**Current Versions**: [email protected]
---
## Why CLI Scripts Alongside MCP Servers?
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 |
---
## Directory Structure
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---
## The 5 Design Principles
### 1. One Script Per Tool
Each script does one thing well, matching an MCP tool but with extended capabilities.
### 2. JSON Output by Default
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:");### 3. Extended Capabilities for Local Use
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### 4. Consistent Argument Patterns
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### 5. Shebang and Direct Execution
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
*/---
## Critical Rules
### Always Do
β 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: "..." }### Never Do
β 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)---
## When to Use Scripts vs MCP
**Use CLI scripts when:**
- Working in terminal/Claude Code environment
- Need to save results to files
- Processing batch inputs from files
- Chaining multiple operations
- Need caching for repeated lookups
- Want richer output formats
**Use MCP tools when:**
- In Claude.ai web interface
- Simple one-off lookups
- No file I/O needed
- Building conversational flows
---
## Shared Code Between MCP and Scripts
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 coreHowever, keeping them separate is also fine - the scripts may evolve to have capabilities the MCP can't support, and that's okay.
---
## Using Bundled Resources
### Templates (templates/)
**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### Rules (rules/)
**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/---
## Dependencies
**Required**:
- [email protected] - TypeScript execution without compilation
Add to package.json:
{
"devDependencies": {
"tsx": "^4.21.0"
}
}---
## Official Documentation
- **tsx**: https://github.com/privatenumber/tsx
- **Node.js CLI**: https://nodejs.org/api/cli.html
---
## Package Versions (Verified 2026-01-09)
{
"devDependencies": {
"tsx": "^4.21.0"
}
}---
## Complete Setup Checklist
- [ ] Create
scripts/ directory in MCP server project- [ ] Add tsx to devDependencies
- [ ] Create first script from template
- [ ] Create SCRIPTS.md from template
- [ ] Test script:
npx tsx scripts/tool-name.ts --help- [ ] Verify JSON output format
- [ ] Document all scripts in SCRIPTS.md
---
# MCP CLI Scripts Corrections
Apply when editing TypeScript files in
scripts/ directories.## Shebang
| If Claude suggests... | Use instead... |
|----------------------|----------------|
|
#!/usr/bin/env node | #!/usr/bin/env npx tsx ||
#!/usr/bin/env ts-node | #!/usr/bin/env npx tsx || No shebang | Add
#!/usr/bin/env npx tsx at top |**Why**: tsx handles ESM + TypeScript without compilation. Node requires transpilation. ts-node has compatibility issues.
## Output Format
| If Claude suggests... | Use instead... |
|----------------------|----------------|
|
console.log("Found 5 results") | console.log(JSON.stringify({ success: true, count: 5 })) ||
console.log(data) | console.log(JSON.stringify(data, null, 2)) || Unstructured text output | Structured JSON output |
**Why**: JSON output is machine-readable. Claude Code can parse and use structured data.
## Error Handling
| If Claude suggests... | Use instead... |
|----------------------|----------------|
|
console.error("Error: " + err.message) | console.error(JSON.stringify({ success: false, error: err.message })) ||
throw new Error(...) without catching | Catch and output JSON error ||
process.exit(1) without error output | Output JSON error, then exit |**Why**: Consistent error format allows Claude Code to detect and handle failures.
## Argument Patterns
Use these standard argument names consistently:
| Pattern | Description |
|---------|-------------|
|
--input <file> | Read input from file ||
--output <file> | Write output to file ||
--format <type> | Output format (json/csv/table) ||
--verbose | Debug output ||
--help or -h | Show usage |**Why**: Consistent patterns reduce cognitive load. Claude can predict script interfaces.
## Verbose Output
| If Claude suggests... | Use instead... |
|----------------------|----------------|
|
console.log("Processing...") | if (args.verbose) console.error("Processing...") || Status messages to stdout | Status messages to stderr (preserves stdout for data) |
**Why**: Verbose output should go to stderr so stdout contains only the result data.
How to Use This Skill Unit
Option A: Project-Specific (Recommended)
- Click "Download" above
- In your project, create the directory:
.agent/skills/mcp-cli-scripts/ - Save the file as
SKILL.md - The agent will automatically discover the skill based on its description.
Option B: Global Installation (All Agents)
Save the file to these locations to make it available across all projects:
- Claude Code:
~/.claude/skills/jezweb/claude-skills/mcp-cli-scripts/SKILL.md - Cursor:
~/.cursor/skills/jezweb/claude-skills/mcp-cli-scripts/SKILL.md - Antigravity:
~/.gemini/antigravity/skills/jezweb/claude-skills/mcp-cli-scripts/SKILL.md
π Install with CLI:npx skills add jezweb/claude-skills
