@workel/mcp 0.1.0 → 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/server.js CHANGED
@@ -15,10 +15,21 @@
15
15
  * task) for where a transport gets chosen and attached.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WORKSPACE_ARG = void 0;
18
19
  exports.buildServer = buildServer;
20
+ exports.buildWorkspaceServer = buildWorkspaceServer;
19
21
  const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
22
+ const zod_1 = require("zod");
23
+ const workspaces_1 = require("./workspaces");
24
+ const redact_1 = require("./api/redact");
25
+ const version_1 = require("./version");
20
26
  const SERVER_NAME = 'workel';
21
- const SERVER_VERSION = '0.1.0';
27
+ /**
28
+ * Read from package.json via ./version rather than duplicated as a literal:
29
+ * `serverInfo.version` is what every connected host reports for this server,
30
+ * so a stale literal silently misidentifies the build during an incident.
31
+ */
32
+ const SERVER_VERSION = version_1.VERSION;
22
33
  function isPermitted(descriptor, caps) {
23
34
  return descriptor.scope === undefined || caps.scopes.includes(descriptor.scope);
24
35
  }
@@ -37,22 +48,103 @@ function isPermitted(descriptor, caps) {
37
48
  function toSdkToolResult(result) {
38
49
  return result;
39
50
  }
51
+ /** The argument every tool gains when more than one workspace is configured. */
52
+ exports.WORKSPACE_ARG = 'workspace';
53
+ /**
54
+ * Builds the `workspace` argument's schema. An enum rather than a free string:
55
+ * the model sees the exact set of reachable workspaces in the tool definition
56
+ * and picks one, instead of guessing a name and learning it was wrong from an
57
+ * error. `resolve()` still validates, since a client may ignore the schema.
58
+ */
59
+ function workspaceArgSchema(labels) {
60
+ return zod_1.z
61
+ .enum(labels)
62
+ .describe('Which Workel workspace to act in. Each workspace is reached through its own API key, ' +
63
+ 'and they are fully isolated from one another — a task or project in one is never ' +
64
+ `visible from another. Available: ${labels.map((l) => `"${l}"`).join(', ')}.`);
65
+ }
40
66
  /**
41
67
  * `tools` defaults to an empty registry — a later task supplies the real
42
68
  * list of tool factories here.
69
+ *
70
+ * Single-workspace entry point, and the shape every existing caller and test
71
+ * uses. It delegates into the multi-workspace builder with a one-entry
72
+ * registry rather than duplicating the registration loop, so there is exactly
73
+ * one implementation of scope gating, schema construction and the redaction
74
+ * backstop — two loops would drift, and the security-relevant half is the one
75
+ * that would drift silently.
43
76
  */
44
77
  function buildServer(client, caps, tools = []) {
78
+ const registry = (0, workspaces_1.createWorkspaceRegistry)([
79
+ { id: 'default', name: 'default', keyName: 'default', scopes: caps.scopes, client },
80
+ ]);
81
+ return buildWorkspaceServer(registry, tools);
82
+ }
83
+ /**
84
+ * Registers one tool per NAME regardless of how many workspaces are
85
+ * configured, with the workspace as an argument.
86
+ *
87
+ * The alternative — one server process (or one registration) per workspace —
88
+ * multiplies the tool count by the workspace count, and every tool definition
89
+ * is context the model pays for on every turn. Here 9 tools stay 9 tools
90
+ * whether the user has one workspace or twelve.
91
+ *
92
+ * Each workspace keeps its OWN client, and therefore its own workspace-bound
93
+ * key: this multiplexes addressing, never authority. A request still carries
94
+ * exactly one key, and the API's tenancy check is unchanged.
95
+ */
96
+ function buildWorkspaceServer(registry, tools = []) {
45
97
  const server = new mcp_js_1.McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
46
98
  const registerTool = server.registerTool.bind(server);
47
99
  for (const factory of tools) {
48
- const descriptor = factory(client);
49
- if (!isPermitted(descriptor, caps))
100
+ // One descriptor per workspace: each closes over its own workspace's
101
+ // client, so dispatching is a map lookup rather than a client swap.
102
+ const byWorkspaceId = new Map(registry.entries.map((entry) => [entry.id, factory(entry.client)]));
103
+ const sample = byWorkspaceId.get(registry.entries[0].id);
104
+ // Register when ANY key can use it. A key that lacks the scope is refused
105
+ // per-call with a message naming the workspace — withholding the tool
106
+ // entirely would hide it from the workspaces that CAN use it.
107
+ if (!isPermitted(sample, { scopes: registry.unionScopes }))
50
108
  continue;
51
- registerTool(descriptor.name, {
52
- description: descriptor.description,
53
- inputSchema: descriptor.inputSchema,
54
- annotations: descriptor.annotations,
55
- }, async (args) => toSdkToolResult(await descriptor.handler(args)));
109
+ const inputSchema = registry.isSingle
110
+ ? sample.inputSchema
111
+ : { [exports.WORKSPACE_ARG]: workspaceArgSchema(registry.labels), ...sample.inputSchema };
112
+ registerTool(sample.name, {
113
+ description: sample.description,
114
+ inputSchema,
115
+ annotations: sample.annotations,
116
+ }, async (args) => {
117
+ try {
118
+ const { [exports.WORKSPACE_ARG]: requested, ...toolArgs } = args;
119
+ // Throws a message naming the valid workspaces, which the redaction
120
+ // backstop below turns into an error result the model can act on.
121
+ const entry = registry.resolve(typeof requested === 'string' ? requested : undefined);
122
+ // Scopes are per-key, so a tool registered off the union may still be
123
+ // unusable in THIS workspace. Refusing here — naming the workspace and
124
+ // the missing scope — beats a bare 403 that says neither.
125
+ if (sample.scope !== undefined && !entry.scopes.includes(sample.scope)) {
126
+ throw new Error(`The API key for workspace "${entry.label}" does not carry the "${sample.scope}" scope, ` +
127
+ `so ${sample.name} cannot be used there. Grant that scope to the key in ` +
128
+ 'Workel Settings → Developers, or target a workspace whose key already has it.');
129
+ }
130
+ const descriptor = byWorkspaceId.get(entry.id);
131
+ // `workspace` is this layer's addressing argument — the tools know
132
+ // nothing about it, so it never reaches their handlers.
133
+ return toSdkToolResult(await descriptor.handler(registry.isSingle ? args : toolArgs));
134
+ }
135
+ catch (err) {
136
+ /**
137
+ * The last line of defence before a throwable becomes model-visible
138
+ * text. Only WorkelApiError is redacted upstream (client.ts); anything
139
+ * else — notably undici embedding the whole Authorization header value
140
+ * in a TypeError for a header-illegal key — would otherwise reach the
141
+ * model verbatim, and from there the provider's logs and any exported
142
+ * transcript. Never remove without replacing the redaction.
143
+ */
144
+ const message = err instanceof Error ? err.message : String(err);
145
+ return { content: [{ type: 'text', text: (0, redact_1.redact)(message) }], isError: true };
146
+ }
147
+ });
56
148
  }
57
149
  return server;
58
150
  }
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot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AAC"}
@@ -16,7 +16,7 @@ const mapping_1 = require("../api/mapping");
16
16
  const output_1 = require("../output");
17
17
  const defineTool_1 = require("./defineTool");
18
18
  const conventions_1 = require("./conventions");
19
- const DESCRIPTION = "List the board columns of a project, in a project's saved display order. These columns are " +
19
+ const DESCRIPTION = "List the board columns of a project. The order returned is not the board's display order — sort by each column's `order` field to reconstruct it. These columns are " +
20
20
  'kanban lists, not tasks — a column such as "To Do" or "Done" holds tasks but is not one itself; ' +
21
21
  'use workel_list_tasks with the returned column id (a task\'s `column_id`) to see the tasks inside ' +
22
22
  'one. `is_done` marks a column whose tasks are treated as complete. A project id that is not ' +
@@ -1 +1 @@
1
- {"version":3,"file":"workel_project_columns.js","sourceRoot":"","sources":["../../src/tools/workel_project_columns.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,6BAAwB;AAExB,4CAA0D;AAC1D,sCAAyC;AACzC,6CAA4D;AAC5D,+CAAsG;AAEtG,MAAM,WAAW,GACf,6FAA6F;IAC7F,kGAAkG;IAClG,oGAAoG;IACpG,8FAA8F;IAC9F,+FAA+F;IAC/F,iGAAiG;IACjG,6CAA6C;IAC7C,oCAAsB,CAAC;AAElB,MAAM,wBAAwB,GAAgB,CAAC,MAAM,EAAE,EAAE,CAC9D,IAAA,uBAAU,EAAC;IACT,IAAI,EAAE,6BAA6B;IACnC,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE;QACX,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrB,KAAK,EAAE,yBAAW;QAClB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC9B;IACD,WAAW,EAAE,EAAE,GAAG,8BAAgB,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACnE,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACtB,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MA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MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAsD,CAAC;QACrF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAC7B,aAAa,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAC3C,EAAE,KAAK,EAAE,MAAM,EAAE,CAClB,CAAC;QACF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,kCAAwB,CAAC,CAAC;QAC7D,OAAO,IAAA,4BAAc,EAAC,IAAA,qBAAY,EAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3E,CAAC;CACF,CAAC,CAAC;AApBQ,QAAA,wBAAwB,4BAoBhC"}
@@ -3,7 +3,7 @@
3
3
  * scope, same scope as the task tools — comments are not their own scope
4
4
  * on this surface).
5
5
  *
6
- * Returns every comment on the task, oldest first, top-level and replies
6
+ * Returns every comment on the task, top-level and replies
7
7
  * alike — there is no threading filter. The parent task is resolved
8
8
  * through the same visible-project chain `workel_get_task` uses, so a
9
9
  * task outside it (or a genuinely nonexistent id) 404s before any comment
@@ -1 +1 @@
1
- {"version":3,"file":"workel_task_comments.d.ts","sourceRoot":"","sources":["../../src/tools/workel_task_comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAY5D,eAAO,MAAM,sBAAsB,EAAE,WAuBjC,CAAC"}
1
+ {"version":3,"file":"workel_task_comments.d.ts","sourceRoot":"","sources":["../../src/tools/workel_task_comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc5D,eAAO,MAAM,sBAAsB,EAAE,WAuBjC,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * scope, same scope as the task tools — comments are not their own scope
5
5
  * on this surface).
6
6
  *
7
- * Returns every comment on the task, oldest first, top-level and replies
7
+ * Returns every comment on the task, top-level and replies
8
8
  * alike — there is no threading filter. The parent task is resolved
9
9
  * through the same visible-project chain `workel_get_task` uses, so a
10
10
  * task outside it (or a genuinely nonexistent id) 404s before any comment
@@ -24,13 +24,15 @@ const mapping_1 = require("../api/mapping");
24
24
  const output_1 = require("../output");
25
25
  const defineTool_1 = require("./defineTool");
26
26
  const conventions_1 = require("./conventions");
27
- const DESCRIPTION = 'List every comment on a task, oldest first — top-level comments and replies together, with no ' +
28
- 'threading filter available. A task id that is not visible to this API key (its project is ' +
29
- 'archived, private, the inbox project, or in a different workspace, or the id is genuinely ' +
30
- "nonexistent) returns a not-found result either way. There is no tool to fetch a single comment " +
31
- 'on its own — this list is the only way to read a comment\'s body through this API. Paginated via ' +
32
- 'an opaque `cursor`; a `null` next_cursor means there are no more pages. ' +
33
- conventions_1.UNTRUSTED_CONTENT_NOTE;
27
+ const DESCRIPTION = 'List every comment on a task — top-level comments and replies together, with no threading '
28
+ + 'filter available. The order returned is NOT chronological: sort by each comment\'s '
29
+ + '`created_at` to find the newest — the last item on a page is not the latest comment. '
30
+ + 'A task id that is not visible to this API key (its project is archived, private, the inbox '
31
+ + 'project, or in a different workspace, or the id is genuinely nonexistent) returns a '
32
+ + 'not-found result either way. There is no tool to fetch a single comment on its own — this '
33
+ + "list is the only way to read a comment's body through this API. Paginated via an opaque "
34
+ + '`cursor`; a `null` next_cursor means there are no more pages. '
35
+ + conventions_1.UNTRUSTED_CONTENT_NOTE;
34
36
  const workelListTaskComments = (client) => (0, defineTool_1.defineTool)({
35
37
  name: 'workel_list_task_comments',
36
38
  description: DESCRIPTION,
@@ -1 +1 @@
1
- {"version":3,"file":"workel_task_comments.js","sourceRoot":"","sources":["../../src/tools/workel_task_comments.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,6BAAwB;AAExB,4CAAwD;AACxD,sCAAuD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AO,CAAC,CAAC;YAC/C,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,IAAA,qBAAY,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,CAAC,CAAC,CAAC;QACH,OAAO,IAAA,4BAAc,EAAC,IAAA,qBAAY,EAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3E,CAAC;CACF,CAAC,CAAC;AAvBQ,QAAA,sBAAsB,0BAuB9B"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The multi-workspace registry.
3
+ *
4
+ * A Workel API key is bound to exactly ONE workspace by the API — that binding
5
+ * is the tenancy boundary and nothing in this client can widen it. So reaching
6
+ * several workspaces means holding several keys, and this module is what turns
7
+ * a set of probed keys into the addressing layer the tools use.
8
+ *
9
+ * The alternative — running one server process per workspace — costs the model
10
+ * a full tool set per workspace (9 tools each, growing linearly). Here the tool
11
+ * count is constant and the workspace becomes an argument instead.
12
+ *
13
+ * This module is deliberately pure: `boot.ts` does the `GET /me` probing and
14
+ * hands the results in, so every case below (collisions, single vs. multi,
15
+ * unknown labels) is testable without a network.
16
+ */
17
+ import type { WorkelApiClient } from './api/client';
18
+ export interface WorkspaceEntry {
19
+ /** Workspace id from `GET /me`. Stable; the label is not. */
20
+ id: string;
21
+ /** Workspace display name from `GET /me`. May collide across keys. */
22
+ name: string;
23
+ /**
24
+ * How this workspace is addressed in tool arguments. Equal to `name` when
25
+ * that is unambiguous, otherwise `name (id)` — a label must identify exactly
26
+ * one workspace or a caller cannot target reliably.
27
+ */
28
+ label: string;
29
+ /** The key's own name, for diagnostics. Never the key itself. */
30
+ keyName: string;
31
+ /** Scopes THIS key carries. Different keys may carry different scopes. */
32
+ scopes: string[];
33
+ /** The client bound to this workspace's key. */
34
+ client: WorkelApiClient;
35
+ }
36
+ export interface WorkspaceRegistry {
37
+ entries: WorkspaceEntry[];
38
+ /** True when exactly one workspace is configured — the `workspace` argument is then optional. */
39
+ isSingle: boolean;
40
+ /** Every label, in configuration order. The enum offered to callers. */
41
+ labels: string[];
42
+ /** Union of scopes across all keys — what determines whether a tool registers at all. */
43
+ unionScopes: string[];
44
+ /**
45
+ * Resolves a label to its workspace. With one workspace configured, an
46
+ * omitted label resolves to it. With several, an omitted or unknown label
47
+ * throws a message naming the valid choices — the model can correct itself
48
+ * from that without a round trip to a human.
49
+ */
50
+ resolve(label: string | undefined): WorkspaceEntry;
51
+ }
52
+ export interface ProbedWorkspace {
53
+ id: string;
54
+ name: string;
55
+ keyName: string;
56
+ scopes: string[];
57
+ client: WorkelApiClient;
58
+ }
59
+ export declare function createWorkspaceRegistry(probed: ProbedWorkspace[]): WorkspaceRegistry;
60
+ //# sourceMappingURL=workspaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../src/workspaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,gDAAgD;IAChD,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,iGAAiG;IACjG,QAAQ,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yFAAyF;IACzF,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAAC;CACpD;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC;CACzB;AAeD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,iBAAiB,CAgDpF"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * The multi-workspace registry.
4
+ *
5
+ * A Workel API key is bound to exactly ONE workspace by the API — that binding
6
+ * is the tenancy boundary and nothing in this client can widen it. So reaching
7
+ * several workspaces means holding several keys, and this module is what turns
8
+ * a set of probed keys into the addressing layer the tools use.
9
+ *
10
+ * The alternative — running one server process per workspace — costs the model
11
+ * a full tool set per workspace (9 tools each, growing linearly). Here the tool
12
+ * count is constant and the workspace becomes an argument instead.
13
+ *
14
+ * This module is deliberately pure: `boot.ts` does the `GET /me` probing and
15
+ * hands the results in, so every case below (collisions, single vs. multi,
16
+ * unknown labels) is testable without a network.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createWorkspaceRegistry = createWorkspaceRegistry;
20
+ /**
21
+ * Two workspaces can legitimately share a display name — different orgs, or
22
+ * the same name reused. Bare names would then be ambiguous, so ONLY the
23
+ * colliding ones get their id appended; unique names stay clean, which is what
24
+ * the overwhelmingly common single-workspace and distinct-name cases deserve.
25
+ */
26
+ function assignLabels(probed) {
27
+ const counts = new Map();
28
+ for (const w of probed)
29
+ counts.set(w.name, (counts.get(w.name) ?? 0) + 1);
30
+ return probed.map((w) => ((counts.get(w.name) ?? 0) > 1 ? `${w.name} (${w.id})` : w.name));
31
+ }
32
+ function createWorkspaceRegistry(probed) {
33
+ if (probed.length === 0) {
34
+ throw new Error('At least one workspace is required to build a registry.');
35
+ }
36
+ const labels = assignLabels(probed);
37
+ const entries = probed.map((w, i) => ({
38
+ id: w.id,
39
+ name: w.name,
40
+ label: labels[i],
41
+ keyName: w.keyName,
42
+ scopes: w.scopes,
43
+ client: w.client,
44
+ }));
45
+ const byLabel = new Map(entries.map((e) => [e.label, e]));
46
+ // Ids are always unambiguous, so accept them too — a caller that has an id
47
+ // from a previous response should not have to translate it back to a name.
48
+ const byId = new Map(entries.map((e) => [e.id, e]));
49
+ const unionScopes = Array.from(new Set(entries.flatMap((e) => e.scopes)));
50
+ const isSingle = entries.length === 1;
51
+ return {
52
+ entries,
53
+ isSingle,
54
+ labels: entries.map((e) => e.label),
55
+ unionScopes,
56
+ resolve(label) {
57
+ if (label === undefined || label.trim() === '') {
58
+ if (isSingle)
59
+ return entries[0];
60
+ throw new Error(`This server is connected to ${entries.length} workspaces, so "workspace" is required. ` +
61
+ `Valid values: ${entries.map((e) => `"${e.label}"`).join(', ')}.`);
62
+ }
63
+ const trimmed = label.trim();
64
+ const found = byLabel.get(trimmed) ?? byId.get(trimmed);
65
+ if (found)
66
+ return found;
67
+ throw new Error(`Unknown workspace "${trimmed}". This key set reaches: ` +
68
+ `${entries.map((e) => `"${e.label}"`).join(', ')}. ` +
69
+ 'A workspace missing from that list needs its own API key added to WORKEL_API_KEYS.');
70
+ },
71
+ };
72
+ }
73
+ //# sourceMappingURL=workspaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../src/workspaces.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AA6DH,0DAgDC;AA7DD;;;;;GAKG;AACH,SAAS,YAAY,CAAC,MAAyB;IAC7C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;I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
  {
2
2
  "name": "@workel/mcp",
3
- "version": "0.1.0",
4
- "description": "Official Model Context Protocol server for Workel \u2014 a thin client of the Workel Public API v1",
3
+ "version": "0.2.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Official Model Context Protocol server for Workel — a thin client of the Workel Public API v1",
5
8
  "main": "dist/index.js",
6
9
  "bin": {
7
10
  "workel-mcp": "dist/index.js"
8
11
  },
9
12
  "files": [
10
- "dist"
13
+ "dist",
14
+ "LICENSE"
11
15
  ],
12
16
  "engines": {
13
17
  "node": ">=20"
@@ -27,7 +31,12 @@
27
31
  "ai",
28
32
  "agents"
29
33
  ],
34
+ "author": "Workel",
30
35
  "license": "MIT",
36
+ "homepage": "https://developer.workel.com",
37
+ "bugs": {
38
+ "url": "https://developer.workel.com"
39
+ },
31
40
  "dependencies": {
32
41
  "@modelcontextprotocol/sdk": "^1.30.0",
33
42
  "zod": "^3.23.8"
package/dist/remote.d.ts DELETED
@@ -1,164 +0,0 @@
1
- /**
2
- * The stateless Streamable HTTP entry — the v2 remote transport
3
- * (docs/MCP_SERVER_PLAN.md §"Phase 5 — v2 remote (bearer)"). This is
4
- * Phase 5 as CODE ONLY: nothing here is deployed, wired into CI, or given a
5
- * hostname. Its job is to prove `buildServer()` (`./server.ts`) is really
6
- * transport-independent — this module never edits it, only imports it — and
7
- * to make the remote-specific risks the stdio transport never had to face
8
- * concrete and testable: a curl-style `wk_`-only bearer check, a bare
9
- * `WWW-Authenticate: Bearer` challenge with none of the OAuth metadata that
10
- * is known to make some MCP clients silently ignore a static header, Origin
11
- * validation, and a front throttle keyed on a HASH of the bearer rather
12
- * than the caller's IP — per-IP is worthless here, since claude.ai and the
13
- * OpenAI Agents SDK both call out from shared provider egress ranges, so
14
- * every real tenant would collide in one IP-keyed bucket while a hashed-key
15
- * bucket keeps them apart without ever storing the raw key.
16
- *
17
- * Every request pipeline step below runs in a FIXED order and each step is
18
- * an unconditional early return — that order IS the security property, not
19
- * an implementation detail:
20
- *
21
- * 1. method — only POST is ever handled; everything else is 405.
22
- * 2. Origin — a PRESENT, disallowed Origin is 403. An ABSENT Origin
23
- * is allowed: server-to-server connectors (the only
24
- * caller this endpoint is designed for) send none, and
25
- * refusing them would break the one caller that matters.
26
- * 3. auth — no `Authorization` header, or a bearer not shaped like
27
- * `wk_...`, is 401 with a BARE `WWW-Authenticate: Bearer`
28
- * challenge — no `realm`, no `resource_metadata`, no
29
- * parameters at all — and, critically, NO upstream fetch
30
- * happens for either failure. A `wk_`-shaped bearer that
31
- * turns out to be wrong is not this module's problem to
32
- * diagnose: it goes to dispatch and comes back as
33
- * whatever the real Workel API says.
34
- * 4. throttle — a fixed window per SHA-256(bearer), sized (see
35
- * `REQUESTS_ALLOWED_PER_WINDOW` below) to match the
36
- * Public API v1's own per-key write ceiling
37
- * (`RouteServiceProvider.php`), so this front door is
38
- * never the tighter one. Exceeding it is a 429
39
- * response carrying `Retry-After`.
40
- * 5. dispatch — a brand-new `WorkelApiClient` bound to THIS request's
41
- * bearer, a brand-new `buildServer()` result, and a
42
- * brand-new stateless transport, connected and handed
43
- * the request. Nothing from one request — client,
44
- * server, transport, or key — is ever reused by the
45
- * next one; see `dispatch()` below.
46
- *
47
- * No per-request `/me` scope probe (a deliberate scope decision, not an
48
- * oversight — see the docblock on `computeCaps()` below for why, and the
49
- * final report's `decisions_outside_brief` for the tradeoff it accepts).
50
- *
51
- * Env reads: the ONLY function in this file that ever reads an environment
52
- * variable is `startRemote()`, and the ONLY way it does so is through
53
- * `config.ts`'s existing exported `loadConfig()` — see the docblock on
54
- * `startRemote()` for the one real friction point that decision creates
55
- * (`loadConfig` requires `WORKEL_API_KEY`, which this transport has no use
56
- * for) and why it is accepted rather than worked around by touching
57
- * `config.ts`, which is out of scope for this module.
58
- */
59
- import * as http from 'node:http';
60
- import { type FetchLike } from './api/client';
61
- export interface RemoteRequest extends AsyncIterable<Buffer> {
62
- method?: string;
63
- headers: Record<string, string | string[] | undefined>;
64
- }
65
- export interface RemoteResponse {
66
- writeHead(statusCode: number, headers?: Record<string, string>): void;
67
- end(chunk?: string): void;
68
- }
69
- /**
70
- * `message` is always a static string literal at every call site in this
71
- * file — nothing dynamic (an Origin value, a throttle key, an upstream
72
- * error) is ever string-interpolated into it. Anything dynamic rides in
73
- * `meta`, and `log()` below runs `meta` through `redactDeep` before it ever
74
- * reaches this interface's implementation — see `log()`'s docblock for why
75
- * that is a real, load-bearing second line of defense and not just
76
- * decoration.
77
- */
78
- export interface RemoteLogger {
79
- info(message: string, meta?: Record<string, unknown>): void;
80
- warn(message: string, meta?: Record<string, unknown>): void;
81
- error(message: string, meta?: Record<string, unknown>): void;
82
- }
83
- export interface RemoteHandlerDeps {
84
- fetch: FetchLike;
85
- logger: RemoteLogger;
86
- /** Defaults to `[]` when omitted — see the file docblock, step 2: an empty allowlist refuses every PRESENT Origin, but an absent Origin is still allowed regardless of this list's contents. */
87
- allowedOrigins?: string[];
88
- now: () => number;
89
- /** The Public API v1 base URL every per-request `WorkelApiClient` is built against. */
90
- baseUrl: string;
91
- /**
92
- * Gate (b) of D5 ("Read-only by default; writes are a double opt-in",
93
- * docs/MCP_SERVER_PLAN.md), resolved ONCE by the caller (`startRemote`,
94
- * from `config.ts`'s `loadConfig().enableWrites`) and passed in as a
95
- * plain boolean — never re-read from the environment inside the request
96
- * pipeline itself. `registeredWriteTools(writesEnabled)` (`./tools/registration.ts`)
97
- * is the same gate (b) `boot.ts` applies for stdio; passing this value
98
- * explicitly is what keeps this file from needing its own `process.env`
99
- * read to apply it.
100
- */
101
- writesEnabled: boolean;
102
- }
103
- export type RemoteRequestHandler = (req: RemoteRequest, res: RemoteResponse) => Promise<void>;
104
- /**
105
- * Sized to match the Public API v1's own per-key write ceiling
106
- * (`public-api` in `RouteServiceProvider.php`) so this front door is
107
- * never the tighter one for a legitimately busy key. Exported so
108
- * `remote.test.ts` can assert against this single source of the number
109
- * rather than restating it as a second, driftable literal.
110
- */
111
- export declare const REQUESTS_ALLOWED_PER_WINDOW = 120;
112
- /**
113
- * The largest request body this server will buffer. JSON-RPC tool calls are
114
- * kilobytes; this is generous. The cap is load-bearing: the only gate ahead
115
- * of this read is a `wk_` PREFIX test, never an upstream key verification, so
116
- * an attacker who has never held a valid key can reach it. Uncapped, a single
117
- * request buffered 200 MiB off-heap (+915 MB RSS) with zero upstream calls.
118
- */
119
- export declare const MAX_REQUEST_BODY_BYTES: number;
120
- /** Thrown by `readRawBody` when a body exceeds `MAX_REQUEST_BODY_BYTES`; the handler turns it into a 413. */
121
- export declare class RequestBodyTooLargeError extends Error {
122
- constructor();
123
- }
124
- /**
125
- * Builds the stateless request pipeline described in the file docblock.
126
- * Returns a plain `async (req, res) => void` function with no top-level
127
- * side effects of its own — constructing it opens no socket and reaches no
128
- * network; only actually CALLING the returned function (once per real HTTP
129
- * request, from `startRemote`'s `http.Server`, or directly from a test)
130
- * does anything.
131
- */
132
- export declare function createRemoteHandler(deps: RemoteHandlerDeps): RemoteRequestHandler;
133
- export interface StartRemoteOptions {
134
- env?: NodeJS.ProcessEnv;
135
- fetch?: FetchLike;
136
- logger?: RemoteLogger;
137
- now?: () => number;
138
- allowedOrigins?: string[];
139
- port?: number;
140
- }
141
- /**
142
- * Binds `createRemoteHandler`'s pipeline to a real Node `http.Server`. This
143
- * is the only place in the file that reads `process.env` — and even here,
144
- * only through `config.ts`'s existing exported `loadConfig()`, never a new
145
- * `env.SOMETHING` read of this module's own invention.
146
- *
147
- * That constraint has one real, honestly-stated cost: `loadConfig` requires
148
- * `WORKEL_API_KEY` to be set (`config.ts`'s `resolveApiKey`), a requirement
149
- * that makes sense for the stdio entry (`index.ts`), which serves exactly
150
- * one configured key for its whole process lifetime, but does NOT describe
151
- * this transport at all — the remote server's bearer arrives fresh on
152
- * every request (`dispatch()` above) and `WORKEL_API_KEY`, if set, is never
153
- * read by any request this process handles. Reusing `loadConfig` here is
154
- * still the right call for `baseUrl`/`enableWrites` — this file must not
155
- * re-derive `config.ts`'s own validation (an `https://` scheme check, a
156
- * boolean-flag parse) a second, drifting time — but it means an operator
157
- * deploying this entry must still set an (unused-per-request)
158
- * `WORKEL_API_KEY` purely to satisfy that loader. `config.ts` is out of
159
- * scope for this change; a follow-up that gives it a remote-shaped loader
160
- * (or exports its currently-private `resolveBaseUrl`/`parseBooleanFlag`
161
- * helpers directly) is the honest fix, not a workaround added here.
162
- */
163
- export declare function startRemote(opts?: StartRemoteOptions): http.Server;
164
- //# sourceMappingURL=remote.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAyB,KAAK,SAAS,EAAwB,MAAM,cAAc,CAAC;AAmB3F,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,MAAM,CAAC;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACtE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC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