@imenam/mcp-organizer 1.0.2 → 1.0.3

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.
@@ -742,7 +742,11 @@ export declare const AgentWatcherSchema: z.ZodObject<{
742
742
  since: z.ZodNullable<z.ZodISODateTime>;
743
743
  lastSeen: z.ZodNullable<z.ZodISODateTime>;
744
744
  }, z.core.$strip>;
745
- /** `GET notifications` : jeton et espace de l'agent, demandes en attente et veilleur du jeton. */
745
+ /**
746
+ * `GET notifications` : jeton et espace de l'agent, demandes en attente,
747
+ * veilleur du jeton et curseur de départ d'une veille (`since` de la
748
+ * première attente : seules les demandes passées en attente ensuite sont rendues).
749
+ */
746
750
  export declare const NotificationsDataSchema: z.ZodObject<{
747
751
  token: z.ZodObject<{
748
752
  id: z.ZodString;
@@ -763,6 +767,7 @@ export declare const NotificationsDataSchema: z.ZodObject<{
763
767
  since: z.ZodNullable<z.ZodISODateTime>;
764
768
  lastSeen: z.ZodNullable<z.ZodISODateTime>;
765
769
  }, z.core.$strip>;
770
+ cursor: z.ZodISODateTime;
766
771
  }, z.core.$strip>;
767
772
  /**
768
773
  * `GET requests/wait` : demandes passées en attente (vide à l'expiration) et
@@ -179,12 +179,17 @@ export const IdeaDataSchema = z.object({ idea: AgentIdeaSchema });
179
179
  export const PromoteIdeaDataSchema = z.object({ idea: AgentIdeaSchema, task: AgentTaskSummarySchema });
180
180
  /** Présence d'un veilleur de notifications pour le jeton. */
181
181
  export const AgentWatcherSchema = z.object({ armed: z.boolean(), since: TimestampSchema.nullable(), lastSeen: TimestampSchema.nullable() });
182
- /** `GET notifications` : jeton et espace de l'agent, demandes en attente et veilleur du jeton. */
182
+ /**
183
+ * `GET notifications` : jeton et espace de l'agent, demandes en attente,
184
+ * veilleur du jeton et curseur de départ d'une veille (`since` de la
185
+ * première attente : seules les demandes passées en attente ensuite sont rendues).
186
+ */
183
187
  export const NotificationsDataSchema = z.object({
184
188
  token: z.object({ id: IdSchema, name: z.string() }),
185
189
  space: AgentSpaceSchema,
186
190
  pendingCount: z.number().int().min(0),
187
191
  watcher: AgentWatcherSchema,
192
+ cursor: TimestampSchema,
188
193
  });
189
194
  /**
190
195
  * `GET requests/wait` : demandes passées en attente (vide à l'expiration) et
@@ -21,6 +21,7 @@ export const notificationRoutes = [
21
21
  space: spaceData(agent.space),
22
22
  pendingCount,
23
23
  watcher,
24
+ cursor: new Date().toISOString(),
24
25
  });
25
26
  },
26
27
  },
@@ -1,4 +1 @@
1
- import { type AgentRequestSummary } from "../../shared/schemas/agent-tools.schema.js";
2
- /** Ligne d'une demande : une seule ligne, lisible telle quelle dans la notification. */
3
- export declare function formatRequestEvent(request: AgentRequestSummary): string;
4
1
  export declare function runWatchMode(tokenId: string | undefined): Promise<number>;
@@ -1,6 +1,7 @@
1
1
  import { MAX_WAIT_SECONDS } from "../../shared/schemas/agent-tools.schema.js";
2
2
  import { ConfigError } from "../core/errors.js";
3
3
  import { OrganizerSiteClient, SiteError } from "../mcp/client.js";
4
+ import { formatRequestEvent } from "../mcp/notifications.js";
4
5
  import { readHandoff } from "../mcp/watch-handoff.js";
5
6
  /**
6
7
  * Mode veilleur (`--watch <identifiant du jeton>`).
@@ -15,15 +16,6 @@ import { readHandoff } from "../mcp/watch-handoff.js";
15
16
  */
16
17
  const BACKOFF_MIN_MS = 1_000;
17
18
  const BACKOFF_MAX_MS = 30_000;
18
- /** Longueur maximale de l'extrait du texte de la demande. */
19
- const EXCERPT_LENGTH = 120;
20
- /** Ligne d'une demande : une seule ligne, lisible telle quelle dans la notification. */
21
- export function formatRequestEvent(request) {
22
- const text = request.text.replace(/\s+/g, " ").trim();
23
- const excerpt = text.length > EXCERPT_LENGTH ? `${text.slice(0, EXCERPT_LENGTH - 1)}…` : text;
24
- const context = request.contextTask ? ` · ${request.contextTask.key}` : "";
25
- return `[organizer] ${request.kind} · ${request.author.name} — "${excerpt}"${context} (${request.id})`;
26
- }
27
19
  /** Refus définitif du site : un nouvel essai donnerait la même réponse. */
28
20
  function isRefusal(error) {
29
21
  return error instanceof SiteError && error.status !== undefined && error.status >= 400 && error.status < 500 && error.status !== 408 && error.status !== 429;
@@ -1,13 +1,30 @@
1
+ import { type AgentRequestSummary } from "../../shared/schemas/agent-tools.schema.js";
1
2
  import type { OrganizerSiteClient, SiteConnection } from "./client.js";
2
- import type { ToolDefinition } from "./tools.js";
3
+ import { type ToolDefinition } from "./tools.js";
3
4
  /**
4
- * Outil `enable_notifications`, exécuté par le mode MCP lui-même : il lit le
5
- * jeton, l'espace et l'état du veilleur sur le site, dépose le relais du
6
- * veilleur et rend l'appel `Monitor` que l'agent doit faire.
5
+ * Outils de notification, exécutés par le mode MCP lui-même.
6
+ *
7
+ * `enable_notifications` fonctionne de deux façons. En local, il dépose le
8
+ * relais du veilleur et rend l'appel `Monitor` qui lance `--watch`. Derrière
9
+ * le relais de mcp-http-gateway, qui remplit l'argument réservé
10
+ * `_gateway_watch`, il rend une spécification de veille
11
+ * (`_meta["gateway/watch"]`) : le relais lance alors son propre veilleur, qui
12
+ * appelle `wait_for_requests` en boucle à travers la gateway.
7
13
  */
14
+ /** Clés de la convention de veille de mcp-http-gateway (voir son gateway-watch.js). */
15
+ export declare const WATCH_ARG = "_gateway_watch";
16
+ /** Résultat d'un outil de notification : texte pour l'agent et métadonnées pour le relais. */
17
+ export interface NotificationToolResult {
18
+ text: string;
19
+ meta?: Record<string, unknown>;
20
+ }
21
+ /** Ligne d'une demande : une seule ligne, lisible telle quelle dans la notification. */
22
+ export declare function formatRequestEvent(request: AgentRequestSummary): string;
8
23
  /** Durée maximale d'un `Monitor` côté hôte. */
9
24
  export declare const MONITOR_TIMEOUT_MS = 1800000;
10
25
  export declare const ENABLE_NOTIFICATIONS_TOOL: ToolDefinition;
26
+ export declare const WAIT_FOR_REQUESTS_TOOL: ToolDefinition;
11
27
  /** Commande du veilleur du jeton `tokenId`. */
12
28
  export declare function watchCommand(tokenId: string): string;
13
- export declare function enableNotifications(client: OrganizerSiteClient, connection: SiteConnection): Promise<string>;
29
+ export declare function enableNotifications(client: OrganizerSiteClient, connection: SiteConnection, args: Record<string, unknown>): Promise<NotificationToolResult>;
30
+ export declare function waitForRequests(client: OrganizerSiteClient, args: Record<string, unknown>): Promise<NotificationToolResult>;
@@ -1,35 +1,100 @@
1
- import { NotificationsDataSchema } from "../../shared/schemas/agent-tools.schema.js";
1
+ import { MAX_WAIT_SECONDS, NotificationsDataSchema } from "../../shared/schemas/agent-tools.schema.js";
2
+ import { ToolArgumentError } from "./tools.js";
2
3
  import { writeHandoff } from "./watch-handoff.js";
3
4
  /**
4
- * Outil `enable_notifications`, exécuté par le mode MCP lui-même : il lit le
5
- * jeton, l'espace et l'état du veilleur sur le site, dépose le relais du
6
- * veilleur et rend l'appel `Monitor` que l'agent doit faire.
5
+ * Outils de notification, exécutés par le mode MCP lui-même.
6
+ *
7
+ * `enable_notifications` fonctionne de deux façons. En local, il dépose le
8
+ * relais du veilleur et rend l'appel `Monitor` qui lance `--watch`. Derrière
9
+ * le relais de mcp-http-gateway, qui remplit l'argument réservé
10
+ * `_gateway_watch`, il rend une spécification de veille
11
+ * (`_meta["gateway/watch"]`) : le relais lance alors son propre veilleur, qui
12
+ * appelle `wait_for_requests` en boucle à travers la gateway.
7
13
  */
14
+ /** Clés de la convention de veille de mcp-http-gateway (voir son gateway-watch.js). */
15
+ export const WATCH_ARG = "_gateway_watch";
16
+ const WATCH_META = "gateway/watch";
17
+ const EVENTS_META = "gateway/events";
18
+ /** Longueur maximale de l'extrait du texte d'une demande dans sa ligne. */
19
+ const EXCERPT_LENGTH = 120;
20
+ /** Ligne d'une demande : une seule ligne, lisible telle quelle dans la notification. */
21
+ export function formatRequestEvent(request) {
22
+ const text = request.text.replace(/\s+/g, " ").trim();
23
+ const excerpt = text.length > EXCERPT_LENGTH ? `${text.slice(0, EXCERPT_LENGTH - 1)}…` : text;
24
+ const context = request.contextTask ? ` · ${request.contextTask.key}` : "";
25
+ return `[organizer] ${request.kind} · ${request.author.name} — "${excerpt}"${context} (${request.id})`;
26
+ }
8
27
  /** Durée maximale d'un `Monitor` côté hôte. */
9
28
  export const MONITOR_TIMEOUT_MS = 1_800_000;
10
29
  const PACKAGE_NAME = "@imenam/mcp-organizer";
11
30
  export const ENABLE_NOTIFICATIONS_TOOL = {
12
31
  name: "enable_notifications",
13
32
  description: "Get notified in real time of the requests the members of your space send to the AI, without polling the queue. Returns immediately: it blocks nothing and starts nothing on its own. It hands you the exact Monitor call to make right after — arming that watcher is what actually delivers notifications, and until you do it no request will reach you. Call this once at the start of a session; then keep working, each new pending request interrupts you on its own. The host stops the watcher after 30 minutes at most: re-arm it with the same Monitor call each time it expires.",
14
- inputSchema: { type: "object", properties: {}, additionalProperties: false },
33
+ inputSchema: {
34
+ type: "object",
35
+ properties: {
36
+ [WATCH_ARG]: {
37
+ type: "object",
38
+ description: "Filled in by the mcp-http-gateway relay, never by the agent: the relay will run the watcher and needs a watch specification instead of a local command.",
39
+ },
40
+ },
41
+ additionalProperties: false,
42
+ },
43
+ };
44
+ export const WAIT_FOR_REQUESTS_TOOL = {
45
+ name: "wait_for_requests",
46
+ description: "Block until at least one request of your space becomes pending (created, or released by a member), or until the timeout. Returns the new pending requests (none on timeout) and a cursor: pass it to the next call to get exactly what became pending since. It is the waiting tool of the notification watcher; to stay reachable, prefer enable_notifications.",
47
+ inputSchema: {
48
+ type: "object",
49
+ properties: {
50
+ cursor: {
51
+ type: "string",
52
+ description: "Cursor returned by the previous call. Without it, only requests that become pending after the call starts are returned.",
53
+ },
54
+ timeout_seconds: { type: "integer", minimum: 1, maximum: MAX_WAIT_SECONDS, description: `Maximum wait, in seconds (1-${MAX_WAIT_SECONDS}, defaults to 30).` },
55
+ watcher: {
56
+ type: "boolean",
57
+ description: "Set by the notification watcher: the wait counts as the presence of this token's watcher, shown as listening in the web app.",
58
+ },
59
+ },
60
+ additionalProperties: false,
61
+ },
15
62
  };
16
63
  /** Commande du veilleur du jeton `tokenId`. */
17
64
  export function watchCommand(tokenId) {
18
65
  return `npx -y ${PACKAGE_NAME} --watch ${tokenId}`;
19
66
  }
20
- export async function enableNotifications(client, connection) {
67
+ export async function enableNotifications(client, connection, args) {
68
+ for (const name of Object.keys(args)) {
69
+ if (name !== WATCH_ARG)
70
+ throw new ToolArgumentError(`Invalid arguments — ${name}: enable_notifications takes no argument.`);
71
+ }
21
72
  const envelope = await client.envelope({ method: "GET", path: "notifications", query: {}, body: undefined });
22
- const { token, space, pendingCount, watcher } = client.parseData(NotificationsDataSchema, envelope.data);
73
+ const { token, space, pendingCount, watcher, cursor } = client.parseData(NotificationsDataSchema, envelope.data);
74
+ if (args[WATCH_ARG] !== undefined) {
75
+ return {
76
+ text: `Watch specification for the mcp-http-gateway relay: requests of space "${space.name}" for token "${token.name}".`,
77
+ meta: {
78
+ [WATCH_META]: {
79
+ tool: WAIT_FOR_REQUESTS_TOOL.name,
80
+ arguments: { watcher: true },
81
+ cursor,
82
+ description: "New requests for the AI in the organizer",
83
+ },
84
+ },
85
+ };
86
+ }
23
87
  writeHandoff({ tokenId: token.id, url: connection.url, token: connection.token });
24
88
  const command = watchCommand(token.id);
25
89
  if (watcher.armed) {
26
- return [
90
+ const text = [
27
91
  `Notifications are already live for token "${token.name}" on space "${space.name}" (watcher armed since ${watcher.since}).`,
28
92
  "Nothing to do: keep working, new requests will interrupt you on their own.",
29
93
  "Do not arm a second watcher — you would get every request twice.",
30
94
  "Only exception: if the host just told you your watcher expired or stopped, re-arm it",
31
95
  `with the same Monitor call (command \`${command}\`, timeout_ms ${MONITOR_TIMEOUT_MS}).`,
32
96
  ].join("\n");
97
+ return { text };
33
98
  }
34
99
  const lines = [
35
100
  `Notifications enabled for token "${token.name}" on space "${space.name}".`,
@@ -50,5 +115,26 @@ export async function enableNotifications(client, connection) {
50
115
  if (pendingCount > 0) {
51
116
  lines.push("", `${pendingCount} request(s) are already pending. Only requests that become pending AFTER the`, "watcher starts are announced — process the backlog with list_requests.");
52
117
  }
53
- return lines.join("\n");
118
+ return { text: lines.join("\n") };
119
+ }
120
+ export async function waitForRequests(client, args) {
121
+ for (const name of Object.keys(args)) {
122
+ if (!(name in WAIT_FOR_REQUESTS_TOOL.inputSchema.properties))
123
+ throw new ToolArgumentError(`Invalid arguments — ${name}: unknown argument. Check the tool's input schema.`);
124
+ }
125
+ const { cursor, timeout_seconds: timeout, watcher } = args;
126
+ if (cursor !== undefined && typeof cursor !== "string")
127
+ throw new ToolArgumentError("Invalid arguments — cursor: expected the string returned by the previous call.");
128
+ if (timeout !== undefined && (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < 1 || timeout > MAX_WAIT_SECONDS)) {
129
+ throw new ToolArgumentError(`Invalid arguments — timeout_seconds: expected an integer from 1 to ${MAX_WAIT_SECONDS}.`);
130
+ }
131
+ if (watcher !== undefined && typeof watcher !== "boolean")
132
+ throw new ToolArgumentError("Invalid arguments — watcher: expected a boolean.");
133
+ const seconds = timeout ?? 30;
134
+ const result = await client.waitForRequests({ timeout_seconds: seconds, since: cursor, watcher: watcher === true });
135
+ const lines = result.requests.map(formatRequestEvent);
136
+ const text = lines.length === 0
137
+ ? `No new pending request in "${result.space.name}" after ${seconds}s. Cursor: ${result.cursor}`
138
+ : `${lines.length} new pending request(s) in "${result.space.name}":\n${lines.join("\n")}\nCursor: ${result.cursor}\n\nNext: call claim_request with the id of the oldest request.`;
139
+ return { text, meta: { [EVENTS_META]: { cursor: result.cursor, lines } } };
54
140
  }
@@ -1,6 +1,6 @@
1
1
  import { type SiteConnection } from "./client.js";
2
2
  /** Présentation du serveur transmise au client MCP : concepts et déroulé. */
3
- export declare const INSTRUCTIONS = "mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.\n\nYour token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.\n\nConcepts:\n- A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.\n- A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).\n- A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply) or failed (with the reason).\n- A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.\n- The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it.\n\nWork loop, when the user asks you to process the queue:\n1. list_requests to see the pending requests of your space.\n2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, task tree, members, recent ideas). get_context shows the space at any time.\n3. Read what you need with get_task and search_tasks.\n4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea \u2014 always passing the request_id. Each write is one undoable action of the batch.\n5. complete_request with a short reply in the author's language (or fail_request with the reason), then go back to step 1 until no request is pending.\nWhen the queue is empty, tell the user.\n\nNotifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor. Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line \"notifications stopped\" means the site refused the token: tell the user.\n\nHow to handle each kind of request:\n- **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.\n- **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.\n- **remark** and **message**: do whatever is useful \u2014 answer, update or create tasks, comment \u2014 and say what you did in the reply.\n- **idea_promotion**: turn the context idea into a well-formed task with promote_idea.\n\nRules: write titles, descriptions and replies in the language of the users; keep the reply short and factual. Errors tell you what to do next; an error about the token (missing, revoked, expired, owner no longer a member) cannot be fixed by retrying: tell the user.";
3
+ export declare const INSTRUCTIONS = "mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.\n\nYour token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.\n\nConcepts:\n- A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.\n- A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).\n- A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply) or failed (with the reason).\n- A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.\n- The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it.\n\nWork loop, when the user asks you to process the queue:\n1. list_requests to see the pending requests of your space.\n2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, task tree, members, recent ideas). get_context shows the space at any time.\n3. Read what you need with get_task and search_tasks.\n4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea \u2014 always passing the request_id. Each write is one undoable action of the batch.\n5. complete_request with a short reply in the author's language (or fail_request with the reason), then go back to step 1 until no request is pending.\nWhen the queue is empty, tell the user.\n\nNotifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor, whatever the command (behind mcp-http-gateway, the gateway relay answers in place of this server and gives its own watcher command). Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line \"notifications stopped\" means the site refused the token, and a line \"[gateway-watch] \u2026 la veille \u00E9choue\" means the gateway watcher keeps failing: tell the user. wait_for_requests is the waiting tool of the watcher: you do not need to call it.\n\nHow to handle each kind of request:\n- **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.\n- **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.\n- **remark** and **message**: do whatever is useful \u2014 answer, update or create tasks, comment \u2014 and say what you did in the reply.\n- **idea_promotion**: turn the context idea into a well-formed task with promote_idea.\n\nRules: write titles, descriptions and replies in the language of the users; keep the reply short and factual. Errors tell you what to do next; an error about the token (missing, revoked, expired, owner no longer a member) cannot be fixed by retrying: tell the user.";
4
4
  /**
5
5
  * Connexion au site d'après `ORGANIZER_URL` et `ORGANIZER_TOKEN` ; une valeur
6
6
  * absente ou invalide, ou une URL http vers une autre machine, est une `ConfigError`.
@@ -6,36 +6,36 @@ import { createLogger, setupLogging } from "../core/logger.js";
6
6
  import { ConfigError } from "../core/errors.js";
7
7
  import { OrganizerSiteClient, SiteError } from "./client.js";
8
8
  import { AGENT_TOOLS, ToolArgumentError, findAgentTool, toolHttpRequest } from "./tools.js";
9
- import { ENABLE_NOTIFICATIONS_TOOL, enableNotifications } from "./notifications.js";
9
+ import { ENABLE_NOTIFICATIONS_TOOL, WAIT_FOR_REQUESTS_TOOL, enableNotifications, waitForRequests } from "./notifications.js";
10
10
  import { removeOwnHandoffs } from "./watch-handoff.js";
11
11
  /** Présentation du serveur transmise au client MCP : concepts et déroulé. */
12
- export const INSTRUCTIONS = `mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.
13
-
14
- Your token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.
15
-
16
- Concepts:
17
- - A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.
18
- - A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).
19
- - A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply) or failed (with the reason).
20
- - A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.
21
- - The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it.
22
-
23
- Work loop, when the user asks you to process the queue:
24
- 1. list_requests to see the pending requests of your space.
25
- 2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, task tree, members, recent ideas). get_context shows the space at any time.
26
- 3. Read what you need with get_task and search_tasks.
27
- 4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea — always passing the request_id. Each write is one undoable action of the batch.
28
- 5. complete_request with a short reply in the author's language (or fail_request with the reason), then go back to step 1 until no request is pending.
29
- When the queue is empty, tell the user.
30
-
31
- Notifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor. Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line "notifications stopped" means the site refused the token: tell the user.
32
-
33
- How to handle each kind of request:
34
- - **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.
35
- - **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.
36
- - **remark** and **message**: do whatever is useful — answer, update or create tasks, comment — and say what you did in the reply.
37
- - **idea_promotion**: turn the context idea into a well-formed task with promote_idea.
38
-
12
+ export const INSTRUCTIONS = `mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.
13
+
14
+ Your token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.
15
+
16
+ Concepts:
17
+ - A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.
18
+ - A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).
19
+ - A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply) or failed (with the reason).
20
+ - A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.
21
+ - The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it.
22
+
23
+ Work loop, when the user asks you to process the queue:
24
+ 1. list_requests to see the pending requests of your space.
25
+ 2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, task tree, members, recent ideas). get_context shows the space at any time.
26
+ 3. Read what you need with get_task and search_tasks.
27
+ 4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea — always passing the request_id. Each write is one undoable action of the batch.
28
+ 5. complete_request with a short reply in the author's language (or fail_request with the reason), then go back to step 1 until no request is pending.
29
+ When the queue is empty, tell the user.
30
+
31
+ Notifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor, whatever the command (behind mcp-http-gateway, the gateway relay answers in place of this server and gives its own watcher command). Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line "notifications stopped" means the site refused the token, and a line "[gateway-watch] … la veille échoue" means the gateway watcher keeps failing: tell the user. wait_for_requests is the waiting tool of the watcher: you do not need to call it.
32
+
33
+ How to handle each kind of request:
34
+ - **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.
35
+ - **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.
36
+ - **remark** and **message**: do whatever is useful — answer, update or create tasks, comment — and say what you did in the reply.
37
+ - **idea_promotion**: turn the context idea into a well-formed task with promote_idea.
38
+
39
39
  Rules: write titles, descriptions and replies in the language of the users; keep the reply short and factual. Errors tell you what to do next; an error about the token (missing, revoked, expired, owner no longer a member) cannot be fixed by retrying: tell the user.`;
40
40
  /** Hôtes de la machine locale, seuls admis en http. */
41
41
  const LOCAL_HOSTNAMES = new Set(["localhost", "127.0.0.1", "[::1]"]);
@@ -84,15 +84,22 @@ export async function runMcpMode() {
84
84
  const logger = createLogger("mcp");
85
85
  const client = new OrganizerSiteClient(connection);
86
86
  const server = new Server({ name: "mcp-organizer", version: APP_VERSION }, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
87
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...AGENT_TOOLS.map((tool) => tool.definition), ENABLE_NOTIFICATIONS_TOOL] }));
87
+ // Outils exécutés par le mode MCP lui-même : leur résultat peut porter des métadonnées pour le relais de mcp-http-gateway.
88
+ const notificationTools = {
89
+ [ENABLE_NOTIFICATIONS_TOOL.name]: (args) => enableNotifications(client, connection, args),
90
+ [WAIT_FOR_REQUESTS_TOOL.name]: (args) => waitForRequests(client, args),
91
+ };
92
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...AGENT_TOOLS.map((tool) => tool.definition), ENABLE_NOTIFICATIONS_TOOL, WAIT_FOR_REQUESTS_TOOL] }));
88
93
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
89
94
  const { name, arguments: args } = request.params;
90
- if (name === ENABLE_NOTIFICATIONS_TOOL.name) {
95
+ const notificationTool = notificationTools[name];
96
+ if (notificationTool) {
91
97
  try {
92
- return { content: [{ type: "text", text: await enableNotifications(client, connection) }] };
98
+ const result = await notificationTool((args ?? {}));
99
+ return { content: [{ type: "text", text: result.text }], ...(result.meta ? { _meta: result.meta } : {}) };
93
100
  }
94
101
  catch (error) {
95
- if (!(error instanceof SiteError))
102
+ if (!(error instanceof SiteError) && !(error instanceof ToolArgumentError))
96
103
  logger.error(`Tool ${name} failed: ${error?.stack ?? error}`);
97
104
  return errorResult(error?.message ?? String(error));
98
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imenam/mcp-organizer",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "MCP server with a multi-user web GUI to organize tasks in personal and shared spaces; requests to the AI are queued and processed by the connected agent, every agent action is logged and undoable.",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {