@nicolasmondain/cli-agent 2.1.1 → 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,468 +1,170 @@
1
1
  # cli-agent
2
2
 
3
- > Bridge the gap between natural language and CLI commands
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 semantic 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 that enables AI agents to understand and orchestrate multiple commands from a single natural language request:
20
-
21
- ```mermaid
22
- flowchart TD
23
- A["User: 'Set up my project with linting and tests'"] --> B[".cli-agent.json\nSemantic Catalog"]
24
- B --> C["cli-agent list --format json"]
25
- C --> D["Agent identifies matching commands"]
26
- D --> E["cli-agent init my-project --format json"]
27
- D --> F["cli-agent add-linting --format json"]
28
- D --> G["cli-agent add-testing --format json"]
29
- E --> H["Structured JSON output"]
30
- F --> H
31
- G --> H
32
- H --> I["Agent reports combined results"]
33
13
  ```
34
-
35
- ## How It Works
36
-
37
- When you say: **"Set up my project with linting and tests"**
38
-
39
- The AI agent:
40
-
41
- 1. Reads `.cli-agent.json` (or runs `cli-agent list --format json`)
42
- 2. Matches command descriptions to your 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. Executes each command sequentially:
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. Parses each JSON response and reports combined results
53
-
54
- ## Features
55
-
56
- - **Natural Language Mapping** — Command descriptions enable AI agents to match user intent to the right command
57
- - **Command Discovery** — `cli-agent list --format json` exposes all commands with their arguments and options
58
- - **MCP Integration** — Generate MCP tool manifests for native Claude Code integration
59
- - **Multi-runtime Support** — Execute JavaScript, TypeScript, and shell scripts
60
- - **AI-First Design** — JSON output, non-interactive execution, predictable exit codes
61
-
62
- ## Installation
63
-
64
- ```bash
65
- 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
66
19
  ```
67
20
 
68
- Or globally:
21
+ ## Quick Start
22
+
23
+ ### 1. Install
69
24
 
70
25
  ```bash
71
26
  npm install -g @nicolasmondain/cli-agent
72
27
  ```
73
28
 
74
- ## Quick Start
75
-
76
- ### 1. Create a configuration file
77
-
78
- Create `.cli-agent.json` in your project root:
29
+ ### 2. Create `.cli-agent.json`
79
30
 
80
31
  ```json
81
32
  {
82
- "name": "project-cli",
83
- "description": "Project automation tools",
33
+ "name": "cli-agent",
84
34
  "commands": [
85
35
  {
86
- "name": "init",
87
- "description": "Initialize a new project with standard folder structure and configuration files",
88
- "script": "./scripts/init.js",
89
- "arguments": [
90
- {
91
- "name": "name",
92
- "description": "Project name",
93
- "required": true
94
- }
95
- ]
96
- },
97
- {
98
- "name": "add-linting",
99
- "description": "Add ESLint and Prettier configuration to the project",
100
- "script": "./scripts/add-linting.js",
101
- "options": [
102
- {
103
- "flags": "--typescript",
104
- "description": "Include TypeScript ESLint rules"
105
- }
106
- ]
107
- },
108
- {
109
- "name": "add-testing",
110
- "description": "Add Jest or Vitest testing setup with example tests",
111
- "script": "./scripts/add-testing.js",
36
+ "name": "deploy",
37
+ "description": "Deploy the app to staging or production",
38
+ "script": "./scripts/deploy.sh",
112
39
  "options": [
113
- {
114
- "flags": "-r, --runner <runner>",
115
- "description": "Test runner to use",
116
- "choices": ["jest", "vitest"],
117
- "default": "vitest"
118
- }
40
+ { "flags": "-e, --env <env>", "choices": ["staging", "production"] }
119
41
  ]
120
42
  }
121
43
  ]
122
44
  }
123
45
  ```
124
46
 
125
- ### 2. Create your scripts
47
+ ### 3. Configure Claude Code
126
48
 
127
- Create `scripts/init.js`:
49
+ Add to your Claude Code MCP settings:
128
50
 
