@nicolasmondain/cli-agent 2.1.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,471 +1,170 @@
1
1
  # cli-agent
2
2
 
3
- > A semantic command catalog for AI agents
3
+ > Turn your scripts into AI-powered tools
4
4
 
5
- A CLI wrapper that enables AI agents to discover and execute commands through a structured catalog. Define your commands once in JSON, and let both humans and AI agents use them seamlessly.
5
+ cli-agent is an MCP server that lets AI assistants like Claude execute your scripts through natural language.
6
6
 
7
- ## Why cli-agent?
7
+ ## How it works
8
8
 
9
- ### The Problem
9
+ 1. You define your scripts in `.cli-agent.json`
10
+ 2. cli-agent exposes them as MCP tools
11
+ 3. Claude understands what they do and runs them when needed
10
12
 
11
- AI agents can execute scripts, but they face challenges:
12
-
13
- - **Discovery**: They must read source code to understand what scripts exist
14
- - **Invocation**: They must guess arguments and options
15
- - **Parsing**: Each script outputs data differently
16
-
17
- ### The Solution
18
-
19
- cli-agent provides a **semantic catalog** of commands. AI agents read the catalog, match commands to user intent, and execute them one by one:
20
-
21
- ```mermaid
22
- flowchart TD
23
- A["User: 'Set up my project with linting and tests'"] --> B[AI Agent]
24
- B --> C["cli-agent list --format json"]
25
- C --> D["Agent reads command catalog"]
26
- D --> E["Agent matches intent to commands"]
27
- E --> F["cli-agent init my-project --format json"]
28
- F --> G{Success?}
29
- G -->|Yes| H["cli-agent add-linting --format json"]
30
- G -->|No| I["Agent stops and reports error"]
31
- H --> J{Success?}
32
- J -->|Yes| K["cli-agent add-testing --format json"]
33
- J -->|No| I
34
- K --> L["Agent reports combined results"]
35
13
  ```
36
-
37
- ## How It Works
38
-
39
- When an AI agent (like Claude) receives: **"Set up my project with linting and tests"**
40
-
41
- 1. **Discovery**: The agent calls `cli-agent list --format json` to get the command catalog
42
- 2. **Matching**: The agent reads command descriptions and matches them to user intent:
43
- - `init` → "Initialize a new project with standard structure"
44
- - `add-linting` → "Add ESLint configuration to the project"
45
- - `add-testing` → "Add Jest/Vitest testing setup"
46
- 3. **Execution**: The agent executes each command one by one:
47
- ```bash
48
- cli-agent init my-project --format json
49
- cli-agent add-linting --format json
50
- cli-agent add-testing --format json
51
- ```
52
- 4. **Error handling**: If any command fails, the agent stops the sequence and reports the error
53
- 5. **Result**: The agent aggregates results and reports back to the user
54
-
55
- **Note:** cli-agent itself has no AI capabilities. It's a tool catalog and executor. The AI agent (Claude, GPT, etc.) handles the natural language understanding and orchestration.
56
-
57
- ## Features
58
-
59
- - **Semantic Catalog** — Command descriptions enable AI agents to match user intent
60
- - **Command Discovery** — `cli-agent list --format json` exposes all commands with arguments and options
61
- - **MCP Integration** — Generate MCP tool manifests for native Claude Code integration
62
- - **Multi-runtime Support** — Execute JavaScript, TypeScript, and shell scripts
63
- - **AI-First Design** — JSON output, non-interactive execution, predictable exit codes
64
-
65
- ## Installation
66
-
67
- ```bash
68
- npm install @nicolasmondain/cli-agent
14
+ User: "Deploy to staging"
15
+
16
+ Claude matches intent → deploy --env staging
17
+
18
+ Your script runs → Result returned to Claude
69
19
  ```
70
20
 
71
- Or globally:
21
+ ## Quick Start
22
+
23
+ ### 1. Install
72
24
 
73
25
  ```bash
74
26
  npm install -g @nicolasmondain/cli-agent
75
27
  ```
76
28
 
77
- ## Quick Start
78
-
79
- ### 1. Create a configuration file
80
-
81
- Create `.cli-agent.json` in your project root:
29
+ ### 2. Create `.cli-agent.json`
82
30
 
83
31
  ```json
84
32
  {
85
- "name": "project-cli",
86
- "description": "Project automation tools",
33
+ "name": "cli-agent",
87
34
  "commands": [
88
35
  {
89
- "name": "init",
90
- "description": "Initialize a new project with standard folder structure and configuration files",
91
- "script": "./scripts/init.js",
92
- "arguments": [
93
- {
94
- "name": "name",
95
- "description": "Project name",
96
- "required": true
97
- }
98
- ]
99
- },
100
- {
101
- "name": "add-linting",
102
- "description": "Add ESLint and Prettier configuration to the project",
103
- "script": "./scripts/add-linting.js",
104
- "options": [
105
- {
106
- "flags": "--typescript",
107
- "description": "Include TypeScript ESLint rules"
108
- }
109
- ]
110
- },
111
- {
112
- "name": "add-testing",
113
- "description": "Add Jest or Vitest testing setup with example tests",
114
- "script": "./scripts/add-testing.js",
36
+ "name": "deploy",
37
+ "description": "Deploy the app to staging or production",
38
+ "script": "./scripts/deploy.sh",
115
39
  "options": [
116
- {
117
- "flags": "-r, --runner <runner>",
118
- "description": "Test runner to use",
119
- "choices": ["jest", "vitest"],
120
- "default": "vitest"
121
- }
40
+ { "flags": "-e, --env <env>", "choices": ["staging", "production"] }
122
41
  ]
123
42
  }
124
43
  ]
125
44
  }
126
45
  ```
