@workel/mcp 0.2.0 → 0.4.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/README.md +86 -17
- package/dist/api/client.d.ts +19 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +41 -6
- package/dist/api/client.js.map +1 -1
- package/dist/api/mapping.d.ts +13 -1
- package/dist/api/mapping.d.ts.map +1 -1
- package/dist/api/mapping.js +72 -0
- package/dist/api/mapping.js.map +1 -1
- package/dist/api/types.d.ts +106 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/config.d.ts +5 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +37 -10
- package/dist/config.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +14 -4
- package/dist/server.js.map +1 -1
- package/dist/tools/createComment.js +1 -1
- package/dist/tools/createComment.js.map +1 -1
- package/dist/tools/createEvent.js +1 -1
- package/dist/tools/createEvent.js.map +1 -1
- package/dist/tools/createTask.js +1 -1
- package/dist/tools/createTask.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/logTime.d.ts +28 -0
- package/dist/tools/logTime.d.ts.map +1 -0
- package/dist/tools/logTime.js +83 -0
- package/dist/tools/logTime.js.map +1 -0
- package/dist/tools/registration.d.ts +5 -2
- package/dist/tools/registration.d.ts.map +1 -1
- package/dist/tools/registration.js +9 -2
- package/dist/tools/registration.js.map +1 -1
- package/dist/tools/updateTask.d.ts +20 -6
- package/dist/tools/updateTask.d.ts.map +1 -1
- package/dist/tools/updateTask.js +37 -11
- package/dist/tools/updateTask.js.map +1 -1
- package/dist/tools/uploadAttachment.d.ts +49 -0
- package/dist/tools/uploadAttachment.d.ts.map +1 -0
- package/dist/tools/uploadAttachment.js +133 -0
- package/dist/tools/uploadAttachment.js.map +1 -0
- package/dist/tools/workel_projects.js +1 -1
- package/dist/tools/workel_projects.js.map +1 -1
- package/dist/tools/workel_task_activity.d.ts +27 -0
- package/dist/tools/workel_task_activity.d.ts.map +1 -0
- package/dist/tools/workel_task_activity.js +67 -0
- package/dist/tools/workel_task_activity.js.map +1 -0
- package/dist/tools/workel_tasks.d.ts.map +1 -1
- package/dist/tools/workel_tasks.js +10 -4
- package/dist/tools/workel_tasks.js.map +1 -1
- package/dist/tools/workel_time_entries.d.ts +25 -0
- package/dist/tools/workel_time_entries.d.ts.map +1 -0
- package/dist/tools/workel_time_entries.js +74 -0
- package/dist/tools/workel_time_entries.js.map +1 -0
- package/dist/version.d.ts +16 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +17 -1
- package/dist/version.js.map +1 -1
- package/dist/worker.d.ts +41 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +113 -0
- package/dist/worker.js.map +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `workel_list_time_entries` — `GET /time-entries` (`read:time` scope; time
|
|
4
|
+
* has its own scopes on this surface, NOT `read:tasks`).
|
|
5
|
+
*
|
|
6
|
+
* Time tracked on tasks: each row is one block of time someone ran a timer
|
|
7
|
+
* for or logged by hand. Verified against `TimeEntriesController::index`:
|
|
8
|
+
*
|
|
9
|
+
* - Rows are limited to tasks on the workspace's visible projects (the same
|
|
10
|
+
* `ChecksProjectVisibility` chain every task tool uses), so time on an
|
|
11
|
+
* archived, private or inbox project never appears.
|
|
12
|
+
* - `from` is inclusive and `to` is EXCLUSIVE, both compared against the
|
|
13
|
+
* entry's `started_at` (an entry belongs to the moment it started). Either
|
|
14
|
+
* accepts a date or a date-time; a bare date is midnight UTC. The window
|
|
15
|
+
* cannot exceed 400 days; the server rejects a wider one rather than
|
|
16
|
+
* narrowing it, so this tool does not pre-validate it.
|
|
17
|
+
* - `task_id`, `project_id` and `user_id` narrow by exact id.
|
|
18
|
+
* - A running timer is included, with `running: true` and `ended_at` /
|
|
19
|
+
* `duration_seconds` null: its elapsed time is now minus `started_at`.
|
|
20
|
+
*
|
|
21
|
+
* `note` is the tracker's own free text, so it is bounded like every other
|
|
22
|
+
* free-text field and carries the untrusted-content note.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.workelListTimeEntries = void 0;
|
|
26
|
+
const zod_1 = require("zod");
|
|
27
|
+
const mapping_1 = require("../api/mapping");
|
|
28
|
+
const output_1 = require("../output");
|
|
29
|
+
const defineTool_1 = require("./defineTool");
|
|
30
|
+
const conventions_1 = require("./conventions");
|
|
31
|
+
const DESCRIPTION = 'List time tracked on tasks: each row is one block of time a person ran a timer for or logged by ' +
|
|
32
|
+
'hand, with the task, its project, who tracked it, started_at, ended_at, duration_seconds, ' +
|
|
33
|
+
'billable and an optional note. Narrow by task_id, project_id or user_id, and by from/to: from is ' +
|
|
34
|
+
"inclusive and to is EXCLUSIVE, both compared against each entry's started_at, and either accepts " +
|
|
35
|
+
'a date (midnight UTC) or a date-time; the window cannot exceed 400 days. A running timer appears ' +
|
|
36
|
+
'with running: true and ended_at/duration_seconds null; its elapsed time is now minus started_at. ' +
|
|
37
|
+
'To total time, add duration_seconds across the rows (and the running ones by hand). Only time on ' +
|
|
38
|
+
"tasks of projects visible to this API key is returned. Paginated via an opaque `cursor`; a `null` " +
|
|
39
|
+
'next_cursor means there are no more pages. ' +
|
|
40
|
+
conventions_1.UNTRUSTED_CONTENT_NOTE;
|
|
41
|
+
const workelListTimeEntries = (client) => (0, defineTool_1.defineTool)({
|
|
42
|
+
name: 'workel_list_time_entries',
|
|
43
|
+
description: DESCRIPTION,
|
|
44
|
+
inputSchema: {
|
|
45
|
+
limit: conventions_1.limitSchema,
|
|
46
|
+
cursor: zod_1.z.string().optional(),
|
|
47
|
+
from: zod_1.z.string().optional(),
|
|
48
|
+
to: zod_1.z.string().optional(),
|
|
49
|
+
task_id: zod_1.z.string().optional(),
|
|
50
|
+
project_id: zod_1.z.string().optional(),
|
|
51
|
+
user_id: zod_1.z.string().optional(),
|
|
52
|
+
},
|
|
53
|
+
annotations: { ...conventions_1.READ_ANNOTATIONS, title: 'List time entries' },
|
|
54
|
+
scope: 'read:time',
|
|
55
|
+
handler: async (args) => {
|
|
56
|
+
const { limit, cursor, from, to, task_id, project_id, user_id } = args;
|
|
57
|
+
const result = await client.get('/time-entries', {
|
|
58
|
+
limit,
|
|
59
|
+
cursor,
|
|
60
|
+
from,
|
|
61
|
+
to,
|
|
62
|
+
task_id,
|
|
63
|
+
project_id,
|
|
64
|
+
user_id,
|
|
65
|
+
});
|
|
66
|
+
const items = result.data.data.map((row) => {
|
|
67
|
+
const mapped = (0, mapping_1.mapTimeEntryFromWire)(row);
|
|
68
|
+
return { ...mapped, note: mapped.note === null ? null : (0, output_1.truncateText)(mapped.note) };
|
|
69
|
+
});
|
|
70
|
+
return (0, conventions_1.jsonToolResult)((0, output_1.listEnvelope)(items, result.data.meta.next_cursor));
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
exports.workelListTimeEntries = workelListTimeEntries;
|
|
74
|
+
//# sourceMappingURL=workel_time_entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workel_time_entries.js","sourceRoot":"","sources":["../../src/tools/workel_time_entries.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,6BAAwB;AAExB,4CAAsD;AACtD,sCAAuD;AACvD,6CAA4D;AAC5D,+CAAsG;AAEtG,MAAM,WAAW,GACf,kGAAkG;IAClG,4FAA4F;IAC5F,mGAAmG;IACnG,mGAAmG;IACnG,mGAAmG;IACnG,mGAAmG;IACnG,mGAAmG;IACnG,oGAAoG;IACpG,6CAA6C;IAC7C,oCAAsB,CAAC;AAElB,MAAM,qBAAqB,GAAgB,CAAC,MAAM,EAAE,EAAE,CAC3D,IAAA,uBAAU,EAAC;IACT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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;AAxCQ,QAAA,qBAAqB,yBAwC7B"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node reads package.json from disk; Workers cannot — it has no filesystem and
|
|
3
|
+
* no `__dirname`, so the read below throws at MODULE LOAD and the whole Worker
|
|
4
|
+
* fails to boot, not just the version lookup.
|
|
5
|
+
*
|
|
6
|
+
* The bundle-time constant is therefore checked first. This is not a fallback
|
|
7
|
+
* for a failed read: on Workers the read must never be attempted at all.
|
|
8
|
+
*
|
|
9
|
+
* The obvious alternative — `import pkg from '../package.json'` — was rejected
|
|
10
|
+
* because package.json sits outside `rootDir`, so enabling resolveJsonModule
|
|
11
|
+
* drags it into the emitted dist tree and changes the published layout.
|
|
12
|
+
*
|
|
13
|
+
* Drift between the injected value and package.json is prevented by a test
|
|
14
|
+
* (see server.redaction.test.ts), matching how RELEASING.md already pins the
|
|
15
|
+
* version across package.json / manifest.json / server.json.
|
|
16
|
+
*/
|
|
1
17
|
export declare const VERSION: string;
|
|
2
18
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAiCA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO,EAAE,MACiE,CAAC"}
|
package/dist/version.js
CHANGED
|
@@ -24,5 +24,21 @@ function readPackageVersion() {
|
|
|
24
24
|
}
|
|
25
25
|
throw new Error('Unable to resolve package.json to determine the server version.');
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Node reads package.json from disk; Workers cannot — it has no filesystem and
|
|
29
|
+
* no `__dirname`, so the read below throws at MODULE LOAD and the whole Worker
|
|
30
|
+
* fails to boot, not just the version lookup.
|
|
31
|
+
*
|
|
32
|
+
* The bundle-time constant is therefore checked first. This is not a fallback
|
|
33
|
+
* for a failed read: on Workers the read must never be attempted at all.
|
|
34
|
+
*
|
|
35
|
+
* The obvious alternative — `import pkg from '../package.json'` — was rejected
|
|
36
|
+
* because package.json sits outside `rootDir`, so enabling resolveJsonModule
|
|
37
|
+
* drags it into the emitted dist tree and changes the published layout.
|
|
38
|
+
*
|
|
39
|
+
* Drift between the injected value and package.json is prevented by a test
|
|
40
|
+
* (see server.redaction.test.ts), matching how RELEASING.md already pins the
|
|
41
|
+
* version across package.json / manifest.json / server.json.
|
|
42
|
+
*/
|
|
43
|
+
exports.VERSION = typeof WORKEL_MCP_VERSION !== 'undefined' ? WORKEL_MCP_VERSION : readPackageVersion();
|
|
28
44
|
//# sourceMappingURL=version.js.map
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;AAE5B;;;;GAIG;AACH,SAAS,kBAAkB;IACzB,MAAM,UAAU,GAAG,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE/F,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAA,iBAAY,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;YACpD,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACpC,OAAO,GAAG,CAAC,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACrF,CAAC;
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;AAE5B;;;;GAIG;AACH,SAAS,kBAAkB;IACzB,MAAM,UAAU,GAAG,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE/F,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAA,iBAAY,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;YACpD,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACpC,OAAO,GAAG,CAAC,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACrF,CAAC;AASD;;;;;;;;;;;;;;;GAeG;AACU,QAAA,OAAO,GAClB,OAAO,kBAAkB,KAAK,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cloudflare Workers entry — a third transport shell around the SAME
|
|
3
|
+
* `createRemoteHandler` the Node server uses (`./remote.ts`). This module
|
|
4
|
+
* adapts Fetch's `Request`/`Response` to the small Node-shaped request/response
|
|
5
|
+
* interfaces that handler expects, and does nothing else: no auth decisions, no
|
|
6
|
+
* routing, no tool logic. Everything security-relevant stays in one place.
|
|
7
|
+
*
|
|
8
|
+
* Why Workers rather than a container: the frontend already deploys here, so
|
|
9
|
+
* `mcp.workel.com` is a DNS record and a route on infrastructure that exists,
|
|
10
|
+
* instead of a new App Service, a container registry push, and a Terraform
|
|
11
|
+
* apply. The handler is transport-agnostic by design, which is what makes this
|
|
12
|
+
* a ~100-line adapter rather than a port.
|
|
13
|
+
*
|
|
14
|
+
* Config comes from `env` bindings, never `process.env` — Workers has no
|
|
15
|
+
* process. The names match the container's variables exactly so one runbook
|
|
16
|
+
* covers both.
|
|
17
|
+
*
|
|
18
|
+
* One honest difference from the Node deployment: `remote.ts`'s front throttle
|
|
19
|
+
* is a module-level Map, which on Workers is per-ISOLATE rather than
|
|
20
|
+
* per-process. Isolates are many and short-lived, so that ceiling is softer
|
|
21
|
+
* here. It is defense-in-depth either way — the authoritative per-key and
|
|
22
|
+
* per-workspace limits live on the Public API and are reported live by
|
|
23
|
+
* `/me`, so no amount of edge concurrency bypasses them. If this front
|
|
24
|
+
* throttle ever needs to be authoritative, that is a Durable Object or the
|
|
25
|
+
* Workers Rate Limiting API, not a bigger Map.
|
|
26
|
+
*/
|
|
27
|
+
export interface WorkerEnv {
|
|
28
|
+
/** Public API v1 base URL. The PUBLIC surface only — never internal, never the database. */
|
|
29
|
+
WORKEL_API_BASE_URL?: string;
|
|
30
|
+
/** Presence switches on OAuth mode; see RemoteHandlerDeps.protectedResourceMetadataUrl. */
|
|
31
|
+
WORKEL_OAUTH_RESOURCE_METADATA_URL?: string;
|
|
32
|
+
/** Comma-separated. Empty means: refuse any PRESENT Origin, still allow an absent one. */
|
|
33
|
+
WORKEL_ALLOWED_ORIGINS?: string;
|
|
34
|
+
/** "true" enables the write tools. Read-only by default, matching the stdio server. */
|
|
35
|
+
WORKEL_ENABLE_WRITES?: string;
|
|
36
|
+
}
|
|
37
|
+
declare const _default: {
|
|
38
|
+
fetch(request: Request, env: WorkerEnv): Promise<Response>;
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|
|
41
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,MAAM,WAAW,SAAS;IACxB,4FAA4F;IAC5F,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2FAA2F;IAC3F,kCAAkC,CAAC,EAAE,MAAM,CAAC;IAC5C,0FAA0F;IAC1F,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uFAAuF;IACvF,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;;mBA0DsB,OAAO,OAAO,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;;AADlE,wBAqCE"}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Cloudflare Workers entry — a third transport shell around the SAME
|
|
4
|
+
* `createRemoteHandler` the Node server uses (`./remote.ts`). This module
|
|
5
|
+
* adapts Fetch's `Request`/`Response` to the small Node-shaped request/response
|
|
6
|
+
* interfaces that handler expects, and does nothing else: no auth decisions, no
|
|
7
|
+
* routing, no tool logic. Everything security-relevant stays in one place.
|
|
8
|
+
*
|
|
9
|
+
* Why Workers rather than a container: the frontend already deploys here, so
|
|
10
|
+
* `mcp.workel.com` is a DNS record and a route on infrastructure that exists,
|
|
11
|
+
* instead of a new App Service, a container registry push, and a Terraform
|
|
12
|
+
* apply. The handler is transport-agnostic by design, which is what makes this
|
|
13
|
+
* a ~100-line adapter rather than a port.
|
|
14
|
+
*
|
|
15
|
+
* Config comes from `env` bindings, never `process.env` — Workers has no
|
|
16
|
+
* process. The names match the container's variables exactly so one runbook
|
|
17
|
+
* covers both.
|
|
18
|
+
*
|
|
19
|
+
* One honest difference from the Node deployment: `remote.ts`'s front throttle
|
|
20
|
+
* is a module-level Map, which on Workers is per-ISOLATE rather than
|
|
21
|
+
* per-process. Isolates are many and short-lived, so that ceiling is softer
|
|
22
|
+
* here. It is defense-in-depth either way — the authoritative per-key and
|
|
23
|
+
* per-workspace limits live on the Public API and are reported live by
|
|
24
|
+
* `/me`, so no amount of edge concurrency bypasses them. If this front
|
|
25
|
+
* throttle ever needs to be authoritative, that is a Durable Object or the
|
|
26
|
+
* Workers Rate Limiting API, not a bigger Map.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const remote_1 = require("./remote");
|
|
30
|
+
/**
|
|
31
|
+
* Adapt a Fetch `Request` to the handler's request shape.
|
|
32
|
+
*
|
|
33
|
+
* The body is read once, up front, and yielded as a single chunk. The handler's
|
|
34
|
+
* own `MAX_REQUEST_BODY_BYTES` guard still applies — it checks a running total
|
|
35
|
+
* while iterating, so one large chunk trips it exactly as many small ones
|
|
36
|
+
* would.
|
|
37
|
+
*/
|
|
38
|
+
function toRemoteRequest(request, body) {
|
|
39
|
+
const headers = {};
|
|
40
|
+
request.headers.forEach((value, key) => {
|
|
41
|
+
headers[key.toLowerCase()] = value;
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
method: request.method,
|
|
45
|
+
headers,
|
|
46
|
+
url: new URL(request.url).pathname,
|
|
47
|
+
async *[Symbol.asyncIterator]() {
|
|
48
|
+
if (body.byteLength > 0) {
|
|
49
|
+
yield Buffer.from(body);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Collect what the handler writes into a real `Response`.
|
|
56
|
+
*
|
|
57
|
+
* The handler calls writeHead/end exactly once per request (it guards on a
|
|
58
|
+
* `responded` flag), so a promise resolved by `end` is a faithful translation
|
|
59
|
+
* rather than a race.
|
|
60
|
+
*/
|
|
61
|
+
function createCollector() {
|
|
62
|
+
let resolve;
|
|
63
|
+
const response = new Promise((r) => {
|
|
64
|
+
resolve = r;
|
|
65
|
+
});
|
|
66
|
+
let status = 500;
|
|
67
|
+
let headers = {};
|
|
68
|
+
const res = {
|
|
69
|
+
writeHead(s, h) {
|
|
70
|
+
status = s;
|
|
71
|
+
headers = h ?? {};
|
|
72
|
+
},
|
|
73
|
+
end(chunk) {
|
|
74
|
+
resolve(new Response(chunk ?? null, { status, headers }));
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
return { res, response };
|
|
78
|
+
}
|
|
79
|
+
exports.default = {
|
|
80
|
+
async fetch(request, env) {
|
|
81
|
+
const handler = (0, remote_1.createRemoteHandler)({
|
|
82
|
+
// FetchLike is `typeof fetch`, so the runtime's own global satisfies it
|
|
83
|
+
// directly — no wrapper, and nothing here can accidentally alter a
|
|
84
|
+
// request on its way upstream.
|
|
85
|
+
fetch,
|
|
86
|
+
logger: {
|
|
87
|
+
// console in Workers goes to the observability log stream. Kept to the
|
|
88
|
+
// same three levels the Node logger uses so log shape does not depend
|
|
89
|
+
// on where the server happens to run.
|
|
90
|
+
info: (message, meta) => console.log(message, meta ?? {}),
|
|
91
|
+
warn: (message, meta) => console.warn(message, meta ?? {}),
|
|
92
|
+
error: (message, meta) => console.error(message, meta ?? {}),
|
|
93
|
+
},
|
|
94
|
+
now: () => Date.now(),
|
|
95
|
+
baseUrl: env.WORKEL_API_BASE_URL ?? 'https://api.workel.com/api/public/v1',
|
|
96
|
+
writesEnabled: env.WORKEL_ENABLE_WRITES === 'true',
|
|
97
|
+
protectedResourceMetadataUrl: env.WORKEL_OAUTH_RESOURCE_METADATA_URL,
|
|
98
|
+
allowedOrigins: (env.WORKEL_ALLOWED_ORIGINS ?? '')
|
|
99
|
+
.split(',')
|
|
100
|
+
.map((o) => o.trim())
|
|
101
|
+
.filter(Boolean),
|
|
102
|
+
});
|
|
103
|
+
// Read the body before handing over: Workers gives a stream, the handler
|
|
104
|
+
// wants async-iterable chunks, and a GET/HEAD has no body to read at all.
|
|
105
|
+
const raw = request.method === 'GET' || request.method === 'HEAD'
|
|
106
|
+
? new Uint8Array(0)
|
|
107
|
+
: new Uint8Array(await request.arrayBuffer());
|
|
108
|
+
const { res, response } = createCollector();
|
|
109
|
+
await handler(toRemoteRequest(request, raw), res);
|
|
110
|
+
return response;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAEH,qCAAwF;AAaxF;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,OAAgB,EAAE,IAAgB;IACzD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACrC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO;QACP,GAAG,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ;QAClC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;YAC3B,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe;IACtB,IAAI,OAA+B,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAW,CAAC,CAAC,EAAE,EAAE;QAC3C,OAAO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AK,MAAM;YAClD,4BAA4B,EAAE,GAAG,CAAC,kCAAkC;YACpE,cAAc,EAAE,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC;iBAC/C,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpB,MAAM,CAAC,OAAO,CAAC;SACnB,CAAC,CAAC;QAEH,yEAAyE;QACzE,0EAA0E;QAC1E,MAAM,GAAG,GACP,OAAO,CAAC,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;YACnD,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC;YACnB,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QAElD,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC;QAC5C,MAAM,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;QAElD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workel/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"description": "Official Model Context Protocol server for Workel
|
|
7
|
+
"description": "Official Model Context Protocol server for Workel \u2014 a thin client of the Workel Public API v1",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"bin": {
|
|
10
10
|
"workel-mcp": "dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
|
+
"!dist/remote.*",
|
|
14
15
|
"LICENSE"
|
|
15
16
|
],
|
|
16
17
|
"engines": {
|
|
@@ -33,7 +34,11 @@
|
|
|
33
34
|
],
|
|
34
35
|
"author": "Workel",
|
|
35
36
|
"license": "MIT",
|
|
36
|
-
"
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/WorkelCEO/workel-mcp.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://developer.workel.com/#mcp",
|
|
37
42
|
"bugs": {
|
|
38
43
|
"url": "https://developer.workel.com"
|
|
39
44
|
},
|
|
@@ -46,6 +51,7 @@
|
|
|
46
51
|
"@types/node": "^20.10.6",
|
|
47
52
|
"jest": "^29.7.0",
|
|
48
53
|
"ts-jest": "^29.4.9",
|
|
49
|
-
"typescript": "^5.3.3"
|
|
54
|
+
"typescript": "^5.3.3",
|
|
55
|
+
"wrangler": "^4.126.0"
|
|
50
56
|
}
|
|
51
57
|
}
|