129
- ```javascript
130
- export default async function(context) {
131
- const name = context.args.name;
132
-
133
- // Your initialization logic here...
134
-
135
- return {
136
- success: true,
137
- message: `Initialized project: ${name}`,
138
- data: {
139
- name,
140
- path: `./${name}`,
141
- 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"]
142
57
  }
143
- };
58
+ }
144
59
  }
145
60
  ```
146
61
 
147
- ### 3. Run your commands
62
+ Done. Claude can now run your scripts.
148
63
 
149
- ```bash
150
- # Human-friendly output
151
- cli-agent init my-project
152
-
153
- # JSON output for AI agents
154
- cli-agent init my-project --format json
155
- ```
156
-
157
- ## Command Discovery
64
+ ## Writing Scripts
158
65
 
159
- ### For Humans
66
+ Scripts can be JavaScript, TypeScript, or shell scripts.
160
67
 
161
- ```bash
162
- # Show all commands
163
- cli-agent list
68
+ ### JavaScript (.js)
164
69
 
165
- # Show help for a specific command
166
- 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
+ }
167
76
  ```
168
77
 
169
- ### For AI Agents
78
+ ### TypeScript (.ts)
170
79
 
171
- ```bash
172
- # Get machine-readable command catalog
173
- cli-agent list --format json
174
- ```
80
+ ```typescript
81
+ import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
175
82
 
176
- Output:
177
- ```json
178
- {
179
- "success": true,
180
- "data": {
181
- "name": "project-cli",
182
- "commands": [
183
- {
184
- "name": "init",
185
- "description": "Initialize a new project with standard folder structure and configuration files",
186
- "arguments": [{ "name": "name", "description": "Project name", "required": true }],
187
- "options": []
188
- },
189
- {
190
- "name": "add-linting",
191
- "description": "Add ESLint and Prettier configuration to the project",
192
- "arguments": [],
193
- "options": [{ "flags": "--typescript", "description": "Include TypeScript ESLint rules" }]
194
- }
195
- ]
196
- }
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}` };
197
86
  }
198
87
  ```
199
88
 
200
- ### For MCP Clients
201
-
202
- Generate an MCP tool manifest for Claude Code and other MCP-compatible clients:
89
+ ### Shell (.sh)
203
90
 
204
91
  ```bash
205
- # Output to stdout
206
- cli-agent mcp:manifest
207
-
208
- # Write to file
209
- cli-agent mcp:manifest --output .mcp-tools.json
210
- ```
211
-
212
- Output:
213
- ```json
214
- {
215
- "tools": [
216
- {
217
- "name": "init",
218
- "description": "Initialize a new project with standard folder structure and configuration files",
219
- "inputSchema": {
220
- "type": "object",
221
- "properties": {
222
- "name": { "type": "string", "description": "Project name" }
223
- },
224
- "required": ["name"]
225
- }
226
- }
227
- ]
228
- }
92
+ #!/bin/bash
93
+ ENV="${CLI_AGENT_OPT_ENV}"
94
+ echo "Deploying to $ENV..."
95
+ echo '{"success": true}'
229
96
  ```
230
97
 
231
- ## Configuration Reference
232
-
233
- ### Configuration File Locations
234
-
235
- cli-agent looks for configuration in this order:
236
-
237
- 1. `--config <path>` flag (explicit path)
238
- 2. `.cli-agent.json` in current directory
239
- 3. `cli-agent` field in `package.json`
240
- 4. `~/.cli-agent.json` (global commands)
241
-
242
- ### Full Schema
98
+ ## Configuration
243
99
 
244
100
  ```json
245
101
  {
246
- "name": "my-cli",
247
- "version": "1.0.0",
248
- "description": "CLI description shown in help",
102
+ "name": "cli-agent",
249
103
  "commands": [
250
104
  {
251
105
  "name": "command-name",
252
- "description": "Clear description for AI agent understanding",
106
+ "description": "What this command does (helps Claude understand when to use it)",
253
107
  "script": "./path/to/script.js",
254
108
  "arguments": [
255
- {
256
- "name": "arg-name",
257
- "description": "What this argument represents",
258
- "required": true,
259
- "variadic": false
260
- }
109
+ { "name": "arg", "description": "Positional argument", "required": true }
261
110
  ],
262
111
  "options": [
263
- {
264
- "flags": "-s, --short <value>",
265
- "description": "What this option does",
266
- "default": "default-value",
267
- "required": false,
268
- "choices": ["option1", "option2"]
269
- }
112
+ { "flags": "-o, --option <value>", "description": "Named option", "default": "value" }
270
113
  ]
271
114
  }
272
115
  ]
273
116
  }
274
117
  ```