127
46
 
128
- ### 2. Create your scripts
47
+ ### 3. Configure Claude Code
129
48
 
130
- Create `scripts/init.js`:
49
+ Add to your Claude Code MCP settings:
131
50
 
132
- ```javascript
133
- export default async function(context) {
134
- const name = context.args.name;
135
-
136
- // Your initialization logic here...
137
-
138
- return {
139
- success: true,
140
- message: `Initialized project: ${name}`,
141
- data: {
142
- name,
143
- path: `./${name}`,
144
- files: ['package.json', 'tsconfig.json', 'src/index.ts']
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "cli-agent": {
55
+ "command": "npx",
56
+ "args": ["cli-agent", "mcp:serve"]
145
57
  }
146
- };
58
+ }
147
59
  }
148
60
  ```
149
61
 
150
- ### 3. Run your commands
62
+ Done. Claude can now run your scripts.
151
63
 
152
- ```bash
153
- # Human-friendly output
154
- cli-agent init my-project
155
-
156
- # JSON output for AI agents
157
- cli-agent init my-project --format json
158
- ```
159
-
160
- ## Command Discovery
64
+ ## Writing Scripts
161
65
 
162
- ### For Humans
66
+ Scripts can be JavaScript, TypeScript, or shell scripts.
163
67
 
164
- ```bash
165
- # Show all commands
166
- cli-agent list
68
+ ### JavaScript (.js)
167
69
 
168
- # Show help for a specific command
169
- cli-agent init --help
70
+ ```javascript
71
+ export default async function(context) {
72
+ const env = context.options.env;
73
+ // your logic here
74
+ return { success: true, message: `Deployed to ${env}` };
75
+ }
170
76
  ```
171
77
 
172
- ### For AI Agents
78
+ ### TypeScript (.ts)
173
79
 
174
- ```bash
175
- # Get machine-readable command catalog
176
- cli-agent list --format json
177
- ```
80
+ ```typescript
81
+ import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
178
82
 
179
- Output:
180
- ```json
181
- {
182
- "success": true,
183
- "data": {
184
- "name": "project-cli",
185
- "commands": [
186
- {
187
- "name": "init",
188
- "description": "Initialize a new project with standard folder structure and configuration files",
189
- "arguments": [{ "name": "name", "description": "Project name", "required": true }],
190
- "options": []
191
- },
192
- {
193
- "name": "add-linting",
194
- "description": "Add ESLint and Prettier configuration to the project",
195
- "arguments": [],
196
- "options": [{ "flags": "--typescript", "description": "Include TypeScript ESLint rules" }]
197
- }
198
- ]
199
- }
83
+ export default async function(context: ScriptContext): Promise<CommandResult> {
84
+ const env = context.options.env as string;
85
+ return { success: true, message: `Deployed to ${env}` };
200
86
  }
201
87
  ```
202
88
 
203
- ### For MCP Clients
204
-
205
- Generate an MCP tool manifest for Claude Code and other MCP-compatible clients:
89
+ ### Shell (.sh)
206
90
 
207
91
  ```bash
208
- # Output to stdout
209
- cli-agent mcp:manifest
210
-
211
- # Write to file
212
- cli-agent mcp:manifest --output .mcp-tools.json
213
- ```
214
-
215
- Output:
216
- ```json
217
- {
218
- "tools": [
219
- {
220
- "name": "init",
221
- "description": "Initialize a new project with standard folder structure and configuration files",
222
- "inputSchema": {
223
- "type": "object",
224
- "properties": {
225
- "name": { "type": "string", "description": "Project name" }
226
- },
227
- "required": ["name"]
228
- }
229
- }
230
- ]
231
- }
92
+ #!/bin/bash
93
+ ENV="${CLI_AGENT_OPT_ENV}"
94
+ echo "Deploying to $ENV..."
95
+ echo '{"success": true}'
232
96
  ```
233
97
 
234
- ## Configuration Reference
235
-
236
- ### Configuration File Locations
237
-
238
- cli-agent looks for configuration in this order:
239
-
240
- 1. `--config <path>` flag (explicit path)
241
- 2. `.cli-agent.json` in current directory
242
- 3. `cli-agent` field in `package.json`
243
- 4. `~/.cli-agent.json` (global commands)
244
-
245
- ### Full Schema
98
+ ## Configuration
246
99
 
247
100
  ```json
248
101
  {
249
- "name": "my-cli",
250
- "version": "1.0.0",
251
- "description": "CLI description shown in help",
102
+ "name": "cli-agent",
252
103
  "commands": [
253
104
  {
254
105
  "name": "command-name",
255
- "description": "Clear description for AI agent understanding",
106
+ "description": "What this command does (helps Claude understand when to use it)",
256
107
  "script": "./path/to/script.js",
257
108
  "arguments": [
258
- {
259
- "name": "arg-name",
260
- "description": "What this argument represents",
261
- "required": true,
262
- "variadic": false
263
- }
109
+ { "name": "arg", "description": "Positional argument", "required": true }
264
110
  ],
265
111
  "options": [
266
- {
267
- "flags": "-s, --short <value>",
268
- "description": "What this option does",
269
- "default": "default-value",
270
- "required": false,
271
- "choices": ["option1", "option2"]
272
- }
112
+ { "flags": "-o, --option <value>", "description": "Named option", "default": "value" }
273
113
  ]
274
114
  }
275
115
  ]
276
116
  }
277
117
  ```
