Back to AI Tools & Agents

mcp-cli-scripts

CLIscriptsClaude CodeCursorMCPAI Agentautomationlocal developmenttypescript
⭐ 860πŸ“„ MITπŸ•’ 2026-06-11Source β†—

Install this skill

npx skills add jezweb/claude-skills

Works 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

  1. Install tsx as a project dependency
  2. Extract business logic into a shared core module
  3. Create a script in the scripts/ folder using the template
  4. Register the tool in SCRIPTS.md for documentation
  5. 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

Why include CLI scripts if I already have an MCP server?
CLI scripts provide full file system access, local caching, and batch processing capabilities that aren't possible within the stateless MCP protocol used by web interfaces.
Should I share code between the MCP server and the CLI scripts?
Yes, move your logic into a core module and import those functions into both your MCP handlers and your CLI wrappers to ensure consistency.
Why must I use npx tsx instead of node?
tsx natively handles TypeScript execution and modern ESM imports without requiring a separate compilation step or complex ts-node configurations.

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.

Source & trust

⭐ 860 starsπŸ“„ MITπŸ•’ Updated 2026-06-11
πŸ“„ Full skill instructions β€” original source: jezweb/claude-skills
# MCP CLI Scripts Pattern

**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 core


However, 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)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/mcp-cli-scripts/
  3. Save the file as SKILL.md
  4. 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

Read the Master Guide: Mastering Agent Skills β†’

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid ai tools & agents issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under AI Tools & Agents and is published by JezWeb, maintained in jezweb/claude-skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.