Skip to content

Skills for Claude Code CLI such as full stack dev Cloudflare, React, Tailwind v4, and AI integrations.

feat(mcp-cli-scripts): Add skill for CLI scripts alongside MCP servers

Jezbb0b7494c939
diff --git a/skills/mcp-cli-scripts/.claude-plugin/plugin.json b/skills/mcp-cli-scripts/.claude-plugin/plugin.json
new file mode 100644
index 00000000..a4d3d1c7
--- /dev/null
+++ b/skills/mcp-cli-scripts/.claude-plugin/plugin.json
@@ -0,0 +1,12 @@
+{
+ "name": "mcp-cli-scripts",
+ "description": "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. └── lookup.ts # CLI wrapp",
+ "version": "1.0.0",
+ "author": {
+ "name": "Jeremy Dawes",
+ "email": "[email protected]"
+ },
+ "license": "MIT",
+ "repository": "https://github.com/jezweb/claude-skills",
+ "keywords": []
+}
diff --git a/skills/mcp-cli-scripts/README.md b/skills/mcp-cli-scripts/README.md
new file mode 100644
index 00000000..58704621
--- /dev/null
+++ b/skills/mcp-cli-scripts/README.md
@@ -0,0 +1,42 @@
+# MCP CLI Scripts
+
+Build CLI scripts alongside MCP servers for Claude Code terminal environments.
+
+## Auto-Trigger Keywords
+
+This skill should be invoked when discussing:
+
+- MCP server scripts, CLI scripts for MCP, MCP companion scripts
+- SCRIPTS.md, batch processing MCP, MCP file output
+- npx tsx scripts, TypeScript CLI scripts
+- MCP batch operations, MCP caching, MCP file I/O
+- Saving MCP results to files
+- Processing batch inputs for MCP tools
+- CLI wrappers for APIs
+
+## What This Skill Provides
+
+1. **Pattern**: Why and when to create CLI scripts alongside MCP servers
+2. **Templates**: TypeScript script template, SCRIPTS.md documentation template
+3. **Rules**: Correction rules for consistent script patterns
+4. **Best Practices**: JSON output, argument patterns, error handling
+
+## Quick Start
+
+```bash
+# Copy templates to your MCP server project
+cp ~/.claude/skills/mcp-cli-scripts/templates/script-template.ts scripts/new-tool.ts
+cp ~/.claude/skills/mcp-cli-scripts/templates/SCRIPTS-TEMPLATE.md SCRIPTS.md
+
+# Install tsx
+npm install -D tsx
+
+# Run your script
+npx tsx scripts/new-tool.ts --help
+```
+
+## Related Skills
+
+- `fastmcp` - Python MCP server framework
+- `typescript-mcp` - TypeScript MCP patterns
+- `cloudflare-mcp-server` - Cloudflare-hosted MCP servers
diff --git a/skills/mcp-cli-scripts/SKILL.md b/skills/mcp-cli-scripts/SKILL.md
new file mode 100644
index 00000000..b04b370e
--- /dev/null
+++ b/skills/mcp-cli-scripts/SKILL.md
@@ -0,0 +1,257 @@
+---
+name: mcp-cli-scripts
+description: |
+ 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.
+---
+
+# MCP CLI Scripts Pattern
+
+**Status**: Production Ready
+**Last Updated**: 2025-12-27
+**Dependencies**: tsx (dev dependency)
+**Latest 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.
+
+```typescript
+// 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:
+
+```typescript
+// 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:
+
+```bash
+# 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:
+
+```typescript
+#!/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.
+
+```bash
+# 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.
+
+```bash
+# 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:
+
+```bash
+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:
+```json
+{
+ "devDependencies": {
+ "tsx": "^4.19.2"
+ }
+}
+```
+
+---
+
+## Official Documentation
+
+- **tsx**: https://github.com/privatenumber/tsx
+- **Node.js CLI**: https://nodejs.org/api/cli.html
+
+---
+
+## Package Versions (Verified 2025-12-27)
+
+```json
+{
+ "devDependencies": {
+ "tsx": "^4.19.2"
+ }
+}
+```
+
+---
+
+## 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
diff --git a/skills/mcp-cli-scripts/rules/mcp-cli-scripts.md b/skills/mcp-cli-scripts/rules/mcp-cli-scripts.md
new file mode 100644
index 00000000..4929d27c
--- /dev/null
+++ b/skills/mcp-cli-scripts/rules/mcp-cli-scripts.md
@@ -0,0 +1,56 @@
+# 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.
diff --git a/skills/mcp-cli-scripts/templates/SCRIPTS-TEMPLATE.md b/skills/mcp-cli-scripts/templates/SCRIPTS-TEMPLATE.md
new file mode 100644
index 00000000..89482ac6
--- /dev/null
+++ b/skills/mcp-cli-scripts/templates/SCRIPTS-TEMPLATE.md
@@ -0,0 +1,72 @@
+# CLI Scripts
+
+These scripts provide command-line access to {server-name} functionality.
+For use with Claude Code in terminal environments.
+
+## Prerequisites
+
+- Node.js 18+
+- Run `npm install` in this directory
+
+## Available Scripts
+
+### {tool-name}.ts
+
+{Description of what this tool does}
+
+**Usage:**
+```bash
+npx tsx scripts/{tool-name}.ts <required-arg>
+npx tsx scripts/{tool-name}.ts --option value
+```
+
+**Arguments:**
+- `<required-arg>` - Description
+- `--option <value>` - Description (default: x)
+
+**Examples:**
+```bash
+# Basic usage
+npx tsx scripts/{tool-name}.ts 12345
+
+# With options
+npx tsx scripts/{tool-name}.ts --input batch.csv --output results.json
+
+# Verbose mode
+npx tsx scripts/{tool-name}.ts 12345 --verbose
+```
+
+**Output:**
+```json
+{
+ "success": true,
+ "data": { ... }
+}
+```
+
+### {another-tool}.ts
+
+...
+
+## Common Options
+
+All scripts support these common options:
+
+| Option | Description |
+|--------|-------------|
+| `--output <file>` | Write results to file instead of stdout |
+| `--format <type>` | Output format: json, csv, table |
+| `--verbose` | Show debug information |
+| `--help` | Show usage information |
+
+## Error Handling
+
+Scripts exit with code 0 on success, non-zero on failure.
+Errors are output as JSON:
+
+```json
+{
+ "success": false,
+ "error": "Error message here"
+}
+```
diff --git a/skills/mcp-cli-scripts/templates/script-template.ts b/skills/mcp-cli-scripts/templates/script-template.ts
new file mode 100644
index 00000000..6eb54435
--- /dev/null
+++ b/skills/mcp-cli-scripts/templates/script-template.ts
@@ -0,0 +1,159 @@
+#!/usr/bin/env npx tsx
+/**
+ * {Tool Name} - {Brief description}
+ *
+ * Usage:
+ * npx tsx scripts/{tool-name}.ts <args>
+ * npx tsx scripts/{tool-name}.ts --help
+ *
+ * Examples:
+ * npx tsx scripts/{tool-name}.ts {example}
+ */
+
+import * as fs from 'fs';
+import * as path from 'path';
+
+// ============================================================================
+// Configuration
+// ============================================================================
+
+interface Config {
+ // Add config options
+}
+
+function loadConfig(): Config {
+ // Load from env, config file, etc.
+ return {};
+}
+
+// ============================================================================
+// Argument Parsing
+// ============================================================================
+
+interface Args {
+ // Define expected arguments
+ input?: string;
+ output?: string;
+ format: 'json' | 'csv' | 'table';
+ verbose: boolean;
+ help: boolean;
+}
+
+function parseArgs(): Args {
+ const args = process.argv.slice(2);
+ const parsed: Args = {
+ format: 'json',
+ verbose: false,
+ help: false,
+ };
+
+ for (let i = 0; i < args.length; i++) {
+ switch (args[i]) {
+ case '--input':
+ parsed.input = args[++i];
+ break;
+ case '--output':
+ parsed.output = args[++i];
+ break;
+ case '--format':
+ parsed.format = args[++i] as Args['format'];
+ break;
+ case '--verbose':
+ parsed.verbose = true;
+ break;
+ case '--help':
+ case '-h':
+ parsed.help = true;
+ break;
+ }
+ }
+
+ return parsed;
+}
+
+function showHelp(): void {
+ console.log(`
+{Tool Name} - {Description}
+
+Usage:
+ npx tsx scripts/{tool-name}.ts [options] <args>
+
+Options:
+ --input <file> Read input from file
+ --output <file> Write output to file
+ --format <type> Output format: json, csv, table (default: json)
+ --verbose Show debug information
+ --help, -h Show this help
+
+Examples:
+ npx tsx scripts/{tool-name}.ts example-arg
+ npx tsx scripts/{tool-name}.ts --input data.csv --output results.json
+`);
+}
+
+// ============================================================================
+// Core Logic
+// ============================================================================
+
+interface Result {
+ success: boolean;
+ data?: unknown;
+ error?: string;
+}
+
+async function execute(/* params */): Promise<Result> {
+ // Implement core logic here
+ // This could also import from a shared module
+ return { success: true, data: {} };
+}
+
+// ============================================================================
+// Output Formatting
+// ============================================================================
+
+function formatOutput(result: Result, format: Args['format']): string {
+ switch (format) {
+ case 'json':
+ return JSON.stringify(result, null, 2);
+ case 'csv':
+ // Implement CSV formatting
+ return '';
+ case 'table':
+ // Implement table formatting
+ return '';
+ }
+}
+
+// ============================================================================
+// Main
+// ============================================================================
+
+async function main(): Promise<void> {
+ const args = parseArgs();
+
+ if (args.help) {
+ showHelp();
+ process.exit(0);
+ }
+
+ try {
+ const result = await execute(/* pass args */);
+ const output = formatOutput(result, args.format);
+
+ if (args.output) {
+ fs.writeFileSync(args.output, output);
+ if (args.verbose) {
+ console.error(`Written to ${args.output}`);
+ }
+ } else {
+ console.log(output);
+ }
+
+ process.exit(result.success ? 0 : 1);
+ } catch (error: any) {
+ console.error(JSON.stringify({ success: false, error: error.message }));
+ process.exit(1);
+ }
+}
+
+main();