@kairos-sdk/core 0.2.1 → 0.3.1

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 Anthropic API key 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,96 @@ 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. Your host LLM generates the workflow using Kairos's specialized context, then Kairos validates and deploys it. No Anthropic API key needed — no double-LLM calls, no wasted tokens. Kairos auto-syncs your n8n instance's node types so the catalog always matches your exact setup.
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 required for all MCP operations. Kairos syncs your instance's node types to generate accurate workflows that match your exact n8n setup.
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
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
+ | `kairos_sync` | Manually refresh the node catalog from your n8n instance (auto-runs on first `kairos_prompt` call) |
104
+
105
+ #### Deployment tools
106
+
107
+ | Tool | Description |
108
+ |------|-------------|
109
+ | `kairos_deploy` | Deploys validated workflow JSON to n8n (re-validates before deploying) |
110
+ | `kairos_list` | List all deployed workflows |
111
+ | `kairos_get` | Get full workflow JSON by ID |
112
+ | `kairos_activate` | Activate a workflow |
113
+ | `kairos_deactivate` | Deactivate a workflow |
114
+ | `kairos_delete` | Delete a workflow |
115
+ | `kairos_executions` | List recent executions with status |
116
+
117
+ ---
118
+
119
+ ## Use as SDK
120
+
121
+ ### Installation
27
122
 
28
123
  ```bash
29
124
  npm install @kairos-sdk/core @anthropic-ai/sdk
@@ -36,8 +131,9 @@ npm install @kairos-sdk/core @anthropic-ai/sdk
36
131
  ## Requirements
37
132
 
38
133
  - Node.js 18+
39
- - An [Anthropic API key](https://console.anthropic.com)
40
- - An n8n instance with API access enabled (Cloud or self-hosted)
134
+ - **SDK only:** An [Anthropic API key](https://console.anthropic.com) — the SDK calls Claude internally
135
+ - **MCP:** No Anthropic key needed your host LLM does the generation
136
+ - An n8n instance with API access enabled (Cloud or self-hosted) — only needed for deployment, not for generation/validation
41
137
 
42
138
  ---
43
139
 
@@ -94,15 +190,26 @@ The baseline run used Claude with the 22-rule validator and correction loop but
94
190
 
95
191
  ## How It Works
96
192
 
193
+ ### SDK flow (calls Claude internally)
194
+
97
195
  1. **Search** — Kairos searches its local workflow library for similar past builds. Matching workflows and their failure patterns are pulled into context.
98
196
  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
197
  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.
198
+ 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
199
  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
200
  6. **Strip** — Forbidden server-assigned fields (`id`, `createdAt`, `updatedAt`, etc.) are stripped before deployment.
103
201
  7. **Deploy** — The validated workflow is posted to your n8n instance via REST API.
104
202
  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
203
 
204
+ ### MCP flow (your LLM generates)
205
+
206
+ 1. **Prompt** — Your LLM calls `kairos_prompt`, which searches the library and returns the specialized system prompt, node catalog, library matches, and failure patterns.
207
+ 2. **Generate** — Your LLM generates the workflow JSON itself using that context. No separate API call.
208
+ 3. **Validate** — Your LLM calls `kairos_validate`, which checks the JSON against the same 23 structural rules.
209
+ 4. **Correct** — If validation fails, your LLM fixes the issues and calls `kairos_validate` again.
210
+ 5. **Deploy** — Your LLM calls `kairos_deploy`, which strips forbidden fields and posts the workflow to n8n.
211
+ 6. **Record** — The deployed workflow is saved to the local library for future retrieval.
212
+
106
213
  ---
107
214
 
108
215
  ## Validator Rules