@2kw/ai-mcp-server 8.2.1 → 8.3.0-dev.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.
@@ -75,7 +75,7 @@ export function register(server, client) {
75
75
  });
76
76
  // ── list_agent_catalog ──────────────────────────────────────────────────
77
77
  server.tool("2kw_list_agent_catalog", "List published agents as id, name and description. This is the read a chat-only USER "
78
- + "key may perform; 2kw_list_agents carries the operator configuration and needs VIEWER or above.", {
78
+ + "key may perform; 2kw_list_agents carries the operator configuration and needs MEMBER or above.", {
79
79
  search: z.string().optional().describe("Filter agents by name"),
80
80
  page: z.number().optional().default(0).describe("Page number (0-based)"),
81
81
  size: z.number().optional().default(20).describe("Page size"),
@@ -134,7 +134,15 @@ export function register(server, client) {
134
134
  tools: z.unknown().optional().describe("Tool configuration (JSON object)"),
135
135
  skills: z.unknown().optional().describe("Skill configuration (JSON object)"),
136
136
  hitlPolicy: z.unknown().optional().describe("Human-in-the-loop approval policy (JSON object)"),
137
- }, async ({ name, model, models, description, instructions, options, tools, skills, hitlPolicy }) => {
137
+ visibility: z
138
+ .enum(["organization", "restricted"])
139
+ .optional()
140
+ .describe("Who may use the agent: `organization` (default) for every member, `restricted` for members of `teamIds` only. A member may restrict an agent only to teams they belong to"),
141
+ teamIds: z
142
+ .array(z.string().min(1))
143
+ .optional()
144
+ .describe("The teams a restricted agent is open to; omit for `organization`"),
145
+ }, async ({ name, model, models, description, instructions, options, tools, skills, hitlPolicy, visibility, teamIds }) => {
138
146
  try {
139
147
  const body = { name, ...modelFields(model, models, true) };
140
148
  if (description !== undefined)
@@ -149,11 +157,15 @@ export function register(server, client) {
149
157
  body.skills = skills;
150
158
  if (hitlPolicy !== undefined)
151
159
  body.hitlPolicy = hitlPolicy;
160
+ if (visibility !== undefined)
161
+ body.visibility = visibility;
162
+ if (teamIds !== undefined)
163
+ body.teamIds = teamIds;
152
164
  const { data } = await client.POST("/v1/agents", {
153
165
  body: body,
154
166
  });
155
- // Create publishes version 1; an older backend does not, so publish then (#668).
156
- const { name: _name, description: _description, ...configuration } = body;
167
+ // Create publishes version 1; an older backend does not, so publish then (#668). Access is not version config.
168
+ const { name: _name, description: _description, visibility: _visibility, teamIds: _teamIds, ...configuration } = body;
157
169
  await ensurePublished(client, data, { ...configuration, changeDescription: "Initial version" });
158
170
  return {
159
171
  content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
@@ -240,6 +252,35 @@ export function register(server, client) {
240
252
  };
241
253
  }
242
254
  });
255
+ // ── get_agent_access / set_agent_access ─────────────────────────────────
256
+ server.tool("2kw_get_agent_access", "Show who may use an agent: everyone in the organization (`organization`), or only members of the listed teams (`restricted`). Administrators and owners reach every agent.", { agentId: z.string().describe("The agent ID") }, async ({ agentId }) => {
257
+ try {
258
+ const { data } = await client.GET("/v1/agents/{id}/access", { params: { path: { id: agentId } } });
259
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
260
+ }
261
+ catch (error) {
262
+ return { content: [{ type: "text", text: formatErrorForMcp(error) }], isError: true };
263
+ }
264
+ });
265
+ server.tool("2kw_set_agent_access", "Replace who may use an agent. `organization` opens it to every member and takes no teams; `restricted` limits it to members of `teamIds` (with no team: administrators and owners only). Administrators and owners only. The organization's default agent cannot be restricted.", {
266
+ agentId: z.string().describe("The agent ID"),
267
+ visibility: z.enum(["organization", "restricted"]).describe("Who may use the agent"),
268
+ teamIds: z
269
+ .array(z.string().min(1))
270
+ .optional()
271
+ .describe("The teams a restricted agent is open to; omit for `organization`"),
272
+ }, async ({ agentId, visibility, teamIds }) => {
273
+ try {
274
+ const { data } = await client.PUT("/v1/agents/{id}/access", {
275
+ params: { path: { id: agentId } },
276
+ body: { visibility, teamIds: teamIds ?? [] },
277
+ });
278
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
279
+ }
280
+ catch (error) {
281
+ return { content: [{ type: "text", text: formatErrorForMcp(error) }], isError: true };
282
+ }
283
+ });
243
284
  // ── list_agent_versions ─────────────────────────────────────────────────
244
285
  server.tool("2kw_list_agent_versions", "List version history for an agent, with pagination.", {
245
286
  agentId: z.string().describe("The agent ID"),
@@ -332,7 +373,7 @@ export function register(server, client) {
332
373
  // ── list_agent_skills ───────────────────────────────────────────────────
333
374
  server.tool("2kw_list_agent_skills", "List the skills an agent's latest published version binds, in authored order. This is the "
334
375
  + "read a chat-only USER key may perform; 2kw_get_latest_agent_version carries the full version "
335
- + "and needs VIEWER or above. An agent with no published version lists none.", { agentId: z.string().describe("The agent ID") }, async ({ agentId }) => {
376
+ + "and needs MEMBER or above. An agent with no published version lists none.", { agentId: z.string().describe("The agent ID") }, async ({ agentId }) => {
336
377
  try {
337
378
  const { data } = await client.GET("/v1/agents/{agentId}/skills", {
338
379
  params: { path: { agentId } },
@@ -0,0 +1,8 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { ApiClient } from "../client.js";
3
+ /**
4
+ * Batches (#1844, batch spec §8): one instruction run by an agent over many files, one item
5
+ * at a time, in the background, as the API key's owner.
6
+ */
7
+ export declare function register(server: McpServer, client: ApiClient): void;
8
+ //# sourceMappingURL=batches.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { writeFile } from "node:fs/promises";
3
+ import { z } from "zod";
4
+ import { formatErrorForMcp } from "../errors.js";
5
+ async function reply(action) {
6
+ try {
7
+ const data = await action();
8
+ return {
9
+ content: [{ type: "text", text: typeof data === "string" ? data : JSON.stringify(data, null, 2) }],
10
+ };
11
+ }
12
+ catch (error) {
13
+ return { content: [{ type: "text", text: formatErrorForMcp(error) }], isError: true };
14
+ }
15
+ }
16
+ const batchId = z.string().min(1).describe("The batch id, from 2kw_create_batch or 2kw_list_batches");
17
+ /**
18
+ * Batches (#1844, batch spec §8): one instruction run by an agent over many files, one item
19
+ * at a time, in the background, as the API key's owner.
20
+ */
21
+ export function register(server, client) {
22
+ server.tool("2kw_create_batch", "Start a batch: the agent runs the instruction once per item, in the background. Give fileIds (uploaded files, each an item) or zipFileId (one uploaded ZIP whose files become the items), not both. A batch takes at most 500 items of at most 5 files each; files that cannot be used are left out and listed in skipped. Poll 2kw_get_batch for progress.", {
23
+ agent: z.string().min(1).describe("The agent to run, by id or name"),
24
+ instruction: z.string().min(1).max(4000).describe("What to do with each item"),
25
+ fileIds: z.array(z.string().min(1)).optional().describe("Uploaded files, each an item (or grouped, see groupBy)"),
26
+ zipFileId: z.string().min(1).optional().describe("One uploaded ZIP whose files become the items, instead of fileIds"),
27
+ groupBy: z
28
+ .enum(["file", "stem"])
29
+ .optional()
30
+ .describe("file (default): one item per file. stem: files that share a base name, such as a.pdf and a.dxf, are one item"),
31
+ requiredOutputs: z
32
+ .array(z.string().min(1))
33
+ .max(10)
34
+ .optional()
35
+ .describe("File extensions, such as pdf, that every item must produce to succeed"),
36
+ idempotencyKey: z
37
+ .string()
38
+ .min(1)
39
+ .max(255)
40
+ .optional()
41
+ .describe("Sending the same key with the same body again returns the same batch; pass one to retry safely"),
42
+ }, async ({ agent, instruction, fileIds, zipFileId, groupBy, requiredOutputs, idempotencyKey }) => reply(async () => {
43
+ if (Boolean(fileIds?.length) === Boolean(zipFileId)) {
44
+ throw new Error("Give either fileIds or zipFileId");
45
+ }
46
+ const { data } = await client.POST("/v1/batches", {
47
+ body: {
48
+ agent,
49
+ instruction,
50
+ ...(fileIds && { file_ids: fileIds }),
51
+ ...(zipFileId && { zip_file_id: zipFileId }),
52
+ group_by: groupBy ?? "file",
53
+ ...(requiredOutputs && { required_outputs: requiredOutputs }),
54
+ idempotency_key: idempotencyKey ?? randomUUID(),
55
+ },
56
+ });
57
+ return data;
58
+ }));
59
+ server.tool("2kw_list_batches", "List your batches, newest first, with their status and counts, without their items. With all=true an admin or owner key lists every batch of the organization, status and counts only.", {
60
+ status: z
61
+ .enum(["queued", "running", "completed", "completed_with_failures", "canceling", "canceled"])
62
+ .optional()
63
+ .describe("Only batches in this status"),
64
+ all: z.boolean().optional().describe("Every batch of the organization (admin or owner)"),
65
+ }, async ({ status, all }) => reply(async () => (await client.GET("/v1/batches", { params: { query: { status, all } } })).data));
66
+ server.tool("2kw_get_batch", "Get a batch with its counts and items: each item's name, status and, when it failed, the reason.", { batchId }, async ({ batchId }) => reply(async () => (await client.GET("/v1/batches/{id}", { params: { path: { id: batchId } } })).data));
67
+ server.tool("2kw_cancel_batch", "Stop a batch: items not started are canceled at once, items running end when their run stops. A batch that has ended is returned as it is.", { batchId }, async ({ batchId }) => reply(async () => (await client.POST("/v1/batches/{id}/cancel", { params: { path: { id: batchId } } })).data));
68
+ server.tool("2kw_download_batch_archive", "Download a batch's outputs as one ZIP and save it to a local path: a folder per succeeded item and a report.csv listing every item with its status, reason and outputs. While the batch runs, the ZIP holds the items finished so far.", {
69
+ batchId,
70
+ savePath: z.string().min(1).describe("Local path to write the ZIP to"),
71
+ }, async ({ batchId, savePath }) => reply(async () => {
72
+ const { data } = await client.GET("/v1/batches/{id}/archive", {
73
+ params: { path: { id: batchId } },
74
+ parseAs: "arrayBuffer",
75
+ });
76
+ const bytes = Buffer.from(data);
77
+ await writeFile(savePath, bytes);
78
+ return `Downloaded ${bytes.length} bytes to ${savePath}`;
79
+ }));
80
+ }
81
+ //# sourceMappingURL=batches.js.map
@@ -2,6 +2,7 @@ import * as agents from "./agents.js";
2
2
  import * as aiGateway from "./ai-gateway.js";
3
3
  import * as analytics from "./analytics.js";
4
4
  import * as annotationQueues from "./annotation-queues.js";
5
+ import * as batches from "./batches.js";
5
6
  import * as billing from "./billing.js";
6
7
  import * as conversations from "./conversations.js";
7
8
  import * as conversion from "./conversion.js";
@@ -44,6 +45,12 @@ export const TOOL_GROUPS = [
44
45
  summary: "Create, read, rename and delete conversations, list their items and cancel a running turn.",
45
46
  register: (s, d) => conversations.register(s, d.client),
46
47
  },
48
+ {
49
+ id: "batches",
50
+ title: "Batches",
51
+ summary: "Run one instruction by an agent over many files in the background, follow or stop it, and download the results as one ZIP.",
52
+ register: (s, d) => batches.register(s, d.client),
53
+ },
47
54
  {
48
55
  id: "memory",
49
56
  title: "Memory",
@@ -60,7 +60,7 @@ export function register(server, client) {
60
60
  }
61
61
  });
62
62
  // ── traces ──────────────────────────────────────────────────────────────
63
- server.tool("2kw_list_traces", "List recent traces in the org. Traces are aggregated by trace_id across all spans. Optional filters: source service, status code (OK/ERROR/UNSET, CSV for multiple), free-text search across trace id + span name + service + backbone.operation.", {
63
+ server.tool("2kw_list_traces", "List recent traces in the org. Traces are aggregated by trace_id across all spans. Optional filters: source service, status code (OK/ERROR/UNSET, CSV for multiple), free-text search across trace id + span name + service + backbone.operation, and a start-time range. Without from, the server lists the 7 days before to, or before now.", {
64
64
  sourceService: z.string().optional().describe("Filter by source_service"),
65
65
  statusCode: z
66
66
  .string()
@@ -70,6 +70,11 @@ export function register(server, client) {
70
70
  .string()
71
71
  .optional()
72
72
  .describe("Free-text search across trace id / span name / service / operation"),
73
+ from: z
74
+ .string()
75
+ .optional()
76
+ .describe("Start of time range (ISO-8601). Default: the 7 days before `to`, or before now"),
77
+ to: z.string().optional().describe("End of time range (ISO-8601)"),
73
78
  page: z.number().int().min(0).optional().describe("Page index (0-based)"),
74
79
  size: z.number().int().min(1).max(100).optional().describe("Page size"),
75
80
  }, async (params) => {
@@ -80,6 +85,8 @@ export function register(server, client) {
80
85
  sourceService: params.sourceService,
81
86
  statusCode: params.statusCode,
82
87
  search: params.search,
88
+ from: params.from,
89
+ to: params.to,
83
90
  page: params.page ?? 0,
84
91
  size: params.size ?? 20,
85
92
  },
@@ -129,13 +136,13 @@ export function register(server, client) {
129
136
  }
130
137
  });
131
138
  // ── sessions ────────────────────────────────────────────────────────────
132
- server.tool("2kw_list_trace_sessions", "List sessions (spans grouped by an exporter-stamped session id) in the org, with turn/error counts, duration, tokens and cost. Optional free-text search across session id and name, an exact session id match, and a start-time range. Each line starts with the session's own id, which 2kw_get_trace_session takes.", {
139
+ server.tool("2kw_list_trace_sessions", "List sessions (spans grouped by an exporter-stamped session id) in the org, with turn/error counts, duration, tokens and cost. Optional free-text search across session id and name, an exact session id match, and a start-time range. Without from, the server lists the 7 days before to, or before now. Each line starts with the session's own id, which 2kw_get_trace_session takes.", {
133
140
  search: z.string().optional().describe("Free-text search across session id and name"),
134
141
  sessionId: z
135
142
  .string()
136
143
  .optional()
137
144
  .describe("Exact match on the session.id the exporter stamped (slashes allowed)"),
138
- from: z.string().optional().describe("Start of time range (ISO-8601)"),
145
+ from: z.string().optional().describe("Start of time range (ISO-8601). Default: the 7 days before `to`, or before now"),
139
146
  to: z.string().optional().describe("End of time range (ISO-8601)"),
140
147
  page: z.number().int().min(0).optional().describe("Page index (0-based)"),
141
148
  size: z.number().int().min(1).max(100).optional().describe("Page size"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2kw/ai-mcp-server",
3
- "version": "8.2.1",
3
+ "version": "8.3.0-dev.16",
4
4
  "description": "MCP server for 2kw.ai — EU-hosted AI platform: OpenAI-compatible LLM gateway, schema-driven document extraction, transcription, agents with a knowledge base, and cost observability. 199 tools for Claude Code, Cursor, and Windsurf.",
5
5
  "mcpName": "ai.2kw/mcp-server",
6
6
  "keywords": [