@kairos-sdk/core 0.2.0 → 0.3.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,8 +1,14 @@
1
1
  # @kairos-sdk/core
2
2
 
3
+ [![CI](https://github.com/Kruttz/kairos-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/Kruttz/kairos-sdk/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@kairos-sdk/core)](https://www.npmjs.com/package/@kairos-sdk/core)
5
+ [![npm downloads](https://img.shields.io/npm/dw/@kairos-sdk/core)](https://www.npmjs.com/package/@kairos-sdk/core)
6
+
3
7
  **Turn plain English into deployed n8n workflows — validated, corrected, and deployed in one call.**
4
8
 
5
- Kairos is a TypeScript SDK that takes a natural-language description of an automation, calls Claude to generate n8n workflow JSON, runs it through a **23-rule structural validator** with an automatic correction loop (up to 3 attempts), and deploys the result to your n8n instance via REST API. A local workflow library with **hybrid retrieval** (TF-IDF + node fingerprinting + outcome history + cluster reranking) and telemetry-based feedback inject past failure patterns into future generations. With a seeded template library, Kairos achieves **100% first-try validation pass rate** across 20 benchmark prompts.
9
+ ![Kairos SDK Demo](demo.gif)
10
+
11
+ Kairos turns plain-English workflow descriptions into validated, deployable n8n workflow JSON. Use it as an **MCP server** (connect to Claude Code, Claude Desktop, or any MCP host — your LLM generates, Kairos validates and deploys, no extra API keys needed) or as a **TypeScript SDK** for programmatic control (calls Claude internally with a specialized prompt). Either way, workflows pass through a **23-rule structural validator** with automatic correction, and a local workflow library with **hybrid retrieval** (TF-IDF + node fingerprinting + outcome history + cluster reranking) injects past failure patterns into future generations. With a seeded template library, Kairos achieves **100% first-try structural validation pass rate** across 20 benchmark prompts (meaning the generated JSON is structurally valid on the first attempt — runtime behavior depends on your credentials and node configuration).
6
12
 
7
13
  ```ts
8
14
  import { Kairos } from '@kairos-sdk/core'
@@ -23,7 +29,95 @@ console.log(result.credentialsNeeded) // what the user still needs to configure
23
29
 
24
30
  ---
25
31
 
26
- ## Installation
32
+ ## Use as MCP Server (no code required)
33
+
34
+ Connect Kairos to any MCP-compatible host — Claude Code, Claude Desktop, ChatGPT, Cursor, or any agent that supports the Model Context Protocol. **No API keys needed for generation** — your host LLM generates the workflow using Kairos's specialized context, then Kairos validates and deploys it. No double-LLM calls, no wasted tokens.
35
+
36
+ ### Setup
37
+
38
+ ```bash
39
+ npm install -g @kairos-sdk/core
40
+ ```
41
+
42
+ ### Claude Code
43
+
44
+ Add to your Claude Code MCP config (`~/.claude/claude_code_config.json`):
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "kairos": {
50
+ "command": "kairos-mcp",
51
+ "env": {
52
+ "N8N_BASE_URL": "https://your-instance.app.n8n.cloud",
53
+ "N8N_API_KEY": "your-n8n-key"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ `N8N_BASE_URL` and `N8N_API_KEY` are only needed for deploy/list/activate operations. For generation and validation, no environment variables are required at all.
61
+
62
+ ### Claude Desktop
63
+
64
+ Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "kairos": {
70
+ "command": "kairos-mcp",
71
+ "env": {
72
+ "N8N_BASE_URL": "https://your-instance.app.n8n.cloud",
73
+ "N8N_API_KEY": "your-n8n-key"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ Then just ask your agent: *"Build me a workflow that monitors a webhook and sends a Slack notification"* — it will call `kairos_prompt` for context, generate the workflow itself, validate it with `kairos_validate`, and deploy with `kairos_deploy`.
81
+
82
+ ### How the MCP flow works
83
+
84
+ The MCP server does **not** call an LLM internally. Instead, it gives your host LLM the specialized knowledge and guardrails to generate n8n workflows itself:
85
+
86
+ 1. **Host LLM calls `kairos_prompt`** — gets the n8n system prompt, node catalog, library matches, and failure patterns
87
+ 2. **Host LLM generates the workflow JSON** using that context (no separate API call)
88
+ 3. **Host LLM calls `kairos_validate`** — checks the JSON against 23 structural rules
89
+ 4. If invalid, the host LLM fixes the issues and validates again
90
+ 5. **Host LLM calls `kairos_deploy`** — sends the validated workflow to n8n
91
+
92
+ This means Kairos works with **any LLM** — Claude, GPT, Gemini, Llama, or anything else connected as an MCP host. Zero Anthropic API key needed.
93
+
94
+ ### Available MCP Tools
95
+
96
+ #### Generation tools (no API keys needed)
97
+
98
+ | Tool | Description |
99
+ |------|-------------|
100
+ | `kairos_prompt` | Returns the specialized system prompt, node catalog, library matches, and failure patterns for a given description |
101
+ | `kairos_validate` | Validates workflow JSON against 23 structural rules — returns errors and warnings |
102
+ | `kairos_search` | Searches the local workflow library for similar past builds |
103
+
104
+ #### Deployment tools (need `N8N_BASE_URL` + `N8N_API_KEY`)
105
+
106
+ | Tool | Description |
107
+ |------|-------------|
108
+ | `kairos_deploy` | Deploys validated workflow JSON to n8n (re-validates before deploying) |
109
+ | `kairos_list` | List all deployed workflows |
110
+ | `kairos_get` | Get full workflow JSON by ID |
111
+ | `kairos_activate` | Activate a workflow |
112
+ | `kairos_deactivate` | Deactivate a workflow |
113
+ | `kairos_delete` | Delete a workflow |
114
+ | `kairos_executions` | List recent executions with status |
115
+
116
+ ---
117
+
118
+ ## Use as SDK
119
+
120
+ ### Installation
27
121
 
28
122
  ```bash
29
123
  npm install @kairos-sdk/core @anthropic-ai/sdk
@@ -36,8 +130,9 @@ npm install @kairos-sdk/core @anthropic-ai/sdk
36
130
  ## Requirements
37
131
 
38
132
  - Node.js 18+
39
- - An [Anthropic API key](https://console.anthropic.com)
40
- - An n8n instance with API access enabled (Cloud or self-hosted)
133
+ - **SDK only:** An [Anthropic API key](https://console.anthropic.com) — the SDK calls Claude internally
134
+ - **MCP:** No Anthropic key needed your host LLM does the generation
135
+ - An n8n instance with API access enabled (Cloud or self-hosted) — only needed for deployment, not for generation/validation
41
136
 
42
137
  ---
43
138
 
@@ -94,15 +189,26 @@ The baseline run used Claude with the 22-rule validator and correction loop but
94
189
 
95
190
  ## How It Works
96
191
 
192
+ ### SDK flow (calls Claude internally)
193
+
97
194
  1. **Search** — Kairos searches its local workflow library for similar past builds. Matching workflows and their failure patterns are pulled into context.
98
195
  2. **Warn** — Known failure patterns (from library matches and global telemetry rates) are injected into the system prompt so Claude avoids repeating known mistakes.
99
196
  3. **Generate** — Your description is sent to Claude with a detailed system prompt, forcing a `generate_workflow` tool call that produces structured n8n workflow JSON.
100
- 4. **Validate** — The workflow is checked against **22 structural rules** covering node IDs, types, versions, names, positions, connections, forbidden fields, trigger presence, AI connection direction, cycle detection, webhook pairing, and required parameters.
197
+ 4. **Validate** — The workflow is checked against **23 structural rules** covering node IDs, types, versions, names, positions, connections, forbidden fields, trigger presence, AI connection direction, cycle detection, webhook pairing, and required parameters.
101
198
  5. **Correct** — If validation fails, the specific rule violations are sent back to Claude for correction (up to 3 attempts, with tighter temperature on the final try).
102
199
  6. **Strip** — Forbidden server-assigned fields (`id`, `createdAt`, `updatedAt`, etc.) are stripped before deployment.
103
200
  7. **Deploy** — The validated workflow is posted to your n8n instance via REST API.
104
201
  8. **Record** — The workflow, its metadata (generation mode, attempt count, failure patterns, credentials needed), and telemetry events are saved locally. Future builds use this history to avoid past mistakes.
105
202
 
203
+ ### MCP flow (your LLM generates)
204
+
205
+ 1. **Prompt** — Your LLM calls `kairos_prompt`, which searches the library and returns the specialized system prompt, node catalog, library matches, and failure patterns.
206
+ 2. **Generate** — Your LLM generates the workflow JSON itself using that context. No separate API call.
207
+ 3. **Validate** — Your LLM calls `kairos_validate`, which checks the JSON against the same 23 structural rules.
208
+ 4. **Correct** — If validation fails, your LLM fixes the issues and calls `kairos_validate` again.
209
+ 5. **Deploy** — Your LLM calls `kairos_deploy`, which strips forbidden fields and posts the workflow to n8n.
210
+ 6. **Record** — The deployed workflow is saved to the local library for future retrieval.
211
+
106
212
  ---
107
213
 
108
214
  ## Validator Rules