@mindstudio-ai/agent 0.0.15 → 0.0.16

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,8 +1,8 @@
1
1
  # @mindstudio-ai/agent
2
2
 
3
- TypeScript SDK for executing [MindStudio](https://mindstudio.ai) workflow steps directly.
3
+ TypeScript SDK, CLI, and MCP server for executing [MindStudio](https://mindstudio.ai) workflow steps directly.
4
4
 
5
- Call any of MindStudio's 120+ built-in actions — AI models, image/video generation, web scraping, integrations, and more — with fully typed inputs and outputs.
5
+ Call any of MindStudio's 120+ built-in actions — AI models, image/video generation, web scraping, integrations, and more — with fully typed inputs and outputs. Use from TypeScript, the command line, or any MCP-compatible AI agent.
6
6
 
7
7
  ## Install
8
8
 
@@ -14,6 +14,8 @@ Requires Node.js 18+.
14
14
 
15
15
  ## Quick start
16
16
 
17
+ ### TypeScript
18
+
17
19
  ```typescript
18
20
  import { MindStudioAgent } from '@mindstudio-ai/agent';
19
21
 
@@ -41,6 +43,57 @@ console.log(results);
41
43
 
42
44
  Every method is fully typed — your editor will autocomplete available parameters, show enum options, and infer the output shape. Results are returned flat for easy destructuring.
43
45
 
46
+ ### CLI
47
+
48
+ ```bash
49
+ # Set your API key
50
+ export MINDSTUDIO_API_KEY=your-api-key
51
+
52
+ # Execute a step with named flags
53
+ mindstudio generate-image --prompt "A mountain landscape at sunset"
54
+
55
+ # Or with JSON input (JSON5-tolerant: unquoted keys, single quotes, trailing commas)
56
+ mindstudio generate-image '{prompt: "A mountain landscape at sunset"}'
57
+
58
+ # Just the image URL, no metadata
59
+ mindstudio generate-image --prompt "A sunset" --output-key imageUrl
60
+
61
+ # List all available methods
62
+ mindstudio list
63
+
64
+ # Show details about a method
65
+ mindstudio info generate-image
66
+
67
+ # Pipe input from another command
68
+ echo '{"query": "TypeScript best practices"}' | mindstudio search-google
69
+ ```
70
+
71
+ Run via `npx` without installing globally:
72
+
73
+ ```bash
74
+ npx @mindstudio-ai/agent generate-text --message "Hello"
75
+ ```
76
+
77
+ ### MCP server
78
+
79
+ Add to your MCP client config (Claude Code, Cursor, VS Code, etc.):
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "mindstudio": {
85
+ "command": "npx",
86
+ "args": ["-y", "@mindstudio-ai/agent", "mcp"],
87
+ "env": {
88
+ "MINDSTUDIO_API_KEY": "your-api-key"
89
+ }
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ All 120+ step methods are exposed as MCP tools with full JSON Schema input definitions, so your AI agent can discover and call them directly. The MCP server also exposes `listAgents` and `runAgent` tools for running pre-built agents.
96
+
44
97
  ## Authentication
45
98
 
46
99
  The SDK supports two authentication modes:
@@ -113,6 +166,18 @@ const result = await agent.generateText({ message: 'Hello' });
113
166
  console.log(result.$rateLimitRemaining); // calls remaining in window
114
167
  ```
115
168
 
169
+ ## Billing
170
+
171
+ Every result includes optional billing metadata:
172
+
173
+ ```typescript
174
+ const result = await agent.generateImage({ prompt: 'A sunset' });
175
+ console.log(result.$billingCost); // cost in credits for this call
176
+ console.log(result.$billingEvents); // itemized billing events
177
+ ```
178
+
179
+ These fields are `undefined` when the server does not return billing headers.
180
+
116
181
  ## Available steps
117
182
 
118
183
  Every step has a dedicated typed method. A few highlights:
@@ -137,6 +202,35 @@ Every step has a dedicated typed method. A few highlights:
137
202
 
138
203
  All methods show full documentation in your editor's IntelliSense — hover any method to see usage notes, parameter descriptions, and enum options.
139
204
 
205
+ ## Running pre-built agents
206
+
207
+ List and run the pre-built agents in your MindStudio organization:
208
+
209
+ ```typescript
210
+ // List all agents in your org
211
+ const { apps } = await agent.listAgents();
212
+ for (const app of apps) {
213
+ console.log(app.name, app.id);
214
+ }
215
+
216
+ // Run an agent and wait for the result
217
+ const result = await agent.runAgent({
218
+ appId: 'your-agent-id',
219
+ variables: { query: 'Summarize the latest news' },
220
+ });
221
+ console.log(result.result);
222
+
223
+ // Run a specific workflow with version override
224
+ const result = await agent.runAgent({
225
+ appId: 'your-agent-id',
226
+ variables: { topic: 'AI' },
227
+ workflow: 'research',
228
+ version: 'draft',
229
+ });
230
+ ```
231
+
232
+ `runAgent()` always uses async mode internally — it submits the run, then polls for the result until it completes or fails. The poll interval defaults to 1 second and can be configured with `pollIntervalMs`.
233
+
140
234
  ## Helpers
141
235
 
142
236
  ```typescript
@@ -192,6 +286,10 @@ import type {
192
286
  StepName,
193
287
  StepInputMap,
194
288
  StepOutputMap,
289
+ AgentInfo,
290
+ ListAgentsResult,
291
+ RunAgentOptions,
292
+ RunAgentResult,
195
293
  } from '@mindstudio-ai/agent';
196
294
  ```
197
295
 
@@ -218,6 +316,115 @@ import { blockTypeAliases } from '@mindstudio-ai/agent';
218
316
  // { userMessage: "generateText", generatePdf: "generateAsset" }
219
317
  ```
220
318
 
319
+ ## CLI reference
320
+
321
+ ```
322
+ Usage: mindstudio <command | method> [options]
323
+
324
+ Commands:
325
+ <method> [json | --flags] Execute a step method
326
+ exec <method> [json | --flags] Execute a step method (same as above)
327
+ list [--json] List available methods
328
+ info <method> Show method details (params, types, output)
329
+ agents [--json] List pre-built agents in your organization
330
+ run <appId> [json | --flags] Run a pre-built agent and wait for result
331
+ mcp Start MCP server (JSON-RPC over stdio)
332
+
333
+ Options:
334
+ --api-key <key> API key (or set MINDSTUDIO_API_KEY env)
335
+ --base-url <url> API base URL
336
+ --app-id <id> App ID for thread context
337
+ --thread-id <id> Thread ID for state persistence
338
+ --output-key <key> Extract a single field from the result
339
+ --no-meta Strip $-prefixed metadata from output
340
+ --workflow <name> Workflow to execute (run command)
341
+ --version <ver> App version override, e.g. "draft" (run command)
342
+ --json Output as JSON (list/agents only)
343
+ --help Show help
344
+ ```
345
+
346
+ Method names use kebab-case on the CLI (`generate-image`), though camelCase (`generateImage`) is also accepted. Typos get a "did you mean?" suggestion. Parameter flags are also kebab-case (`--video-url` for `videoUrl`).
347
+
348
+ Input can be provided as:
349
+ - **Named flags**: `--prompt "a sunset" --mode "background"`
350
+ - **JSON argument**: `'{"prompt": "a sunset"}'` (JSON5-tolerant: unquoted keys, single quotes, trailing commas)
351
+ - **Piped stdin**: `echo '{"prompt": "a sunset"}' | mindstudio generate-image`
352
+
353
+ Values are auto-coerced: `--font-size 12` becomes a number, `--enabled true` becomes a boolean.
354
+
355
+ Output can be shaped with `--output-key` (extract a single field as raw text) and `--no-meta` (strip `$`-prefixed metadata):
356
+
357
+ ```bash
358
+ # Just the URL, ready to pipe
359
+ mindstudio generate-image --prompt "a cat" --output-key imageUrl
360
+
361
+ # Clean JSON without metadata
362
+ mindstudio generate-text --message "hello" --no-meta
363
+ ```
364
+
365
+ Running pre-built agents from the CLI:
366
+
367
+ ```bash
368
+ # List agents in your organization
369
+ mindstudio agents
370
+
371
+ # Run an agent with input variables
372
+ mindstudio run <appId> --query "Summarize the latest news"
373
+
374
+ # Run with JSON input
375
+ mindstudio run <appId> '{"query": "hello", "topic": "AI"}'
376
+
377
+ # Run a specific workflow
378
+ mindstudio run <appId> --query "hello" --workflow research
379
+
380
+ # Extract just the result text
381
+ mindstudio run <appId> --query "hello" --output-key result
382
+ ```
383
+
384
+ Thread persistence across CLI calls:
385
+
386
+ ```bash
387
+ # First call — capture the thread/app IDs from the JSON output
388
+ result=$(mindstudio generate-text --message "My name is Alice")
389
+
390
+ # Subsequent calls — pass them back
391
+ mindstudio generate-text --message "What is my name?" \
392
+ --thread-id $(echo $result | jq -r '."$threadId"') \
393
+ --app-id $(echo $result | jq -r '."$appId"')
394
+ ```
395
+
396
+ ## MCP server
397
+
398
+ The package includes a built-in [MCP](https://modelcontextprotocol.io) (Model Context Protocol) server. It exposes all step methods and helpers as tools, so any MCP-compatible AI agent (Claude Code, Cursor, Windsurf, VS Code Copilot, etc.) can discover and call them.
399
+
400
+ Start manually:
401
+
402
+ ```bash
403
+ mindstudio mcp
404
+ ```
405
+
406
+ Or configure your MCP client:
407
+
408
+ ```json
409
+ {
410
+ "mcpServers": {
411
+ "mindstudio": {
412
+ "command": "npx",
413
+ "args": ["-y", "@mindstudio-ai/agent", "mcp"],
414
+ "env": {
415
+ "MINDSTUDIO_API_KEY": "your-api-key"
416
+ }
417
+ }
418
+ }
419
+ }
420
+ ```
421
+
422
+ The MCP server:
423
+ - Uses stdio transport (JSON-RPC 2.0)
424
+ - Creates one agent per session with automatic thread reuse
425
+ - Returns structured JSON results for each tool call
426
+ - Has zero additional dependencies
427
+
221
428
  ## LLM documentation
222
429
 
223
430
  An `llms.txt` file ships with the package for AI agent consumption:
@@ -228,6 +435,16 @@ node_modules/@mindstudio-ai/agent/llms.txt
228
435
 
229
436
  It contains a compact, complete reference of all methods with their required parameters and output keys — optimized for LLM context windows.
230
437
 
438
+ ## OpenAPI spec
439
+
440
+ The raw OpenAPI spec that this SDK is generated from is available at:
441
+
442
+ ```
443
+ https://v1.mindstudio-api.com/developer/v2/steps/openapi.json
444
+ ```
445
+
446
+ This contains full JSON Schema definitions for every step's input and output, descriptions, and usage notes. Useful if you want to build your own tooling, code generators, or integrations.
447
+
231
448
  ## Error handling
232
449
 
233
450
  ```typescript