275
118
 
276
- ### Writing Effective Descriptions
119
+ ### Configuration locations
277
120
 
278
- Good descriptions are crucial for AI agents to match user intent:
279
-
280
- ```json
281
- {
282
- "name": "init",
283
- "description": "Initialize a new project with standard folder structure and configuration files"
284
- }
285
- ```
121
+ cli-agent looks for configuration in this order:
286
122
 
287
- ```json
288
- {
289
- "name": "db-migrate",
290
- "description": "Run database migrations to update schema to latest version"
291
- }
292
- ```
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)
293
127
 
294
- ```json
295
- {
296
- "name": "deploy",
297
- "description": "Deploy the application to the specified environment (staging or production)"
298
- }
299
- ```
128
+ ## CLI Usage
300
129
 
301
- ## Writing Scripts
130
+ ```bash
131
+ # Start MCP server (used by Claude Code)
132
+ cli-agent mcp:serve
302
133
 
303
- ### JavaScript Scripts (.js)
134
+ # List available commands
135
+ cli-agent list
304
136
 
305
- Scripts must export a default async function:
137
+ # Run a command directly
138
+ cli-agent deploy --env staging
306
139
 
307
- ```javascript
308
- /**
309
- * @param {import('@nicolasmondain/cli-agent').ScriptContext} context
310
- * @returns {Promise<import('@nicolasmondain/cli-agent').CommandResult>}
311
- */
312
- export default async function(context) {
313
- // context.args - positional arguments { name: 'value' }
314
- // context.options - command options { typescript: true, runner: 'vitest' }
315
- // context.cwd - current working directory
316
- // context.format - 'human' or 'json'
317
-
318
- return {
319
- success: true,
320
- message: 'Human-readable message',
321
- data: { /* structured data */ }
322
- };
323
- }
140
+ # JSON output for scripting
141
+ cli-agent deploy --env staging --format json
324
142
  ```
325
143
 
326
- ### TypeScript Scripts (.ts)
144
+ ## Script Context
327
145
 
328
- TypeScript scripts are executed via `tsx` or `ts-node`:
146
+ Scripts receive a context object with:
329
147
 
330
148
  ```typescript
331
- import type { ScriptContext, CommandResult } from '@nicolasmondain/cli-agent';
332
-
333
- export default async function(context: ScriptContext): Promise<CommandResult> {
334
- const name = context.args.name as string;
335
-
336
- return {
337
- success: true,
338
- message: `Initialized ${name}`,
339
- data: { name }
340
- };
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
341
154
  }
