@kumion/cli 0.2.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/dist/mcp.js ADDED
@@ -0,0 +1,144 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import { ApiError } from "./client.js";
4
+ import { describeError, UsageError } from "./errors.js";
5
+ export const MAX_TEST_RUN_WAIT_SECONDS = 120;
6
+ const TERMINAL = new Set(["passed", "failed", "could_not_run", "timeout", "cancelled"]);
7
+ function json(value) {
8
+ return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
9
+ }
10
+ function failure(err) {
11
+ let text = describeError(err);
12
+ if (err instanceof ApiError && err.status === 422)
13
+ text += "\n" + JSON.stringify(err.body, null, 2);
14
+ return { isError: true, content: [{ type: "text", text }] };
15
+ }
16
+ async function attempt(run) {
17
+ try {
18
+ return json(await run());
19
+ }
20
+ catch (err) {
21
+ return failure(err);
22
+ }
23
+ }
24
+ const agentId = z.string().min(1).describe("The agent's id, from list_agents.");
25
+ export function createKumionMcpServer(client, options) {
26
+ const server = new McpServer({ name: "kumion", version: options.version });
27
+ server.registerTool("list_agents", {
28
+ description: "List the voice agents of the Kumion tenant this key belongs to. Needs the agents:read scope.",
29
+ annotations: { readOnlyHint: true },
30
+ }, () => attempt(async () => ({ tenantId: client.tenantId, agents: await client.listAgents() })));
31
+ server.registerTool("get_agent", {
32
+ description: "Read one agent: its draft (prompt, flow graph) and its published version. The returned `revision` is " +
33
+ "what patch_agent needs. Needs agents:read.",
34
+ inputSchema: { agentId },
35
+ annotations: { readOnlyHint: true },
36
+ }, (args) => attempt(() => client.getAgent(args.agentId)));
37
+ server.registerTool("patch_agent", {
38
+ description: "Edit an agent's draft (never goes live by itself — publish_agent does that). `revision` must be the one " +
39
+ "get_agent returned when you read the draft you are changing; if the draft changed since, nothing is " +
40
+ "written and you get a conflict: read it again and re-apply. Needs agents:write.",
41
+ inputSchema: {
42
+ agentId,
43
+ revision: z.string().min(1).describe("The draft revision your change is based on, from get_agent."),
44
+ prompt: z.string().optional().describe("New system prompt (prompt-only agents)."),
45
+ graph: z.unknown().optional().describe("New flow graph — get_agent's draft.graph, edited."),
46
+ },
47
+ annotations: { destructiveHint: false, idempotentHint: false },
48
+ }, (args) => {
49
+ const patch = {};
50
+ if (args.prompt !== undefined)
51
+ patch.prompt = args.prompt;
52
+ if (args.graph !== undefined)
53
+ patch.graph = args.graph;
54
+ if (patch.prompt === undefined && patch.graph === undefined) {
55
+ return failure(new UsageError("Nothing to change: pass `prompt` or `graph`."));
56
+ }
57
+ return attempt(() => client.patchAgent(args.agentId, patch, args.revision));
58
+ });
59
+ server.registerTool("publish_agent", {
60
+ description: "Publish the agent's draft so callers get it. Runs the same pre-publish check as the Portal first and " +
61
+ "publishes only if it passes; there is no way to skip it. Can take a few minutes. On failure the " +
62
+ "failing cases are returned. Needs agents:publish.",
63
+ inputSchema: {
64
+ agentId,
65
+ revision: z.string().optional().describe("Refuse to publish if the draft is no longer at this revision."),
66
+ },
67
+ annotations: { destructiveHint: true, idempotentHint: false },
68
+ }, (args) => attempt(() => client.publishAgent(args.agentId, args.revision)));
69
+ server.registerTool("start_test_run", {
70
+ description: "Run the agent's regression tests against its draft (publishes nothing). Returns at once with the run " +
71
+ `unless waitSeconds is set (at most ${MAX_TEST_RUN_WAIT_SECONDS}); follow a running run with ` +
72
+ "get_test_run. Needs tests:run.",
73
+ inputSchema: {
74
+ agentId,
75
+ waitSeconds: z
76
+ .number()
77
+ .int()
78
+ .min(0)
79
+ .max(MAX_TEST_RUN_WAIT_SECONDS)
80
+ .optional()
81
+ .describe("Wait up to this many seconds for the run to finish before returning."),
82
+ },
83
+ }, (args) => attempt(async () => {
84
+ let run = await client.startTestRun(args.agentId);
85
+ const deadline = (args.waitSeconds ?? 0) * 1000;
86
+ let waited = 0;
87
+ while (!TERMINAL.has(run.status) && waited < deadline) {
88
+ const step = Math.min(3000, deadline - waited);
89
+ await options.sleep(step);
90
+ waited += step;
91
+ run = await client.getTestRun(args.agentId, run.id);
92
+ }
93
+ return { testRun: run };
94
+ }));
95
+ server.registerTool("get_test_run", {
96
+ description: "Read one test run: status, progress and each failing case. Needs tests:run.",
97
+ inputSchema: { agentId, runId: z.string().min(1).describe("The run's id, from start_test_run.") },
98
+ annotations: { readOnlyHint: true },
99
+ }, (args) => attempt(async () => ({ testRun: await client.getTestRun(args.agentId, args.runId) })));
100
+ server.registerTool("list_test_runs", {
101
+ description: "List the agent's recent test runs, newest first. Needs tests:run.",
102
+ inputSchema: { agentId, limit: z.number().int().positive().optional() },
103
+ annotations: { readOnlyHint: true },
104
+ }, (args) => attempt(async () => ({ testRuns: await client.listTestRuns(args.agentId, args.limit) })));
105
+ server.registerTool("create_call", {
106
+ description: "Start a web test call with the agent. Returns the LiveKit room and a participant token to join it. " +
107
+ "Needs calls:create.",
108
+ inputSchema: {
109
+ agentId,
110
+ campaignContactId: z.string().optional().describe("Call as this campaign contact (optional)."),
111
+ },
112
+ annotations: { idempotentHint: false },
113
+ }, (args) => attempt(() => client.createCall(args.agentId, args.campaignContactId)));
114
+ const callId = z.string().min(1).describe("The call's id, from list_calls.");
115
+ server.registerTool("list_calls", {
116
+ description: "List the tenant's call history, newest first, one page at a time (default 20, at most 100); `total` " +
117
+ "counts every call matching the filters. Draft test calls are not listed. Needs calls:read.",
118
+ inputSchema: {
119
+ agentId: z.string().optional().describe("Only this agent's calls."),
120
+ channel: z.enum(["webcall", "sip_did", "trigger"]).optional().describe("Only calls in on this channel."),
121
+ from: z.string().optional().describe("Started at or after this instant (ISO 8601)."),
122
+ to: z.string().optional().describe("Started before this instant (ISO 8601)."),
123
+ q: z.string().optional().describe("Caller number, or the start of a call id."),
124
+ limit: z.number().int().min(1).max(100).optional(),
125
+ offset: z.number().int().min(0).optional(),
126
+ },
127
+ annotations: { readOnlyHint: true },
128
+ }, (args) => attempt(() => client.listCalls(args)));
129
+ server.registerTool("get_call", {
130
+ description: "Read one call: agent, source and direction, numbers, when it started, was answered and ended, how it " +
131
+ "ended, and whether a transcript exists (read it with get_call_transcript). The channel is only on " +
132
+ "list_calls. Needs calls:read.",
133
+ inputSchema: { callId },
134
+ annotations: { readOnlyHint: true },
135
+ }, (args) => attempt(async () => ({ call: await client.getCall(args.callId) })));
136
+ server.registerTool("get_call_transcript", {
137
+ description: "Read what the caller (`user`) and the agent (`assistant`) said on one call, in order. Tool calls and " +
138
+ "the agent's instructions are not included. `available: false` means no transcript has been written " +
139
+ "yet (the call is still up, or never connected) — not that the call was silent. Needs calls:read.",
140
+ inputSchema: { callId },
141
+ annotations: { readOnlyHint: true },
142
+ }, (args) => attempt(async () => ({ transcript: await client.getTranscript(args.callId) })));
143
+ return server;
144
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@kumion/cli",
3
+ "version": "0.2.0",
4
+ "description": "Manage your Kumion voice agents from the terminal over the Kumion Partner API",
5
+ "author": "KAOPA株式会社",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/KarryViber/Kumion.git",
10
+ "directory": "packages/cli"
11
+ },
12
+ "homepage": "https://help.kumion.jp",
13
+ "bugs": {
14
+ "url": "https://github.com/KarryViber/Kumion/issues"
15
+ },
16
+ "type": "module",
17
+ "bin": {
18
+ "kumion": "dist/cli.js"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "!dist/**/*.test.*",
23
+ "skills",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "engines": {
28
+ "node": ">=20.18.1"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.build.json",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest run",
37
+ "prepack": "npm run build"
38
+ },
39
+ "dependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.30.1",
41
+ "@napi-rs/keyring": "^2.1.0",
42
+ "undici": "^7.29.1",
43
+ "zod": "^3.25.76"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.10.2",
47
+ "typescript": "^5.7.2",
48
+ "vitest": "^2.1.8"
49
+ }
50
+ }
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: kumion
3
+ description: Build, edit, test and publish Kumion voice agents for one customer tenant, remotely over the Kumion Partner API with the `kumion` CLI or its `kumion mcp` tools. Use when the user asks to change what a Kumion agent says or does, run its tests, publish it, start a test call, or read what was said on its calls.
4
+ ---
5
+
6
+ # Kumion voice agents
7
+
8
+ Kumion agents live in the Kumion service, per customer tenant. You change them
9
+ **remotely**: read the agent, edit its draft, test the draft, publish. There is no
10
+ repository to clone and no local agent file to keep in sync — do not create one.
11
+
12
+ Two ways in, same operations and same permissions:
13
+
14
+ - **MCP tools** (`list_agents`, `get_agent`, `patch_agent`, `publish_agent`,
15
+ `start_test_run`, `get_test_run`, `list_test_runs`, `create_call`, `list_calls`,
16
+ `get_call`, `get_call_transcript`) when the host
17
+ has the `kumion` MCP server registered.
18
+ - **The `kumion` CLI** otherwise (`kumion --help`). Add `--json` for machine-readable
19
+ output.
20
+
21
+ ## Before anything: is it logged in?
22
+
23
+ Run `kumion auth status`. If it says "Not logged in", **stop and ask the user** to run
24
+ `kumion auth login` themselves: it prints a link and a code, and the user approves
25
+ it in the Portal in their browser (a tenant administrator gets a personal key good for
26
+ 12 hours). With a key from 設定 → 開発者 it is `kumion auth login --with-api-key`,
27
+ which prompts for the tenant ID and the key with hidden input. Do not run the login
28
+ yourself and do not approve anything on the user's behalf. Never ask the user to paste
29
+ an API key into the chat, never put a key in a command line, a file, `.mcp.json` or an
30
+ `env` block. In CI the key comes from the CI
31
+ secret store as `KUMION_API_KEY` + `KUMION_TENANT_ID`.
32
+
33
+ A partner with several customers has one profile per customer tenant
34
+ (`kumion auth list`). Confirm which customer the user means before writing; pass
35
+ `--profile <name>` to the CLI, or register one MCP server per profile.
36
+
37
+ ## The loop
38
+
39
+ 1. **Find the agent** — `list_agents` / `kumion agents list`.
40
+ 2. **Read it** — `get_agent` / `kumion agents get <agentId> --json`. Note `revision`.
41
+ A flow agent's behaviour is in `draft.graph`; a prompt-only agent's in
42
+ `draft.prompt`.
43
+ 3. **Edit the draft** — `patch_agent` with the `revision` you read /
44
+ `kumion agents patch <agentId> --revision <rev> --prompt-file … | --graph-file …`.
45
+ Send the whole edited graph, not a fragment. The draft is not live.
46
+ - **Conflict (409)**: someone saved the agent since you read it. Nothing was
47
+ written. Read it again, re-apply your change to the new draft, patch with the
48
+ new revision. Never retry with a revision you did not just read.
49
+ 4. **Test** — `start_test_run` (then `get_test_run` until it leaves `running`) /
50
+ `kumion test-runs start <agentId>` (waits; exit 0 only on pass). Fix failures in
51
+ the draft and test again.
52
+ 5. **Publish** — only when the user asked for it. `publish_agent` /
53
+ `kumion agents publish <agentId>`. It runs the same pre-publish check as the Portal
54
+ and can take a few minutes. If the check fails, nothing goes live and the failing
55
+ cases come back: fix, test, publish again. There is no skip or override; do not
56
+ look for one.
57
+ 6. **Try it** (optional) — `create_call` / `kumion calls create <agentId>` starts a web
58
+ test call and returns a LiveKit room and token.
59
+
60
+ ## Reading real calls
61
+
62
+ `list_calls` / `kumion calls list` pages through the call history (filter by agent,
63
+ channel, time range, or caller number); `get_call_transcript` /
64
+ `kumion calls transcript <callId>` returns what the caller (`user`) and the agent
65
+ (`assistant`) said. `available: false` means no transcript has been written yet, not a
66
+ silent call. Use a transcript to find where the agent went wrong before editing its
67
+ draft. Transcripts are the tenant's customers' conversations: quote only what the task
68
+ needs.
69
+
70
+ Not available over the Partner API (do not look for a command): operating hours,
71
+ conversation-edit mode, the knowledge base, bookings, external-tool limits and the
72
+ agent language setting. Those are Portal-only.
73
+
74
+ ## When it refuses
75
+
76
+ - **401** — key wrong, revoked, expired, or for another tenant. A personal key from
77
+ the browser login expires after 12 hours and dies when its owner stops being a
78
+ tenant administrator (`kumion auth status` shows its expiry). The user re-runs
79
+ `kumion auth login`.
80
+ - **403 naming a scope** — the key lacks it (`agents:read`, `agents:write`,
81
+ `agents:publish`, `tests:run`, `calls:create`, `calls:read`). The user issues a key with that scope
82
+ in the Portal (設定 → 開発者) and logs in again. Do not work around it.
83
+ - **403 without a scope name** — the tenant's plan cannot publish, or `create_call` hit
84
+ the call-minute limit. Tell the user; a new key does not help.
85
+ - **429** — rate limited; wait the stated seconds.
86
+
87
+ Callers hear what is published. Say clearly to the user what you changed in the draft,
88
+ what the tests said, and whether anything was published.