|
| 1 | +# Make CLI - AI Agents Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document provides instructions for AI agents on how to work with and extend the Make CLI repository. The CLI is a standalone command-line tool that interacts with the Make automation platform. It depends on `@makehq/sdk` for all API access, types, and MCP tool definitions. |
| 6 | + |
| 7 | +## Repository Structure |
| 8 | + |
| 9 | +``` |
| 10 | +make-cli/ |
| 11 | +├── src/ |
| 12 | +│ ├── cli.ts # Executable entry point: sets up Commander, registers all commands |
| 13 | +│ ├── commands.ts # Builds CLI commands from @makehq/sdk MCP tool definitions |
| 14 | +│ ├── auth.ts # Resolves API key and zone from flags or env vars |
| 15 | +│ ├── output.ts # Output formatting: json, compact, table |
| 16 | +│ ├── categories.ts # Display titles and groupings for command categories |
| 17 | +│ └── version.ts # Auto-generated version constant (from scripts/build-version.mjs) |
| 18 | +├── test/ |
| 19 | +│ └── commands.spec.ts # Unit tests for CLI utilities and command building |
| 20 | +├── scripts/ |
| 21 | +│ └── build-version.mjs # Writes src/version.ts from package.json version |
| 22 | +└── dist/ # Compiled output (auto-generated) |
| 23 | + └── cli.js # The executable CLI (ESM with shebang) |
| 24 | +``` |
| 25 | + |
| 26 | +## Dependency on `@makehq/sdk` |
| 27 | + |
| 28 | +All API functionality comes from the `@makehq/sdk` package. The CLI imports: |
| 29 | + |
| 30 | +| Import | Source | Purpose | |
| 31 | +| -------------- | ----------------- | ------------------------------------------------ | |
| 32 | +| `Make` | `@makehq/sdk` | API client — instantiated per command invocation | |
| 33 | +| `MakeError` | `@makehq/sdk` | Typed API error with `statusCode` and `message` | |
| 34 | +| `JSONValue` | `@makehq/sdk` | Generic JSON value type | |
| 35 | +| `MakeMCPTools` | `@makehq/sdk/mcp` | Array of all MCP tool definitions | |
| 36 | +| `MakeMCPTool` | `@makehq/sdk/mcp` | Type describing a single MCP tool | |
| 37 | +| `JSONSchema` | `@makehq/sdk/mcp` | JSON Schema type for tool input parameters | |
| 38 | + |
| 39 | +## How the CLI Works |
| 40 | + |
| 41 | +The CLI uses an **auto-discovery pattern**: it reads the `MakeMCPTools` array from `@makehq/sdk/mcp` and dynamically registers each tool as a CLI subcommand. No command wiring is done by hand. |
| 42 | + |
| 43 | +### Command registration flow |
| 44 | + |
| 45 | +1. `src/index.ts` creates a Commander program with global flags (`--api-key`, `--zone`, `--output`) |
| 46 | +2. It calls `buildCommands(program, MakeMCPTools)` from `src/commands.ts` |
| 47 | +3. `buildCommands` groups tools by `tool.category` and creates nested subcommands: |
| 48 | + - Category → top-level command (e.g. `scenarios`, `data-stores`, `sdk-apps`) |
| 49 | + - Tool action → subcommand (e.g. `list`, `get`, `create`) |
| 50 | +4. Each subcommand's options are derived from `tool.inputSchema.properties` |
| 51 | +5. On execution, the tool's `execute(make, args)` function is called |
| 52 | + |
| 53 | +### Tool name → CLI command mapping |
| 54 | + |
| 55 | +Tool names follow `{category}_{action}` where category dots become hyphens: |
| 56 | + |
| 57 | +``` |
| 58 | +scenarios_list → make scenarios list |
| 59 | +data-stores_get → make data-stores get |
| 60 | +sdk-apps_get-section → make sdk-apps get-section |
| 61 | +``` |
| 62 | + |
| 63 | +### Auth resolution |
| 64 | + |
| 65 | +Every command resolves credentials via `resolveAuth()` in `src/auth.ts`: |
| 66 | + |
| 67 | +- Checks `--api-key` / `--zone` flags first |
| 68 | +- Falls back to `MAKE_API_KEY` / `MAKE_ZONE` environment variables |
| 69 | +- Throws if either is missing |
| 70 | + |
| 71 | +### Output formatting |
| 72 | + |
| 73 | +Controlled by the global `--output` flag (default: `json`): |
| 74 | + |
| 75 | +- `json` — pretty-printed JSON |
| 76 | +- `compact` — single-line JSON |
| 77 | +- `table` — ASCII table (for arrays of objects) |
| 78 | + |
| 79 | +## Adding New Commands |
| 80 | + |
| 81 | +New CLI commands come automatically from new MCP tools added in `@makehq/sdk`. To add a command: |
| 82 | + |
| 83 | +1. Add or update a `.mcp.ts` file in the `@makehq/sdk` repository following its conventions |
| 84 | +2. Bump and publish a new version of `@makehq/sdk` |
| 85 | +3. Update `@makehq/sdk` version in this repo's `package.json` and run `npm install` |
| 86 | +4. No code changes needed in this repo — the new tool is auto-discovered |
| 87 | + |
| 88 | +To customize how a **category** is displayed (title, help group), update `src/categories.ts`. |
| 89 | + |
| 90 | +## Testing Patterns |
| 91 | + |
| 92 | +### Unit Tests (`test/commands.spec.ts`) |
| 93 | + |
| 94 | +Tests cover the helper functions and command-building logic using mock tool definitions: |
| 95 | + |
| 96 | +```typescript |
| 97 | +import { describe, expect, it } from '@jest/globals'; |
| 98 | +import { Command } from 'commander'; |
| 99 | +import { deriveActionName, camelToKebab, coerceValue, buildCommands } from '../src/commands.js'; |
| 100 | +import { resolveAuth } from '../src/auth.js'; |
| 101 | +import { formatOutput } from '../src/output.js'; |
| 102 | +import type { MakeMCPTool } from '@makehq/sdk/mcp'; |
| 103 | + |
| 104 | +const makeTool = (overrides: Partial<MakeMCPTool> = {}): MakeMCPTool => ({ |
| 105 | + name: 'scenarios_list', |
| 106 | + title: 'List scenarios', |
| 107 | + description: 'List all scenarios', |
| 108 | + category: 'scenarios', |
| 109 | + inputSchema: { type: 'object', properties: {}, required: [] }, |
| 110 | + execute: async () => [], |
| 111 | + ...overrides, |
| 112 | +}); |
| 113 | +``` |
| 114 | + |
| 115 | +Tests do **not** mock HTTP requests — they only test pure CLI logic (argument parsing, type coercion, output formatting, command structure). |
| 116 | + |
| 117 | +## Build and Development |
| 118 | + |
| 119 | +### Scripts |
| 120 | + |
| 121 | +- `npm run build` — compile `src/index.ts` to `dist/index.js` (ESM with shebang) |
| 122 | +- `npm run build:version` — write current package.json version to `src/version.ts` |
| 123 | +- `npm test` — run unit tests in `test/` |
| 124 | +- `npm run lint` — TypeScript type-check + ESLint |
| 125 | +- `npm run format` — format with Prettier |
| 126 | + |
| 127 | +### Output |
| 128 | + |
| 129 | +The build produces a single file: `dist/index.js` — an ESM executable with `#!/usr/bin/env node`. |
| 130 | + |
| 131 | +## TypeScript Guidelines |
| 132 | + |
| 133 | +- Use `type` imports for type-only imports |
| 134 | +- All imports from `@makehq/sdk` and `@makehq/sdk/mcp` use the package name (never relative paths into node_modules) |
| 135 | +- Use `.js` extensions in relative imports (e.g. `import { run } from './index.js'`) |
| 136 | + |
| 137 | +## Quality Checklist |
| 138 | + |
| 139 | +Before completing any change: |
| 140 | + |
| 141 | +- [ ] `npm run lint` passes (TypeScript + ESLint) |
| 142 | +- [ ] `npm test` passes |
| 143 | +- [ ] `npm run build` succeeds and produces `dist/index.js` |
| 144 | +- [ ] `node dist/index.js --help` shows expected commands |
0 commit comments