@mindstudio-ai/agent 0.0.15 → 0.0.17

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,11 +43,68 @@ 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
+ # Authenticate (opens browser, saves key locally)
50
+ mindstudio login
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
- The SDK supports two authentication modes:
99
+ The fastest way to authenticate is the interactive login:
47
100
 
48
- **API Key** — for external apps, scripts, and CLI usage:
101
+ ```bash
102
+ mindstudio login
103
+ ```
104
+
105
+ This opens your browser, authenticates with MindStudio, and saves your API key to `~/.mindstudio/config.json`. All subsequent CLI and SDK usage will pick it up automatically.
106
+
107
+ You can also authenticate via environment variable or constructor parameter:
49
108
 
50
109
  ```typescript
51
110
  // Pass directly
@@ -56,15 +115,19 @@ const agent = new MindStudioAgent({ apiKey: 'your-api-key' });
56
115
  const agent = new MindStudioAgent();
57
116
  ```
58
117
 
59
- **Managed mode**automatically available inside MindStudio custom functions:
118
+ MindStudio routes to the correct AI provider (OpenAI, Google, Anthropic, etc.) server-side you do not need separate provider API keys.
60
119
 
61
- ```typescript
62
- // Inside a MindStudio custom function, auth and base URL are automatic
63
- // (CALLBACK_TOKEN and REMOTE_HOSTNAME are set by the runtime)
64
- const agent = new MindStudioAgent();
120
+ Other auth commands:
121
+
122
+ ```bash
123
+ # Check current auth status and verify credentials
124
+ mindstudio whoami
125
+
126
+ # Clear stored credentials
127
+ mindstudio logout
65
128
  ```
66
129
 
67
- Resolution order: constructor `apiKey` > `MINDSTUDIO_API_KEY` env > `CALLBACK_TOKEN` env.
130
+ Resolution order: constructor `apiKey` > `MINDSTUDIO_API_KEY` env > `~/.mindstudio/config.json` > `CALLBACK_TOKEN` env.
68
131
 
69
132
  ## Thread persistence
70
133
 
@@ -113,6 +176,18 @@ const result = await agent.generateText({ message: 'Hello' });
113
176
  console.log(result.$rateLimitRemaining); // calls remaining in window
114
177
  ```
115
178
 
179
+ ## Billing
180
+
181
+ Every result includes optional billing metadata:
182
+
183
+ ```typescript
184
+ const result = await agent.generateImage({ prompt: 'A sunset' });
185
+ console.log(result.$billingCost); // cost in credits for this call
186
+ console.log(result.$billingEvents); // itemized billing events
187
+ ```
188
+
189
+ These fields are `undefined` when the server does not return billing headers.
190
+
116
191
  ## Available steps
117
192
 
118
193
  Every step has a dedicated typed method. A few highlights:
@@ -137,6 +212,35 @@ Every step has a dedicated typed method. A few highlights:
137
212
 
138
213
  All methods show full documentation in your editor's IntelliSense — hover any method to see usage notes, parameter descriptions, and enum options.
139
214
 
215
+ ## Running pre-built agents
216
+
217
+ List and run the pre-built agents in your MindStudio organization:
218
+
219
+ ```typescript
220
+ // List all agents in your org
221
+ const { apps } = await agent.listAgents();
222
+ for (const app of apps) {
223
+ console.log(app.name, app.id);
224
+ }
225
+
226
+ // Run an agent and wait for the result
227
+ const result = await agent.runAgent({
228
+ appId: 'your-agent-id',
229
+ variables: { query: 'Summarize the latest news' },
230
+ });
231
+ console.log(result.result);
232
+
233
+ // Run a specific workflow with version override
234
+ const result = await agent.runAgent({
235
+ appId: 'your-agent-id',
236
+ variables: { topic: 'AI' },
237
+ workflow: 'research',
238
+ version: 'draft',
239
+ });
240
+ ```
241
+
242
+ `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`.
243
+
140
244
  ## Helpers
141
245
 
142
246
  ```typescript
@@ -154,7 +258,7 @@ const { services } = await agent.listConnectors();
154
258
 
155
259
  ```typescript