278
118
 
279
- ### Writing Effective Descriptions
280
-
281
- Good descriptions help AI agents match user intent to the right command:
119
+ ### Configuration locations
282
120
 
283
- ```json
284
- {
285
- "name": "init",
286
- "description": "Initialize a new project with standard folder structure and configuration files"
287
- }
288
- ```
121
+ cli-agent looks for configuration in this order:
289
122
 
290
- ```json
291
- {
292
- "name": "db-migrate",
293
- "description": "Run database migrations to update schema to latest version"
294
- }
295
- ```
123
+ 1. `--config <path>` flag
124
+ 2. `.cli-agent.json` in current directory
125
+ 3. `cli-agent` field in `package.json`
126
+ 4. `~/.cli-agent.json` (global)
296
127
 
297
- ```json
298
- {
299
- "name": "deploy",
300
- "description": "Deploy the application to the specified environment (staging or production)"
301
- }
302
- ```
128
+ ## CLI Usage
303
129
 
304
- ## Writing Scripts
130
+ ```bash
131
+ # Start MCP server (used by Claude Code)
132
+ cli-agent mcp:serve
305
133
 
306
- ### JavaScript Scripts (.js)
134
+ # List available commands
135
+ cli-agent list
307
136
 
308
- Scripts must export a default async function:
137
+ # Run a command directly
138
+ cli-agent deploy --env staging
309
139
 
310
- ```javascript
311
- /**
312
- * @param {import('@nicolasmondain/cli-agent').ScriptContext} context
313
- * @returns {Promise<import('@nicolasmondain/cli-agent').CommandResult>}
314
- */
315
- export default async function(context) {
316
- // context.args - positional arguments { name: 'value' }
317
- // context.options - command options { typescript: true, runner: 'vitest' }
318
- // context.cwd - current working directory
319
- // context.format - 'human' or 'json'
320
-
321
- return {
322
- success: true,
323
- message: 'Human-readable message',
324
- data: { /* structured data */ }
325
- };
326
- }
140
+ # JSON output for scripting
141
+ cli-agent deploy --env staging --format json
327
142
  ```
328
143
 
329
- ### TypeScript Scripts (.ts)
144
+ ## Script Context
330
145
 
331
- TypeScript scripts are executed via `tsx` or `ts-node`:
146
+ Scripts receive a context object with:
332
147
 
333
148
  ```typescript