342
155
  ```
343
156
 
344
- > **Note:** Install `tsx` for TypeScript support: `npm install -g tsx`
345
-
346
- ### Shell Scripts (.sh)
347
-
348
- Shell scripts receive context via environment variables:
349
-
350
- ```bash
351
- #!/bin/bash
352
-
353
- # Arguments: CLI_AGENT_ARG_<NAME>
354
- # Options: CLI_AGENT_OPT_<NAME>
355
- # Format: CLI_AGENT_FORMAT
356
- # CWD: CLI_AGENT_CWD
357
-
358
- NAME="${CLI_AGENT_ARG_NAME}"
359
- TYPESCRIPT="${CLI_AGENT_OPT_TYPESCRIPT:-false}"
360
-
361
- # Output JSON for structured response
362
- if [ "$CLI_AGENT_FORMAT" = "json" ]; then
363
- echo "{\"success\": true, \"data\": {\"name\": \"$NAME\"}}"
364
- else
365
- echo "Initialized project: $NAME"
366
- fi
367
- ```
368
-
369
- ## Standard Options
370
-
371
- All commands automatically have these options:
372
-
373
- | Option | Description |
374
- |--------|-------------|
375
- | `--format <format>` | Output format: `human` or `json` (default: `human`) |
376
- | `--quiet` | Suppress all output except errors |
377
- | `--verbose` | Show detailed output |
378
- | `--debug` | Show debug information |
379
-
380
- ## Built-in Commands
381
-
382
- | Command | Description |
383
- |---------|-------------|
384
- | `list` | List all available commands |
385
- | `mcp:manifest` | Generate MCP tool manifest |
386
-
387
- ## Multi-Command Orchestration
388
-
389
- cli-agent is designed to be called multiple times by an AI agent. The agent orchestrates the execution flow based on user intent:
390
-
391
- ```mermaid
392
- sequenceDiagram
393
- participant User
394
- participant Agent
395
- participant CLI as cli-agent
396
-
397
- User->>Agent: "Set up my project with linting and tests"
398
- Agent->>CLI: cli-agent list --format json
399
- CLI-->>Agent: Command catalog (JSON)
400
- Agent->>Agent: Match intent to commands
401
- Agent->>CLI: cli-agent init my-project --format json
402
- CLI-->>Agent: {"success": true, "data": {...}}
403
- Agent->>CLI: cli-agent add-linting --format json
404
- CLI-->>Agent: {"success": true, "data": {...}}
405
- Agent->>CLI: cli-agent add-testing --format json
406
- CLI-->>Agent: {"success": true, "data": {...}}
407
- Agent->>User: "Project setup complete with linting and tests"
408
- ```
409
-
410
- The agent decides which commands to run and in what order. cli-agent provides:
411
-
412
- - **Discovery**: Machine-readable command catalog
413
- - **Execution**: Consistent invocation interface
414
- - **Output**: Structured JSON for reliable parsing
415
-
416
- ## Using Utilities in Scripts
417
-
418
- cli-agent exports utility functions for use in your scripts:
419
-
420
- ```javascript
421
- import {
422
- // Naming utilities
423
- toKebabCase,
424
- toPascalCase,
425
- toCamelCase,
426
- toScreamingSnakeCase,
427
-
428
- // File system utilities
429
- pathExists,
430
- createDirectory,
431
- createFile,
432
-
433
- // Logging
434
- logInfo,
435
- logError,
436
- logSuccess,
437
- logWarning,
438
- } from '@nicolasmondain/cli-agent';
157
+ Scripts must return:
439
158
 
440
- export default async function(context) {
441
- const name = toKebabCase(context.args.name);
442
-
443
- if (await pathExists(`./${name}`)) {
444
- return { success: false, error: 'Directory already exists' };
445
- }
446
-
447
- await createDirectory(`./${name}`);
448
- logSuccess(`Created ${name}/`);
449
-
450
- 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
451
165
  }
452
166
  ```
453
167
 
454
- ## Project Structure
455
-
456
- ```
457
- your-project/
458
- ├── .cli-agent.json # CLI configuration
459
- ├── scripts/
460
- │ ├── init.js # JavaScript script
461
- │ ├── add-linting.ts # TypeScript script
462
- │ └── deploy.sh # Shell script
463
- └── package.json
464
- ```
465
-
466
168
  ## License
467
169
 
468
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,eAAe;AACf,MAAM,OAAO,GAAG,OAAO,CAAC;AACxB,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,mBAAmB,GACvB,oDAAoD,CAAC;AAEvD;;GAEG;AACH,KAAK,UAAU,aAAa;IAC1B,MAAM,OAAO,GAAG,IAA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ACT,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,EAAE,MAAM,kBAAkB,CAAC;AAG5C,YAAY,EACV,SAAS,EACT,aAAa,EACb,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,oBAAoB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O,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 stdio`);
182
+ }
183
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/mcp/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE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AM,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.1",
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,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,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
- * 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,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,GAAiB;IACzC,MAAM,UAAU,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAE/C,MAAM,QAAQ,GAAsB;QAClC,IAAI,EAAE,UAAU,CAAC,CAAC,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