@imenam/mcp-organizer 1.0.21 → 1.0.22

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 (44) hide show
  1. package/README.md +15 -11
  2. package/dist/shared/logic/documents.d.ts +2 -4
  3. package/dist/shared/logic/documents.js +6 -11
  4. package/dist/shared/schemas/agent-tools.schema.d.ts +133 -7
  5. package/dist/shared/schemas/agent-tools.schema.js +52 -7
  6. package/dist/shared/schemas/documents-api.schema.d.ts +0 -2
  7. package/dist/shared/schemas/documents-api.schema.js +0 -2
  8. package/dist/src/agent-api/attachments.d.ts +2 -0
  9. package/dist/src/agent-api/attachments.js +96 -0
  10. package/dist/src/agent-api/documents.d.ts +1 -1
  11. package/dist/src/agent-api/documents.js +9 -33
  12. package/dist/src/agent-api/files.d.ts +35 -0
  13. package/dist/src/agent-api/files.js +86 -0
  14. package/dist/src/agent-api/router.d.ts +2 -2
  15. package/dist/src/agent-api/router.js +5 -4
  16. package/dist/src/agent-api/tasks.js +5 -8
  17. package/dist/src/agent-api/types.d.ts +4 -2
  18. package/dist/src/core/agent-files.d.ts +41 -0
  19. package/dist/src/core/agent-files.js +102 -0
  20. package/dist/src/core/agent.d.ts +3 -1
  21. package/dist/src/core/agent.js +14 -3
  22. package/dist/src/core/document-text.d.ts +3 -2
  23. package/dist/src/core/document-text.js +3 -2
  24. package/dist/src/core/documents.js +0 -1
  25. package/dist/src/core/history.d.ts +3 -1
  26. package/dist/src/core/history.js +28 -11
  27. package/dist/src/core/requests.d.ts +9 -4
  28. package/dist/src/core/requests.js +21 -10
  29. package/dist/src/core/snapshots.d.ts +3 -3
  30. package/dist/src/core/snapshots.js +3 -1
  31. package/dist/src/gui-api.js +2 -2
  32. package/dist/src/mcp/client.d.ts +7 -4
  33. package/dist/src/mcp/client.js +31 -4
  34. package/dist/src/mcp/start.d.ts +1 -1
  35. package/dist/src/mcp/start.js +6 -6
  36. package/dist/src/mcp/tools.d.ts +11 -0
  37. package/dist/src/mcp/tools.js +55 -4
  38. package/dist/src/mcp/upload.d.ts +22 -0
  39. package/dist/src/mcp/upload.js +79 -0
  40. package/dist/src/server/app.js +38 -4
  41. package/gui/dist/assets/{index-DbzcjyaW.js → index-C1f7hOcM.js} +2 -2
  42. package/gui/dist/assets/{index-Dvf5Yo0e.css → index-CfMiwPSL.css} +1 -1
  43. package/gui/dist/index.html +2 -2
  44. package/package.json +3 -1