334
- import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
335
-
336
- export default async function(context: ScriptContext): Promise<CommandResult> {
337
- const name = context.args.name as string;
338
-
339
- return {
340
- success: true,
341
- message: `Initialized ${name}`,
342
- data: { name }
343
- };
149
+ interface ScriptContext {
150
+ args: Record<string, unknown>; // Positional arguments
151
+ options: Record<string, unknown>; // Named options
152
+ cwd: string; // Current working directory
153
+ format: 'human' | 'json'; // Output format
344
154
  }
345
155
  ```
346
156
 
347
- > **Note:** Install `tsx` for TypeScript support: `npm install -g tsx`
348
-
349
- ### Shell Scripts (.sh)
350
-
351
- Shell scripts receive context via environment variables:
352
-
353
- ```bash
354
- #!/bin/bash
355
-
356
- # Arguments: CLI_AGENT_ARG_<NAME>
357
- # Options: CLI_AGENT_OPT_<NAME>
358
- # Format: CLI_AGENT_FORMAT
359
- # CWD: CLI_AGENT_CWD
360
-
361
- NAME="${CLI_AGENT_ARG_NAME}"
362
- TYPESCRIPT="${CLI_AGENT_OPT_TYPESCRIPT:-false}"
363
-
364
- # Output JSON for structured response
365
- if [ "$CLI_AGENT_FORMAT" = "json" ]; then
366
- echo "{\"success\": true, \"data\": {\"name\": \"$NAME\"}}"
367
- else
368
- echo "Initialized project: $NAME"
369
- fi
370
- ```
371
-
372
- ## Standard Options
373
-
374
- All commands automatically have these options:
375
-
376
- | Option | Description |
377
- |--------|-------------|
378
- | `--format <format>` | Output format: `human` or `json` (default: `human`) |
379
- | `--quiet` | Suppress all output except errors |
380
- | `--verbose` | Show detailed output |
381
- | `--debug` | Show debug information |
382
-
383
- ## Built-in Commands
384
-
385
- | Command | Description |
386
- |---------|-------------|
387
- | `list` | List all available commands |
388
- | `mcp:manifest` | Generate MCP tool manifest |
389
-
390
- ## Multi-Command Orchestration
391
-
392
- cli-agent is designed to be called multiple times by an AI agent. The **agent** orchestrates the execution flow based on user intent:
393
-
394
- ```mermaid
395
- sequenceDiagram
396
- participant User
397
- participant Agent as AI Agent
398
- participant CLI as cli-agent
399
-
400
- User->>Agent: "Set up my project with linting and tests"
401
- Agent->>CLI: cli-agent list --format json
402
- CLI-->>Agent: Command catalog (JSON)
403
- Agent->>Agent: Match intent to commands
404
- Agent->>CLI: cli-agent init my-project --format json
405
- CLI-->>Agent: {"success": true, ...}
406
- Agent->>CLI: cli-agent add-linting --format json
407
- CLI-->>Agent: {"success": true, ...}
408
- Agent->>CLI: cli-agent add-testing --format json
409
- CLI-->>Agent: {"success": true, ...}
410
- Agent->>User: "Project setup complete with linting and tests"
411
- ```
412
-
413
- **Key points:**
414
- - The AI agent decides which commands to run and in what order
415
- - cli-agent executes one command per invocation
416
- - If a command fails, the agent can stop the sequence
417
- - cli-agent provides discovery, execution, and structured output
418
-
419
- ## Using Utilities in Scripts
420
-
421
- cli-agent exports utility functions for use in your scripts:
422
-
423
- ```javascript
424
- import {
425
- // Naming utilities
426
- toKebabCase,
427
- toPascalCase,
428
- toCamelCase,
429
- toScreamingSnakeCase,
430
-
431
- // File system utilities
432
- pathExists,
433
- createDirectory,
434
- createFile,
435
-
436
- // Logging
437
- logInfo,
438
- logError,
439
- logSuccess,
440
- logWarning,
441
- } from '@nicolasmondain/cli-agent';
157
+ Scripts must return:
442
158
 
443
- export default async function(context) {
444
- const name = toKebabCase(context.args.name);
445
-
446
- if (await pathExists(`./${name}`)) {
447
- return { success: false, error: 'Directory already exists' };
448
- }
449
-
450
- await createDirectory(`./${name}`);
451
- logSuccess(`Created ${name}/`);
452
-
453
- return { success: true, message: `Created ${name}/` };
159
+ ```typescript
160
+ interface CommandResult {
161
+ success: boolean;
162
+ message?: string; // Human-readable message
163
+ data?: unknown; // Structured data
164
+ error?: string; // Error message if success is false
454
165
  }
455
166
  ```
456
167
 
457
- ## Project Structure
458
-
459
- ```
460
- your-project/
461
- ├── .cli-agent.json # CLI configuration
462
- ├── scripts/
463
- │ ├── init.js # JavaScript script
464
- │ ├── add-linting.ts # TypeScript script
465
- │ └── deploy.sh # Shell script
466
- └── package.json
467
- ```
468
-
469
168
  ## License
470
169
 
471
170
  MIT
@@ -0,0 +1,13 @@
1
+ /**
2
+ * MCP Serve Command
3
+ *
4
+ * Built-in command that starts an MCP server exposing all configured
5
+ * cli-agent commands as MCP tools for Claude Code and other MCP clients.
6
+ */
7
+ import { Command } from "commander";
8
+ import type { CliConfig } from "../../config/config-schema.js";
9
+ /**
10
+ * Create the mcp:serve command
11
+ */
12
+ export declare function createMcpServeCommand(config: CliConfig | null, configDir: string | null): Command;
13
+ //# sourceMappingURL=mcp-serve.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-serve.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/mcp-serve.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAsCT"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * MCP Serve Command
3
+ *
4
+ * Built-in command that starts an MCP server exposing all configured
5
+ * cli-agent commands as MCP tools for Claude Code and other MCP clients.
6
+ */
7
+ import { Command } from "commander";
8
+ import { startMcpServer } from "../../mcp/mcp-server.js";
9
+ /**
10
+ * Create the mcp:serve command
11
+ */
12
+ export function createMcpServeCommand(config, configDir) {
13
+ const command = new Command("mcp:serve");
14
+ command
15
+ .description("Start MCP server exposing all commands as tools")
16
+ .action(async () => {
17
+ if (!config) {
18
+ console.error("Error: No configuration found. Create a .cli-agent.json file to define commands.");
19
+ process.exit(1);
20
+ return;
21
+ }
22
+ if (config.commands.length === 0) {
23
+ console.error("Error: No commands defined in configuration.");
24
+ process.exit(1);
25
+ return;
26
+ }
27
+ if (!configDir) {
28
+ console.error("Error: Configuration directory not available.");
29
+ process.exit(1);
30
+ return;
31
+ }
32
+ try {
33
+ await startMcpServer({ config, configDir });
34
+ }
35
+ catch (error) {
36
+ console.error("Error starting MCP server:", error instanceof Error ? error.message : String(error));
37
+ process.exit(1);
38
+ }
39
+ });
40
+ return command;
41
+ }
42
+ //# sourceMappingURL=mcp-serve.command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-serve.command.js","sourceRoot":"","sources":["../../../src/cli/commands/mcp-serve.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAwB,EACxB,SAAwB;IAExB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEzC,OAAO;SACJ,WAAW,CAAC,iDAAiD,CAAC;SAC9D,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CACX,kFAAkF,CACnF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,cAAc,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,4BAA4B,EAC5B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -2,8 +2,7 @@
2
2
  /**
3
3
  * CLI Entry Point
4
4
  *
5
- * Generic CLI wrapper that loads commands from external configuration.
6
- * Designed for both human developers and AI agents (MCP compatible).
5
+ * MCP server that turns your scripts into AI-powered tools.
7
6
  */
8
7
  export {};
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;GAIG"}
package/dist/cli/index.js CHANGED
@@ -2,19 +2,18 @@
2
2
  /**
3
3
  * CLI Entry Point
4
4
  *
5
- * Generic CLI wrapper that loads commands from external configuration.
6
- * Designed for both human developers and AI agents (MCP compatible).
5
+ * MCP server that turns your scripts into AI-powered tools.
7
6
  */
8
7
  import { Command } from "commander";
9
8
  import { loadConfig, getExplicitConfigPath } from "../config/config-loader.js";
10
9
  import { createDynamicCommand } from "../command/dynamic-command.factory.js";
11
10
  import { createListCommand } from "./commands/list.command.js";
12
- import { createMcpManifestCommand } from "./commands/mcp-manifest.command.js";
11
+ import { createMcpServeCommand } from "./commands/mcp-serve.command.js";
13
12
  import { logError, logDebug } from "../infra/logger.js";
14
13
  // Package info
15
14
  const VERSION = "2.0.0";
16
15
  const DEFAULT_NAME = "cli-agent";
17
- const DEFAULT_DESCRIPTION = "Generic CLI wrapper for executing external scripts";
16
+ const DEFAULT_DESCRIPTION = "MCP server that turns your scripts into AI-powered tools";
18
17
  /**
19
18
  * Create and configure the main CLI program
20
19
  */
@@ -80,7 +79,7 @@ export default async function(context) {
80
79
  }
81
80
  // Add built-in commands (always available)
82
81
  program.addCommand(createListCommand(config));
83
- program.addCommand(createMcpManifestCommand(config));
82
+ program.addCommand(createMcpServeCommand(config, configResult?.configDir ?? null));
84
83
  // Add global options
85
84
  program
86
85
  .option("-c, --config <path>", "Path to configuration file")
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAExD,e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,CAAC,CAAC;QAErC,0CAA0C;QAC1C,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvE,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CACH,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc;AACd,IAAI,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Library Entry Point
3
3
  *
4
+ * MCP server that turns your scripts into AI-powered tools.
4
5
  * Exports the public API for consumers to use in their scripts.
5
6
  */
6
7
  export type { OutputFormat, LogLevel, CommandResult, ScriptContext, ExitCodeValue, } from "./types/index.js";
@@ -11,4 +12,6 @@ export { pathExists, isDirectory, createDirectory, createFile, resolvePath, join
11
12
  export { setLogLevel, getLogLevel, logError, logWarn, logInfo, logSuccess, logDebug, logTrace, logBox, resetLogger, } from "./infra/logger.js";
12
13
  export { outputResult } from "./infra/output.js";
13
14
  export { getScriptContext } from "./executor/ts-executor.js";
15
+ export { createMcpServer, startMcpServer } from "./mcp/mcp-server.js";
16
+ export type { McpServerOptions } from "./mcp/mcp-server.js";
14
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,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AW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Library Entry Point
3
3
  *
4
+ * MCP server that turns your scripts into AI-powered tools.
4
5
  * Exports the public API for consumers to use in their scripts.
5
6
  */
6
7
  export { ExitCode } from "./types/index.js";
@@ -12,4 +13,6 @@ export { setLogLevel, getLogLevel, logError, logWarn, logInfo, logSuccess, logDe
12
13
  export { outputResult } from "./infra/output.js";
13
14
  // Script context helper (for TypeScript scripts executed via tsx/ts-node)
14
15
  export { getScriptContext } from "./executor/ts-executor.js";
16
+ // MCP Server (for programmatic usage)
17
+ export { createMcpServer, startMcpServer } from "./mcp/mcp-server.js";
15
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAW5C,8DAA8D;AAC9D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,QAAQ,EACR,aAAa,EACb,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAE3C,4DAA4D;AAC5D,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAW5C,8DAA8D;AAC9D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,QAAQ,EACR,aAAa,EACb,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAE3C,4DAA4D;AAC5D,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,0EAA0E;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,sCAAsC;AACtC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * MCP Server Implementation
3
+ *
4
+ * Creates an MCP server that exposes cli-agent commands as tools.
5
+ * Enables native integration with Claude Code and other MCP-compatible clients.
6
+ */
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ import type { CliConfig } from "../config/config-schema.js";
9
+ export interface McpServerOptions {
10
+ config: CliConfig;
11
+ configDir: string;
12
+ }
13
+ /**
14
+ * Create and configure an MCP server from cli-agent configuration
15
+ */
16
+ export declare function createMcpServer(options: McpServerOptions): McpServer;
17
+ /**
18
+ * Start the MCP server with stdio transport
19
+ */
20
+ export declare function startMcpServer(options: McpServerOptions): Promise<void>;
21
+ //# sourceMappingURL=mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,4BAA4B,CAAC;AAO3E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AA8KD;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA2BpE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAU7E"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * MCP Server Implementation
3
+ *
4
+ * Creates an MCP server that exposes cli-agent commands as tools.
5
+ * Enables native integration with Claude Code and other MCP-compatible clients.
6
+ */
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
+ import { z } from "zod";
10
+ import { executeScript, } from "../executor/script-executor.js";
11
+ /**
12
+ * Parse option flags to extract the option name
13
+ * Examples:
14
+ * "-n, --name <value>" -> "name"
15
+ * "--verbose" -> "verbose"
16
+ * "-f, --force" -> "force"
17
+ */
18
+ function parseOptionName(flags) {
19
+ const match = flags.match(/--([a-zA-Z][\w-]*)/);
20
+ if (match && match[1]) {
21
+ return match[1];
22
+ }
23
+ return flags.replace(/[^a-zA-Z0-9-]/g, "");
24
+ }
25
+ /**
26
+ * Determine if option takes a value based on flags
27
+ * Examples:
28
+ * "-n, --name <value>" -> true (required value)
29
+ * "--count [num]" -> true (optional value)
30
+ * "--verbose" -> false (boolean flag)
31
+ */
32
+ function optionTakesValue(flags) {
33
+ return flags.includes("<") || flags.includes("[");
34
+ }
35
+ /**
36
+ * Build Zod schema from command configuration
37
+ */
38
+ function buildZodSchema(command) {
39
+ const shape = {};
40
+ // Add arguments to schema
41
+ if (command.arguments) {
42
+ for (const arg of command.arguments) {
43
+ if (arg.variadic) {
44
+ shape[arg.name] = z
45
+ .array(z.string())
46
+ .describe(arg.description ?? "")
47
+ .optional();
48
+ }
49
+ else if (arg.required === false) {
50
+ shape[arg.name] = z
51
+ .string()
52
+ .describe(arg.description ?? "")
53
+ .optional();
54
+ }
55
+ else {
56
+ shape[arg.name] = z.string().describe(arg.description ?? "");
57
+ }
58
+ }
59
+ }
60
+ // Add options to schema
61
+ if (command.options) {
62
+ for (const opt of command.options) {
63
+ const optName = parseOptionName(opt.flags);
64
+ const takesValue = optionTakesValue(opt.flags);
65
+ let field;
66
+ if (!takesValue) {
67
+ // Boolean flag
68
+ field = z
69
+ .boolean()
70
+ .describe(opt.description ?? "")
71
+ .optional();
72
+ }
73
+ else if (opt.choices && opt.choices.length > 0) {
74
+ // Enum type
75
+ field = z
76
+ .enum(opt.choices)
77
+ .describe(opt.description ?? "");
78
+ if (!opt.required) {
79
+ field = field.optional();
80
+ }
81
+ }
82
+ else if (typeof opt.default === "number") {
83
+ field = z
84
+ .number()
85
+ .describe(opt.description ?? "")
86
+ .optional();
87
+ }
88
+ else {
89
+ field = z
90
+ .string()
91
+ .describe(opt.description ?? "")
92
+ .optional();
93
+ }
94
+ if (opt.default !== undefined && "default" in field) {
95
+ field = field.default(opt.default);
96
+ }
97
+ shape[optName] = field;
98
+ }
99
+ }
100
+ return z.object(shape);
101
+ }
102
+ /**
103
+ * Separate MCP params into args and options based on command config
104
+ */
105
+ function separateArgsAndOptions(command, params) {
106
+ const args = {};
107
+ const options = {};
108
+ const argumentNames = new Set((command.arguments ?? []).map((a) => a.name));
109
+ for (const [key, value] of Object.entries(params)) {
110
+ if (argumentNames.has(key)) {
111
+ args[key] = value;
112
+ }
113
+ else {
114
+ options[key] = value;
115
+ }
116
+ }
117
+ return { args, options };
118
+ }
119
+ /**
120
+ * Execute a tool call by routing to the script executor
121
+ */
122
+ async function executeToolCall(command, params, configDir) {
123
+ const { args, options } = separateArgsAndOptions(command, params);
124
+ const context = {
125
+ args,
126
+ options,
127
+ cwd: process.cwd(),
128
+ format: "json",
129
+ };
130
+ try {
131
+ const result = await executeScript(command.script, context, configDir);
132
+ return {
133
+ content: [
134
+ {
135
+ type: "text",
136
+ text: JSON.stringify(result, null, 2),
137
+ },
138
+ ],
139
+ };
140
+ }
141
+ catch (error) {
142
+ return {
143
+ content: [
144
+ {
145
+ type: "text",
146
+ text: JSON.stringify({
147
+ success: false,
148
+ error: error instanceof Error ? error.message : String(error),
149
+ }, null, 2),
150
+ },
151
+ ],
152
+ };
153
+ }
154
+ }
155
+ /**
156
+ * Create and configure an MCP server from cli-agent configuration
157
+ */
158
+ export function createMcpServer(options) {
159
+ const { config, configDir } = options;
160
+ const server = new McpServer({
161
+ name: config.name ?? "cli-agent",
162
+ version: config.version ?? "1.0.0",
163
+ });
164
+ // Register each command as an MCP tool
165
+ for (const command of config.commands) {
166
+ const inputSchema = buildZodSchema(command);
167
+ server.tool(command.name, command.description ?? `Execute ${command.name} command`, inputSchema.shape, async (params) => {
168
+ return executeToolCall(command, params, configDir);
169
+ });
170
+ }
171
+ return server;
172
+ }
173
+ /**
174
+ * Start the MCP server with stdio transport
175
+ */
176
+ export async function startMcpServer(options) {
177
+ const server = createMcpServer(options);
178
+ const transport = new StdioServerTransport();
179
+ await server.connect(transport);
180
+ // Log to stderr (not stdout - would corrupt MCP messages)
181
+ console.error(`MCP Server "${options.config.name ?? "cli-agent"}" running on st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E,MAAM,CAAC,IAAI,IAAI,WAAW;QAChC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO;KACnC,CAAC,CAAC;IAEH,uCAAuC;IACvC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;QAE5C,MAAM,CAAC,IAAI,CACT,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,WAAW,IAAI,WAAW,OAAO,CAAC,IAAI,UAAU,EACxD,WAAW,CAAC,KAAK,EACjB,KAAK,EAAE,MAAM,EAAE,EAAE;YACf,OAAO,eAAe,CACpB,OAAO,EACP,MAAiC,EACjC,SAAS,CACV,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAyB;IAC5D,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,0DAA0D;IAC1D,OAAO,CAAC,KAAK,CACX,eAAe,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,WAAW,oBAAoB,CACtE,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nicolasmondain/cli-agent",
3
- "version": "2.1.2",
4
- "description": "Generic CLI wrapper for executing external scripts, designed for both human developers and AI agents (MCP compatible)",
3
+ "version": "3.0.0",
4
+ "description": "MCP server that turns your scripts into AI-powered tools for Claude and other AI assistants",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -56,8 +56,10 @@
56
56
  "node": ">=20.0.0"
57
57
  },
58
58
  "dependencies": {
59
+ "@modelcontextprotocol/sdk": "^1.0.0",
59
60
  "commander": "^12.1.0",
60
- "consola": "^3.2.3"
61
+ "consola": "^3.2.3",
62
+ "zod": "^3.25.0"
61
63
  },
62
64
  "devDependencies": {
63
65
  "@release-it/conventional-changelog": "^10.0.4",
@@ -1,14 +0,0 @@
1
- /**
2
- * MCP Manifest Command
3
- *
4
- * Built-in command that generates an MCP (Model Context Protocol) tool manifest
5
- * from the cli-agent configuration. This enables native integration with
6
- * Claude Code and other MCP-compatible clients.
7
- */
8
- import { Command } from 'commander';
9
- import type { CliConfig } from '../../config/config-schema.js';
10
- /**
11
- * Create the mcp:manifest command
12
- */
13
- export declare function createMcpManifestCommand(config: CliConfig | null): Command;
14
- //# sourceMappingURL=mcp-manifest.command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-manifest.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/mcp-manifest.command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAK/D;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAyF1E"}
@@ -1,87 +0,0 @@
1
- /**
2
- * MCP Manifest Command
3
- *
4
- * Built-in command that generates an MCP (Model Context Protocol) tool manifest
5
- * from the cli-agent configuration. This enables native integration with
6
- * Claude Code and other MCP-compatible clients.
7
- */
8
- import { Command } from 'commander';
9
- import { writeFile } from 'node:fs/promises';
10
- import { generateMcpManifestJson, generateMcpManifest } from '../../mcp/manifest-generator.js';
11
- import { outputResult } from '../../infra/output.js';
12
- /**
13
- * Create the mcp:manifest command
14
- */
15
- export function createMcpManifestCommand(config) {
16
- const command = new Command('mcp:manifest');
17
- command
18
- .description('Generate MCP (Model Context Protocol) tool manifest from configuration')
19
- .option('-o, --output <path>', 'Write manifest to file instead of stdout')
20
- .option('--format <format>', 'Output format: human or json', 'human')
21
- .action(async (options) => {
22
- const format = options.format === 'json' ? 'json' : 'human';
23
- if (!config) {
24
- outputResult({
25
- success: false,
26
- error: 'No configuration found. Create a .cli-agent.json file to define commands.',
27
- }, format);
28
- process.exit(1);
29
- return;
30
- }
31
- if (config.commands.length === 0) {
32
- outputResult({
33
- success: false,
34
- error: 'No commands defined in configuration.',
35
- }, format);
36
- process.exit(1);
37
- return;
38
- }
39
- try {
40
- const manifestJson = generateMcpManifestJson(config);
41
- if (options.output) {
42
- // Write to file
43
- await writeFile(options.output, manifestJson + '\n', 'utf-8');
44
- if (format === 'json') {
45
- const manifest = generateMcpManifest(config);
46
- outputResult({
47
- success: true,
48
- message: `MCP manifest written to ${options.output}`,
49
- data: {
50
- path: options.output,
51
- toolCount: manifest.tools.length,
52
- },
53
- }, format);
54
- }
55
- else {
56
- console.log(`MCP manifest written to ${options.output}`);
57
- console.log(`Contains ${config.commands.length} tool(s).`);
58
- }
59
- }
60
- else {
61
- // Output to stdout
62
- if (format === 'json') {
63
- // Wrap manifest in CommandResult for consistent JSON output
64
- const manifest = generateMcpManifest(config);
65
- outputResult({
66
- success: true,
67
- message: `Generated MCP manifest with ${manifest.tools.length} tool(s)`,
68
- data: manifest,
69
- }, format);
70
- }
71
- else {
72
- // Human format: just output the manifest JSON directly
73
- console.log(manifestJson);
74
- }
75
- }
76
- }
77
- catch (error) {
78
- outputResult({
79
- success: false,
80
- error: `Failed to generate manifest: ${error instanceof Error ? error.message : String(error)}`,
81
- }, format);
82
- process.exit(1);
83
- }
84
- });
85
- return command;
86
- }
87
- //# sourceMappingURL=mcp-manifest.command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-manifest.command.js","sourceRoot":"","sources":["../../../src/cli/commands/mcp-manifest.command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAA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C,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,51 +0,0 @@
1
- /**
2
- * MCP Manifest Generator
3
- *
4
- * Converts cli-agent configuration to MCP (Model Context Protocol) tool manifest.
5
- * This enables native integration with Claude Code and other MCP-compatible clients.
6
- */
7
- import type { CliConfig, CommandConfig } from "../config/config-schema.js";
8
- /**
9
- * MCP Tool Input Schema (JSON Schema format)
10
- */
11
- export interface McpInputSchema {
12
- type: "object";
13
- properties: Record<string, McpPropertySchema>;
14
- required?: string[];
15
- }
16
- /**
17
- * MCP Property Schema
18
- */
19
- export interface McpPropertySchema {
20
- type: string;
21
- description?: string;
22
- default?: unknown;
23
- enum?: string[];
24
- }
25
- /**
26
- * MCP Tool Definition
27
- */
28
- export interface McpTool {
29
- name: string;
30
- description: string;
31
- inputSchema: McpInputSchema;
32
- }
33
- /**
34
- * MCP Tools Manifest
35
- */
36
- export interface McpManifest {
37
- tools: McpTool[];
38
- }
39
- /**
40
- * Convert a command config to MCP tool definition
41
- */
42
- export declare function commandToMcpTool(cmd: CommandConfig): McpTool;
43
- /**
44
- * Generate MCP manifest from cli-agent configuration
45
- */
46
- export declare function generateMcpManifest(config: CliConfig): McpManifest;
47
- /**
48
- * Generate MCP manifest as formatted JSON string
49
- */
50
- export declare function generateMcpManifestJson(config: CliConfig, pretty?: boolean): string;
51
- //# sourceMappingURL=manifest-generator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest-generator.d.ts","sourceRoot":"","sources":["../../src/mcp/manifest-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAGd,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC9C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,cAAc,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB;AAmFD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CA0C5D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW,CAIlE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,SAAS,EACjB,MAAM,UAAO,GACZ,MAAM,CAGR"}
@@ -1,130 +0,0 @@
1
- /**
2
- * MCP Manifest Generator
3
- *
4
- * Converts cli-agent configuration to MCP (Model Context Protocol) tool manifest.
5
- * This enables native integration with Claude Code and other MCP-compatible clients.
6
- */
7
- /**
8
- * Parse option flags to extract the option name
9
- * Examples:
10
- * "-n, --name <value>" -> "name"
11
- * "--verbose" -> "verbose"
12
- * "-f, --force" -> "force"
13
- */
14
- function parseOptionName(flags) {
15
- // Match --option-name or -o, --option-name patterns
16
- const match = flags.match(/--([a-zA-Z][\w-]*)/);
17
- if (match && match[1]) {
18
- return match[1];
19
- }
20
- return flags.replace(/[^a-zA-Z0-9-]/g, "");
21
- }
22
- /**
23
- * Determine if option takes a value based on flags
24
- * Examples:
25
- * "-n, --name <value>" -> true (required value)
26
- * "--count [num]" -> true (optional value)
27
- * "--verbose" -> false (boolean flag)
28
- */
29
- function optionTakesValue(flags) {
30
- return flags.includes("<") || flags.includes("[");
31
- }
32
- /**
33
- * Convert an argument config to MCP property schema
34
- */
35
- function argumentToProperty(arg) {
36
- const property = {
37
- type: "string",
38
- };
39
- if (arg.description) {
40
- property.description = arg.description;
41
- }
42
- if (arg.variadic) {
43
- // Variadic arguments accept multiple values
44
- return {
45
- type: "array",
46
- description: arg.description,
47
- };
48
- }
49
- return property;
50
- }
51
- /**
52
- * Convert an option config to MCP property schema
53
- */
54
- function optionToProperty(opt) {
55
- const takesValue = optionTakesValue(opt.flags);
56
- const property = {
57
- type: takesValue ? "string" : "boolean",
58
- };
59
- if (opt.description) {
60
- property.description = opt.description;
61
- }
62
- if (opt.default !== undefined) {
63
- property.default = opt.default;
64
- // Infer type from default value
65
- if (typeof opt.default === "number") {
66
- property.type = "number";
67
- }
68
- else if (typeof opt.default === "boolean") {
69
- property.type = "boolean";
70
- }
71
- }
72
- if (opt.choices && opt.choices.length > 0) {
73
- property.enum = opt.choices;
74
- }
75
- return property;
76
- }
77
- /**
78
- * Convert a command config to MCP tool definition
79
- */
80
- export function commandToMcpTool(cmd) {
81
- const properties = {};
82
- const required = [];
83
- // Convert arguments
84
- if (cmd.arguments) {
85
- for (const arg of cmd.arguments) {
86
- properties[arg.name] = argumentToProperty(arg);
87
- // Arguments are required by default unless explicitly set to false
88
- if (arg.required !== false) {
89
- required.push(arg.name);
90
- }
91
- }
92
- }
93
- // Convert options
94
- if (cmd.options) {
95
- for (const opt of cmd.options) {
96
- const optName = parseOptionName(opt.flags);
97
- properties[optName] = optionToProperty(opt);
98
- if (opt.required) {
99
- required.push(optName);
100
- }
101
- }
102
- }
103
- const tool = {
104
- name: cmd.name,
105
- description: cmd.description ?? `Execute ${cmd.name} command`,
106
- inputSchema: {
107
- type: "object",
108
- properties,
109
- },
110
- };
111
- if (required.length > 0) {
112
- tool.inputSchema.required = required;
113
- }
114
- return tool;
115
- }
116
- /**
117
- * Generate MCP manifest from cli-agent configuration
118
- */
119
- export function generateMcpManifest(config) {
120
- const tools = config.commands.map(commandToMcpTool);
121
- return { tools };
122
- }
123
- /**
124
- * Generate MCP manifest as formatted JSON string
125
- */
126
- export function generateMcpManifestJson(config, pretty = true) {
127
- const manifest = generateMcpManifest(config);
128
- return pretty ? JSON.stringify(manifest, null, 2) : JSON.stringify(manifest);
129
- }
130
- //# sourceMappingURL=manifest-generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest-generator.js","sourceRoot":"","sources":["../../src/mcp/manifest-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4CH;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,oDAAoD;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAChD,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,GAAmB;IAC7C,MAAM,QAAQ,GAAsB;QAClC,IAAI,EAAE,QAAQ;KACf,CAAC;IAEF,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;QACpB,QAAQ,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjB,4CAA4C;QAC5C,OAAO;YACL,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,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