@taiga-ai/mcp-server 0.38.0-dev.1210 → 0.38.0-dev.1211

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.
Files changed (2) hide show
  1. package/dist/index.js +146 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -41837,6 +41837,108 @@ function registerMove(server, client) {
41837
41837
  }));
41838
41838
  }
41839
41839
  /**
41840
+ * What linking knowledge to an initiative reads and needs: the initiative (its
41841
+ * product and the files it links now), each file, and the write the web's
41842
+ * picker is gated on (PRO-4984). A factory's file also reads the product, for
41843
+ * its factory (products:read).
41844
+ */
41845
+ const LINK_KNOWLEDGE_NEEDS = [
41846
+ "backlog:read",
41847
+ "customDocuments:read",
41848
+ "customDocuments:write"
41849
+ ];
41850
+ /**
41851
+ * Why a file read by ID cannot stay linked, or null: one that failed
41852
+ * processing, which the API refuses (findReferenceableIds). One still
41853
+ * processing stays, as the web's upload links it at once. A deleted file does
41854
+ * not read at all; the API's refusal of it is passed through.
41855
+ */
41856
+ function gone(file) {
41857
+ return file.status === "failed" ? "failed processing; add it again" : null;
41858
+ }
41859
+ /** Why a file cannot be newly linked, or null when it can: as the picker offers them (isAddable), ready ones only. */
41860
+ function unavailable(file) {
41861
+ if (file.kbStatus !== "active") return "is being removed";
41862
+ return gone(file) ?? (file.status !== "ready" ? "is still being processed; link it once its status is ready" : null);
41863
+ }
41864
+ /**
41865
+ * The knowledge an edit links, checked as the web's picker offers it
41866
+ * (ReferencedDocumentsPicker): the product's own files and its factory's,
41867
+ * once ready. The API takes any file of the organization, so another
41868
+ * product's file is refused here; a file the person cannot open reads as not
41869
+ * found. Each file is read by ID, its scope and state on it. The description's
41870
+ * images are linked too (origin inline), but the API keeps them whatever is
41871
+ * sent, so they are left out of the list, its cap and the answer. A file linked
41872
+ * already that failed since is refused by the API, so it is named here.
41873
+ */
41874
+ async function knowledgeLinks(client, item, documentIds) {
41875
+ const current = item.documentIds ?? [];
41876
+ const wanted = [...new Set(documentIds)];
41877
+ const ids = [.../* @__PURE__ */ new Set([...current, ...wanted])];
41878
+ const read = await Promise.all(ids.map((docId) => client.getKnowledge(docId).then((result) => [docId, result.data], (error) => {
41879
+ if (isMissOrRefusal(error)) return [docId, null];
41880
+ throw error;
41881
+ })));
41882
+ const files = new Map(read);
41883
+ const inline = (docId) => files.get(docId)?.origin === "inline";
41884
+ const send = wanted.filter((docId) => !inline(docId));
41885
+ if (send.length > 25) return { refused: `An initiative links at most 25 knowledge files.` };
41886
+ const before = current.filter((docId) => !inline(docId));
41887
+ const changed = send.length !== before.length || send.some((docId) => !before.includes(docId));
41888
+ const ref = (docId) => ({
41889
+ id: docId,
41890
+ fileName: files.get(docId)?.fileName ?? null
41891
+ });
41892
+ if (!changed) return {
41893
+ send,
41894
+ changed,
41895
+ linked: send.map(ref),
41896
+ unlinked: []
41897
+ };
41898
+ let factoryId;
41899
+ const reasons = [];
41900
+ for (const docId of send) {
41901
+ const file = files.get(docId);
41902
+ const name = file ? `${file.fileName} (${docId})` : docId;
41903
+ if (before.includes(docId)) {
41904
+ const why = file && gone(file);
41905
+ if (why) reasons.push(`${name}, linked already, ${why}; leave it out to unlink it`);
41906
+ continue;
41907
+ }
41908
+ if (!file) {
41909
+ reasons.push(`${docId} is not a knowledge file this key can open`);
41910
+ continue;
41911
+ }
41912
+ let ofThisProduct = file.productId === item.productId;
41913
+ if (!ofThisProduct && file.productId === null && file.factoryId !== null) {
41914
+ if (!client.hasCapability("products:read")) {
41915
+ reasons.push(`${name} is a factory's file; linking one reads the product, which needs products:read`);
41916
+ continue;
41917
+ }
41918
+ factoryId ??= (await client.getProduct(item.productId)).data.factoryId ?? null;
41919
+ ofThisProduct = file.factoryId === factoryId;
41920
+ }
41921
+ if (!ofThisProduct) {
41922
+ reasons.push(`${name} is not a knowledge file of this product or its factory`);
41923
+ continue;
41924
+ }
41925
+ const why = unavailable(file);
41926
+ if (why) reasons.push(`${name} ${why}`);
41927
+ }
41928
+ if (reasons.length > 0) return { refused: `${reasons.join("; ")}. taiga_list_knowledge lists the product's files (productId) and its factory's (factoryId).` };
41929
+ return {
41930
+ send,
41931
+ changed,
41932
+ linked: send.map(ref),
41933
+ unlinked: before.filter((docId) => !send.includes(docId)).map(ref)
41934
+ };
41935
+ }
41936
+ /** What an edit that changed nothing left as it was. */
41937
+ function unchangedWhat(criteria, knowledge) {
41938
+ if (criteria && knowledge) return "The criteria and linked knowledge are as they were";
41939
+ return criteria ? "The criteria are as they were" : "The linked knowledge is as it was";
41940
+ }
41941
+ /**
41840
41942
  * A criterion as the edit takes it: its text, and whether it needs an
41841
41943
  * end-to-end check. Whether it is met is not the caller's to say: checking a
41842
41944
  * criterion off is a person's verdict or a run's verification, and the web's
@@ -41899,7 +42001,7 @@ const MAX_INT = 2147483647;
41899
42001
  function registerEdit(server, client) {
41900
42002
  server.registerTool("taiga_update_initiative", {
41901
42003
  title: "Edit initiative",
41902
- description: "Change an initiative's title, description, priority, estimate, category, dependencies or acceptance criteria in place, as a person edits it in the web. Use it to correct, reword or translate an initiative rather than canceling it and requesting a new one. A field left out stays as it is. dependencies and acceptanceCriteria replace the whole list: read it first with taiga_get_initiative full: true. A criterion whose text is unchanged keeps whether it is met; a new, reworded or newly end-to-end one starts unmet. The text is refused (CONFLICT) while an agent works on the initiative or its plan waits for review. taiga_move_initiative moves it on the board.",
42004
+ description: "Change an initiative's title, description, priority, estimate, category, dependencies, acceptance criteria or linked knowledge in place, as a person edits it in the web. Use it to correct, reword or translate an initiative rather than canceling it and requesting a new one. A field left out stays as it is. dependencies and acceptanceCriteria and documentIds replace the whole list: read it first with taiga_get_initiative full: true. A criterion whose text is unchanged keeps whether it is met; a new, reworded or newly end-to-end one starts unmet. The text is refused (CONFLICT) while an agent works on the initiative or its plan waits for review. documentIds links knowledge files the planner reads when it plans it: the product's own and its factory's, once ready (taiga_list_knowledge); the result names what it links and unlinks. taiga_move_initiative moves it on the board.",
41903
42005
  inputSchema: object({
41904
42006
  initiativeId,
41905
42007
  title: string$2().trim().min(1).max(500).optional().describe("A new title"),
@@ -41908,34 +42010,58 @@ function registerEdit(server, client) {
41908
42010
  estimate: number$1().int().min(0).max(MAX_INT).optional().describe("Its size in points"),
41909
42011
  category: _enum(BACKLOG_CATEGORIES).optional().describe("The kind of work"),
41910
42012
  dependencies: array(idInput("initiative", "taiga_list_initiatives gives it")).optional().describe("Every initiative it waits for, replacing the list; [] clears it"),
41911
- acceptanceCriteria: array(criterionInput).optional().describe("Every criterion, in order, replacing the list")
42013
+ acceptanceCriteria: array(criterionInput).optional().describe("Every criterion, in order, replacing the list"),
42014
+ documentIds: array(idInput("knowledge file", "taiga_list_knowledge gives it")).optional().describe(`Every knowledge file it links, at most 25, replacing the list; [] clears it. Images in its description stay linked whatever is sent`)
41912
42015
  }),
41913
42016
  annotations: WRITE
41914
42017
  }, (params) => runTool(async () => {
41915
- const { initiativeId: id, acceptanceCriteria, ...fields } = params;
42018
+ const { initiativeId: id, acceptanceCriteria, documentIds, ...fields } = params;
41916
42019
  if (fields.dependencies?.includes(id)) return toolError("VALIDATION_ERROR", "An initiative cannot depend on itself.");
41917
- if (acceptanceCriteria === void 0 && Object.values(fields).every((value) => value === void 0)) return toolError("VALIDATION_ERROR", "Give at least one of title, description, priority, estimate, category, dependencies or acceptanceCriteria.");
42020
+ if (acceptanceCriteria === void 0 && documentIds === void 0 && Object.values(fields).every((value) => value === void 0)) return toolError("VALIDATION_ERROR", "Give at least one of title, description, priority, estimate, category, dependencies, acceptanceCriteria or documentIds.");
42021
+ if (documentIds !== void 0) {
42022
+ const lacking = LINK_KNOWLEDGE_NEEDS.filter((capability) => !client.hasCapability(capability));
42023
+ if (lacking.length > 0) return toolError("FORBIDDEN", `Linking knowledge reads the initiative and each file, and needs ${lacking.join(", ")}, which this key lacks.`);
42024
+ }
41918
42025
  if (acceptanceCriteria !== void 0 && !client.hasCapability("backlog:read")) return toolError("FORBIDDEN", "Editing acceptance criteria reads the current ones first and needs backlog:read, which this key lacks.");
42026
+ const current = acceptanceCriteria !== void 0 || documentIds !== void 0 ? (await client.getBacklogItem(id)).data : null;
42027
+ let links;
42028
+ if (documentIds !== void 0 && current) {
42029
+ const checked = await knowledgeLinks(client, current, documentIds);
42030
+ if ("refused" in checked) return toolError("VALIDATION_ERROR", checked.refused);
42031
+ links = checked;
42032
+ }
41919
42033
  let criteria;
41920
- if (acceptanceCriteria !== void 0) {
41921
- const current = (await client.getBacklogItem(id)).data;
42034
+ if (acceptanceCriteria !== void 0 && current) {
41922
42035
  const carried = carriedCriteria(current.acceptanceCriteria, acceptanceCriteria);
41923
42036
  if (criteriaSpec(carried) !== criteriaSpec(current.acceptanceCriteria)) criteria = carried;
41924
- else if (Object.values(fields).every((value) => value === void 0)) return toolResult({
41925
- ...outcomeOf(current),
41926
- unchanged: "The criteria are as they were; nothing was written."
41927
- });
41928
42037
  }
41929
- const item = (await client.updateBacklogItem(id, {
41930
- ...fields.title !== void 0 ? { title: fields.title } : {},
41931
- ...fields.description !== void 0 ? { description: fields.description } : {},
41932
- ...fields.priority !== void 0 ? { priority: fields.priority } : {},
41933
- ...fields.estimate !== void 0 ? { estimate: fields.estimate } : {},
41934
- ...fields.category !== void 0 ? { category: fields.category } : {},
41935
- ...fields.dependencies !== void 0 ? { dependencies: fields.dependencies } : {},
41936
- ...criteria !== void 0 ? { acceptanceCriteria: criteria } : {}
41937
- })).data;
41938
- return outcome(item);
42038
+ const linksChange = links?.changed === true;
42039
+ if (current && criteria === void 0 && !linksChange && Object.values(fields).every((v) => v === void 0)) return toolResult({
42040
+ ...outcomeOf(current),
42041
+ unchanged: `${unchangedWhat(acceptanceCriteria !== void 0, documentIds !== void 0)}; nothing was written.`
42042
+ });
42043
+ let item;
42044
+ try {
42045
+ item = (await client.updateBacklogItem(id, {
42046
+ ...fields.title !== void 0 ? { title: fields.title } : {},
42047
+ ...fields.description !== void 0 ? { description: fields.description } : {},
42048
+ ...fields.priority !== void 0 ? { priority: fields.priority } : {},
42049
+ ...fields.estimate !== void 0 ? { estimate: fields.estimate } : {},
42050
+ ...fields.category !== void 0 ? { category: fields.category } : {},
42051
+ ...fields.dependencies !== void 0 ? { dependencies: fields.dependencies } : {},
42052
+ ...criteria !== void 0 ? { acceptanceCriteria: criteria } : {},
42053
+ ...links && linksChange ? { documentIds: links.send } : {}
42054
+ })).data;
42055
+ } catch (error) {
42056
+ if (links && error instanceof TaigaApiError && error.status === 400 && /Referenced documents/.test(error.apiMessage ?? "")) return toolError("VALIDATION_ERROR", `${error.apiMessage} Leave them out of documentIds to unlink them.`);
42057
+ throw error;
42058
+ }
42059
+ if (!links) return outcome(item);
42060
+ return toolResult({
42061
+ ...outcomeOf(item),
42062
+ linkedKnowledge: links.linked,
42063
+ unlinkedKnowledge: links.unlinked
42064
+ });
41939
42065
  }));
41940
42066
  }
41941
42067
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taiga-ai/mcp-server",
3
- "version": "0.38.0-dev.1210",
3
+ "version": "0.38.0-dev.1211",
4
4
  "description": "Taiga for AI coding assistants: read products, policies, initiatives and runs, and operate the line, over MCP",
5
5
  "mcpName": "ga.tai/mcp-server",
6
6
  "license": "UNLICENSED",