@@ -81,7 +81,7 @@ export const AGENT_TOOLS = [
81
81
  path: "requests/{request_id}/claim",
82
82
  definition: {
83
83
  name: "claim_request",
84
- description: "Claim a pending request before working on it: it becomes processing for your token only (no other agent can take it or act for it) and you get its full context — text, author, context task or idea, for a message the previous exchanges of its author (their requests and your replies), the task tree of your space with keys, statuses, priorities and assignees, its members and recent ideas. Pass this request_id to every write tool while you process it.",
84
+ description: "Claim a pending request before working on it: it becomes processing for your token only (no other agent can take it or act for it) and you get its full context — text, author, context task or idea, for a message the previous exchanges of its author (their requests and your replies), the context task's attachments (open them with get_attachment), the task tree of your space with keys, statuses, priorities and assignees, its members and recent ideas. Pass this request_id to every write tool while you process it.",
85
85
  inputSchema: {
86
86
  type: "object",
87
87
  properties: { request_id: { type: "string", description: "Id of a pending request, from list_requests." } },
@@ -104,7 +104,7 @@ export const AGENT_TOOLS = [
104
104
  path: "tasks/{task}",
105
105
  definition: {
106
106
  name: "get_task",
107
- description: "Read one task of your space in detail: fields, parents, assignees, tags, description, questions with their options and the members' answers (ids needed by edit_questions), checklist items or test checkpoints (with their ids, needed by edit_checklist), sub-tasks, recent comments and attachments. Use it before modifying a task.",
107
+ description: "Read one task of your space in detail: fields, parents, assignees, tags, description, questions with their options and the members' answers (ids needed by edit_questions), checklist items or test checkpoints (with their ids, needed by edit_checklist), sub-tasks, recent comments and attachments with their id (open them with get_attachment). Use it before modifying a task.",
108
108
  inputSchema: { type: "object", properties: { task: TASK_REF }, required: ["task"], additionalProperties: false },
109
109
  },
110
110
  },
@@ -163,7 +163,7 @@ export const AGENT_TOOLS = [
163
163
  path: "documents",
164
164
  definition: {
165
165
  name: "list_documents",
166
- description: "List the reference documents of your space: files the members upload (reports, specifications, exports…) so you know the real state of their project. Each one comes with its id, file name, description, format, size, version and whether you can read its content.",
166
+ description: "List the reference documents of your space: files the members upload (reports, specifications, exports…) so you know the real state of their project. Each one comes with its id, file name, description, format, size and version; read one with get_document.",
167
167
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
168
168
  },
169
169
  },
@@ -172,7 +172,7 @@ export const AGENT_TOOLS = [
172
172
  path: "documents/{document}",
173
173
  definition: {
174
174
  name: "get_document",
175
- description: "Read a reference document of your space. Text files (txt, md, csv, json, yaml, xml…) come as they are and Word files (.docx) as their extracted text, in parts of 20,000 characters: the result says how many parts there are. You cannot read PDF files or images: you get their name and description only. Read a document when it helps the request you process, for example to align tasks and priorities with a report on the project.",
175
+ description: "Read a reference document of your space. Text files (txt, md, csv, json, yaml, xml…) come as they are, Word files (.docx) and PDF files as their extracted text, in parts of 20,000 characters: the result says how many parts there are. An image comes as the image itself, which you see (reduced when it exceeds the limits of the Claude API). A PDF without a text layer (a scan) is reported as such. Read a document when it helps the request you process, for example to align tasks and priorities with a report on the project.",
176
176
  inputSchema: {
177
177
  type: "object",
178
178
  properties: {
@@ -184,6 +184,23 @@ export const AGENT_TOOLS = [
184
184
  },
185
185
  },
186
186
  },
187
+ {
188
+ method: "GET",
189
+ path: "attachments/{attachment}",
190
+ definition: {
191
+ name: "get_attachment",
192
+ description: "Open an attachment of a task of your space. An image comes as the image itself, which you see (reduced when it exceeds the limits of the Claude API); a PDF file, a text file or a Word file (.docx) comes as its extracted text, in parts of 20,000 characters. A PDF without a text layer (a scan) is reported as such. Take the id from get_task or claim_request, or from a reference ![name](attachment:<id>) in a description, a comment or a checkpoint comment. Open the attachments that matter for the request, for example a screenshot of a failed checkpoint or one cited in a comment mentioning @agent.",
193
+ inputSchema: {
194
+ type: "object",
195
+ properties: {
196
+ attachment: { type: "string", description: "Id of an attachment of a task of your space." },
197
+ part: { type: "integer", minimum: 1, description: "Part of the text to read, from 1. Default: 1." },
198
+ },
199
+ required: ["attachment"],
200
+ additionalProperties: false,
201
+ },
202
+ },
203
+ },
187
204
  {
188
205
  method: "GET",
189
206
  path: "history",
@@ -399,6 +416,32 @@ export const AGENT_TOOLS = [
399
416
  },
400
417
  },
401
418
  },
419
+ {
420
+ method: "POST",
421
+ path: "tasks/{task}/attachments",
422
+ upload: true,
423
+ definition: {
424
+ name: "add_attachment",
425
+ description: "Attach a local file to a task of your space: a screenshot you took during a test, an export or a report you generated. Give the absolute path of the file on the machine where you run: this MCP server reads it and uploads it to the site itself, so its content never goes through you. Any format, up to 20 MB. To show it to the members, pass comment (a comment posted with the file shown in it: an image as a thumbnail, another file by its name) or append_to_description (the same reference added at the end of the description). Members see the file among the attachments of the task and can undo the upload with the rest of the batch.",
426
+ inputSchema: {
427
+ type: "object",
428
+ properties: {
429
+ request_id: REQUEST_ID,
430
+ task: TASK_REF,
431
+ path: { type: "string", description: "Absolute path of a regular file on the machine where you run (e.g. C:\\Users\\me\\capture.png or /tmp/report.pdf)." },
432
+ name: { type: "string", maxLength: 255, description: "File name shown to the members. Default: the name of the file." },
433
+ comment: {
434
+ type: "string",
435
+ maxLength: MAX_COMMENT_LENGTH,
436
+ description: "Text of a comment to post on the task, in the language of the space; the reference to the file is added after it. Omit for no comment.",
437
+ },
438
+ append_to_description: { type: "boolean", description: "Add the reference to the file at the end of the task description. Default: false." },
439
+ },
440
+ required: ["task", "path"],
441
+ additionalProperties: false,
442
+ },
443
+ },
444
+ },
402
445
  {
403
446
  method: "POST",
404
447
  path: "ideas",
@@ -642,6 +685,14 @@ export function toolHttpRequest(tool, args) {
642
685
  delete rest[name];
643
686
  return encodeURIComponent(value.trim());
644
687
  });
688
+ if (tool.upload) {
689
+ const { path: filePath, name, ...fields } = rest;
690
+ if (typeof filePath !== "string" || filePath.trim() === "")
691
+ throw new ToolArgumentError("Invalid arguments — path: expected the absolute path of a file. Check the tool's input schema.");
692
+ if (name !== undefined && (typeof name !== "string" || name.trim() === ""))
693
+ throw new ToolArgumentError("Invalid arguments — name: expected a non-empty string. Check the tool's input schema.");
694
+ return { method: tool.method, path, query: {}, body: fields, file: { path: filePath.trim(), ...(name === undefined ? {} : { name: name }) } };
695
+ }
645
696
  if (tool.method !== "GET")
646
697
  return { method: tool.method, path, query: {}, body: rest };
647
698
  const query = {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Fichier local envoyé par l'agent comme pièce jointe : le mode MCP le lit
3
+ * sur la machine où il tourne, avec les droits de l'utilisateur qui l'a
4
+ * lancé, et l'envoie au site. Son contenu ne passe jamais par l'agent.
5
+ */
6
+ /** Fichier local lu pour l'envoi. */
7
+ export interface LocalUpload {
8
+ filename: string;
9
+ mime: string;
10
+ content: Buffer;
11
+ }
12
+ /** Fichier local refusé : chemin relatif, introuvable, dossier, fichier spécial ou trop lourd. */
13
+ export declare class LocalFileError extends Error {
14
+ constructor(message: string);
15
+ }
16
+ /** Type MIME d'un fichier d'après son extension ; `application/octet-stream` pour une extension inconnue. */
17
+ export declare function mimeOfFilename(filename: string): string;
18
+ /**
19
+ * Lit le fichier régulier désigné par le chemin absolu `filePath` ; `name`
20
+ * remplace son nom. Un lien symbolique est suivi jusqu'au fichier qu'il désigne.
21
+ */
22
+ export declare function readLocalUpload(filePath: string, name?: string): Promise<LocalUpload>;
@@ -0,0 +1,79 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { DOCUMENT_FORMATS } from "../../shared/logic/documents.js";
4
+ import { MAX_ATTACHMENT_BYTES } from "../../shared/schemas/tasks-api.schema.js";
5
+ /** Fichier local refusé : chemin relatif, introuvable, dossier, fichier spécial ou trop lourd. */
6
+ export class LocalFileError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "LocalFileError";
10
+ }
11
+ }
12
+ /** Types MIME reconnus à l'extension, en plus de ceux des documents d'espace. */
13
+ const EXTRA_TYPES = {
14
+ html: "text/html",
15
+ htm: "text/html",
16
+ zip: "application/zip",
17
+ svg: "image/svg+xml",
18
+ bmp: "image/bmp",
19
+ tif: "image/tiff",
20
+ tiff: "image/tiff",
21
+ heic: "image/heic",
22
+ mp4: "video/mp4",
23
+ webm: "video/webm",
24
+ mp3: "audio/mpeg",
25
+ wav: "audio/wav",
26
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
27
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
28
+ };
29
+ /** Type MIME d'un fichier d'après son extension ; `application/octet-stream` pour une extension inconnue. */
30
+ export function mimeOfFilename(filename) {
31
+ const match = /\.([^.]+)$/.exec(filename);
32
+ if (!match)
33
+ return "application/octet-stream";
34
+ const extension = match[1].toLowerCase();
35
+ return DOCUMENT_FORMATS.find((format) => format.extensions.includes(extension))?.mime ?? EXTRA_TYPES[extension] ?? "application/octet-stream";
36
+ }
37
+ function megabytes(bytes) {
38
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
39
+ }
40
+ /**
41
+ * Lit le fichier régulier désigné par le chemin absolu `filePath` ; `name`
42
+ * remplace son nom. Un lien symbolique est suivi jusqu'au fichier qu'il désigne.
43
+ */
44
+ export async function readLocalUpload(filePath, name) {
45
+ if (!path.isAbsolute(filePath))
46
+ throw new LocalFileError(`path must be an absolute path on the machine where the agent runs (got "${filePath}").`);
47
+ let stat;
48
+ try {
49
+ stat = await fs.stat(filePath);
50
+ }
51
+ catch (err) {
52
+ if (err?.code === "ENOENT" || err?.code === "ENOTDIR")
53
+ throw new LocalFileError(`No file at ${filePath}: check the path.`);
54
+ if (err?.code === "EACCES" || err?.code === "EPERM")
55
+ throw new LocalFileError(`The file ${filePath} cannot be read: permission denied.`);
56
+ throw new LocalFileError(`The file ${filePath} cannot be read (${err?.message ?? err}).`);
57
+ }
58
+ if (stat.isDirectory())
59
+ throw new LocalFileError(`${filePath} is a directory: give the path of a file.`);
60
+ if (!stat.isFile())
61
+ throw new LocalFileError(`${filePath} is not a regular file: only regular files can be attached.`);
62
+ if (stat.size > MAX_ATTACHMENT_BYTES) {
63
+ throw new LocalFileError(`The file ${filePath} is too large (${megabytes(stat.size)}): an attachment cannot exceed ${megabytes(MAX_ATTACHMENT_BYTES)}.`);
64
+ }
65
+ let content;
66
+ try {
67
+ content = await fs.readFile(filePath);
68
+ }
69
+ catch (err) {
70
+ throw new LocalFileError(`The file ${filePath} cannot be read (${err?.message ?? err}).`);
71
+ }
72
+ if (content.length > MAX_ATTACHMENT_BYTES) {
73
+ throw new LocalFileError(`The file ${filePath} is too large (${megabytes(content.length)}): an attachment cannot exceed ${megabytes(MAX_ATTACHMENT_BYTES)}.`);
74
+ }
75
+ const filename = (name ?? path.basename(filePath)).trim();
76
+ if (filename === "")
77
+ throw new LocalFileError("name must not be empty.");
78
+ return { filename, mime: mimeOfFilename(path.basename(filePath)), content };
79
+ }
@@ -105,6 +105,34 @@ async function readUploadBody(c) {
105
105
  const mime = file.type.split(";")[0].trim() || "application/octet-stream";
106
106
  return { body: { filename: file.name || "fichier", mime, contentBase64: content.toString("base64") } };
107
107
  }
108
+ /**
109
+ * Formulaire multipart d'un envoi de fichier par l'agent : le fichier (champ
110
+ * `file`) passe en octets, `{ filename, mime, content }`, à côté des autres
111
+ * champs, gardés en texte. Messages en anglais, pour l'agent.
112
+ */
113
+ async function readAgentUpload(c) {
114
+ let form;
115
+ try {
116
+ form = await c.req.formData();
117
+ }
118
+ catch (err) {
119
+ return { response: c.json({ error: `The multipart form cannot be read: ${err?.message ?? err}` }, 400) };
120
+ }
121
+ const body = {};
122
+ for (const [name, value] of form.entries()) {
123
+ if (name !== "file" && typeof value === "string")
124
+ body[name] = value;
125
+ }
126
+ const file = form.get("file");
127
+ if (!(file instanceof File))
128
+ return { response: c.json({ error: "The form holds no file (field \"file\")." }, 400) };
129
+ if (file.size > MAX_ATTACHMENT_BYTES) {
130
+ return { response: c.json({ error: `The file is too large (${(file.size / (1024 * 1024)).toFixed(1)} MB): an attachment cannot exceed ${MAX_ATTACHMENT_BYTES / (1024 * 1024)} MB.` }, 413) };
131
+ }
132
+ const mime = file.type.split(";")[0].trim() || "application/octet-stream";
133
+ body.file = { filename: file.name || "file", mime, content: Buffer.from(await file.arrayBuffer()) };
134
+ return { body };
135
+ }
108
136
  /** Corps d'une requête de modification : JSON, ou formulaire multipart d'un fichier ; `undefined` sans corps. */
109
137
  async function readRequestBody(c) {
110
138
  if (c.req.method === "GET" || c.req.method === "HEAD")
@@ -194,10 +222,16 @@ export function createSiteApp(deps) {
194
222
  maxSize: MAX_BODY_BYTES,
195
223
  onError: (c) => c.json({ error: `Requête trop volumineuse : ${megabytes(MAX_BODY_BYTES)} au plus.` }, 413),
196
224
  }));
197
- // API des agents : jeton de l'en-tête Authorization, corps JSON ; les cookies sont ignorés.
225
+ // API des agents : jeton de l'en-tête Authorization, corps JSON ou formulaire multipart d'un fichier ; les cookies sont ignorés.
198
226
  const agentApi = async (c) => {
199
227
  let body = undefined;
200
- if (c.req.method !== "GET" && c.req.method !== "HEAD") {
228
+ if ((c.req.header("content-type") ?? "").toLowerCase().startsWith("multipart/form-data")) {
229
+ const read = await readAgentUpload(c);
230
+ if ("response" in read)
231
+ return read.response;
232
+ body = read.body;
233
+ }
234
+ else if (c.req.method !== "GET" && c.req.method !== "HEAD") {
201
235
  const text = await c.req.text();
202
236
  if (text.trim() !== "") {
203
237
  try {
@@ -209,7 +243,7 @@ export function createSiteApp(deps) {
209
243
  }
210
244
  }
211
245
  try {
212
- const response = handleAgentRequest({ store: api.store, attachments: api.attachments, now: api.now }, { method: c.req.method, path: c.req.path.slice(AGENT_API_PREFIX.length) || "/", query: c.req.query(), body, bearer: bearerToken(c) });
246
+ const response = await handleAgentRequest({ store: api.store, attachments: api.attachments, now: api.now }, { method: c.req.method, path: c.req.path.slice(AGENT_API_PREFIX.length) || "/", query: c.req.query(), body, bearer: bearerToken(c) });
213
247
  return c.json(response);
214
248
  }
215
249
  catch (err) {
@@ -227,7 +261,7 @@ export function createSiteApp(deps) {
227
261
  c.header("WWW-Authenticate", 'Bearer realm="mcp-organizer"');
228
262
  return c.json({ error: err?.message ?? String(err) }, HTTP_STATUS_BY_ERROR_KIND[kind]);
229
263
  }
230
- // Attente longue des demandes : seule route asynchrone de l'API des agents.
264
+ // Attente longue des demandes : hors du routeur, elle suit l'abandon de la requête par le client.
231
265
  app.get(`${AGENT_API_PREFIX}/requests/wait`, async (c) => {
232
266
  try {
233
267
  const response = await waitForPendingRequests({ store: api.store, attachments: api.attachments, now: api.now }, { method: "GET", path: "/requests/wait", query: c.req.query(), bearer: bearerToken(c) }, c.req.raw.signal);