156
260
  const agent = new MindStudioAgent({
157
- // API key (or set MINDSTUDIO_API_KEY env var)
261
+ // API key (or set MINDSTUDIO_API_KEY env var, or run `mindstudio login`)
158
262
  apiKey: 'your-api-key',
159
263
 
160
264
  // Base URL (or set MINDSTUDIO_BASE_URL env var)
@@ -192,6 +296,10 @@ import type {
192
296
  StepName,
193
297
  StepInputMap,
194
298
  StepOutputMap,
299
+ AgentInfo,
300
+ ListAgentsResult,
301
+ RunAgentOptions,
302
+ RunAgentResult,
195
303
  } from '@mindstudio-ai/agent';
196
304
  ```
197
305
 
@@ -218,6 +326,118 @@ import { blockTypeAliases } from '@mindstudio-ai/agent';
218
326
  // { userMessage: "generateText", generatePdf: "generateAsset" }
219
327
  ```
220
328
 
329
+ ## CLI reference
330
+
331
+ ```
332
+ Usage: mindstudio <command | method> [options]
333
+
334
+ Commands:
335
+ login Authenticate with MindStudio (opens browser)
336
+ logout Clear stored credentials
337
+ whoami Show current authentication status
338
+ <method> [json | --flags] Execute a step method
339
+ exec <method> [json | --flags] Execute a step method (same as above)
340
+ list [--json] List available methods
341
+ info <method> Show method details (params, types, output)
342
+ agents [--json] List pre-built agents in your organization
343
+ run <appId> [json | --flags] Run a pre-built agent and wait for result
344
+ mcp Start MCP server (JSON-RPC over stdio)
345
+
346
+ Options:
347
+ --api-key <key> API key (or set MINDSTUDIO_API_KEY env)
348
+ --base-url <url> API base URL
349
+ --app-id <id> App ID for thread context
350
+ --thread-id <id> Thread ID for state persistence
351
+ --output-key <key> Extract a single field from the result
352
+ --no-meta Strip $-prefixed metadata from output
353
+ --workflow <name> Workflow to execute (run command)
354
+ --version <ver> App version override, e.g. "draft" (run command)
355
+ --json Output as JSON (list/agents only)
356
+ --help Show help
357
+ ```
358
+
359
+ 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`).
360
+
361
+ Input can be provided as:
362
+ - **Named flags**: `--prompt "a sunset" --mode "background"`
363
+ - **JSON argument**: `'{"prompt": "a sunset"}'` (JSON5-tolerant: unquoted keys, single quotes, trailing commas)
364
+ - **Piped stdin**: `echo '{"prompt": "a sunset"}' | mindstudio generate-image`
365
+
366
+ Values are auto-coerced: `--font-size 12` becomes a number, `--enabled true` becomes a boolean.
367
+
368
+ Output can be shaped with `--output-key` (extract a single field as raw text) and `--no-meta` (strip `$`-prefixed metadata):
369
+
370
+ ```bash
371
+ # Just the URL, ready to pipe
372
+ mindstudio generate-image --prompt "a cat" --output-key imageUrl
373
+
374
+ # Clean JSON without metadata
375
+ mindstudio generate-text --message "hello" --no-meta
376
+ ```
377
+
378
+ Running pre-built agents from the CLI:
379
+
380
+ ```bash
381
+ # List agents in your organization
382
+ mindstudio agents
383
+
384
+ # Run an agent with input variables
385
+ mindstudio run <appId> --query "Summarize the latest news"
386
+
387
+ # Run with JSON input
388
+ mindstudio run <appId> '{"query": "hello", "topic": "AI"}'
389
+
390
+ # Run a specific workflow
391
+ mindstudio run <appId> --query "hello" --workflow research
392
+
393
+ # Extract just the result text
394
+ mindstudio run <appId> --query "hello" --output-key result
395
+ ```
396
+
397
+ Thread persistence across CLI calls:
398
+
399
+ ```bash
400
+ # First call — capture the thread/app IDs from the JSON output
401
+ result=$(mindstudio generate-text --message "My name is Alice")
402
+
403
+ # Subsequent calls — pass them back
404
+ mindstudio generate-text --message "What is my name?" \
405
+ --thread-id $(echo $result | jq -r '."$threadId"') \
406
+ --app-id $(echo $result | jq -r '."$appId"')
407
+ ```
408
+
409
+ ## MCP server
410
+
411
+ 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.
412
+
413
+ Start manually:
414
+
415
+ ```bash
416
+ mindstudio mcp
417
+ ```
418
+
419
+ Or configure your MCP client:
420
+
421
+ ```json
422
+ {
423
+ "mcpServers": {
424
+ "mindstudio": {
425
+ "command": "npx",
426
+ "args": ["-y", "@mindstudio-ai/agent", "mcp"],
427
+ "env": {
428
+ "MINDSTUDIO_API_KEY": "your-api-key"
429
+ }
430
+ }
431
+ }
432
+ }
433
+ ```
434
+
435
+ The MCP server:
436
+ - Uses stdio transport (JSON-RPC 2.0)
437
+ - Creates one agent per session with automatic thread reuse
438
+ - Returns structured JSON results for each tool call
439
+ - Has zero additional dependencies
440
+
221
441
  ## LLM documentation
222
442
 
223
443
  An `llms.txt` file ships with the package for AI agent consumption:
@@ -228,6 +448,16 @@ node_modules/@mindstudio-ai/agent/llms.txt
228
448
 
229
449
  It contains a compact, complete reference of all methods with their required parameters and output keys — optimized for LLM context windows.
230
450
 
451
+ ## OpenAPI spec
452
+
453
+ The raw OpenAPI spec that this SDK is generated from is available at:
454
+
455
+ ```
456
+ https://v1.mindstudio-api.com/developer/v2/steps/openapi.json
457
+ ```
458
+
459
+ 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.
460
+
231
461
  ## Error handling
232
462
 
233
463
  ```typescript