@codegame.dev/careerflow-mcp 1.9.0 → 2.1.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 +215 -119
- package/dist/capabilities.js +37 -8
- package/dist/capabilities.js.map +1 -1
- package/dist/client.js +48 -13
- package/dist/client.js.map +1 -1
- package/dist/helpers.js +87 -33
- package/dist/helpers.js.map +1 -1
- package/dist/index.js +134 -55
- package/dist/index.js.map +1 -1
- package/dist/prompts.js +38 -0
- package/dist/prompts.js.map +1 -0
- package/dist/setup.js +139 -16
- package/dist/setup.js.map +1 -1
- package/dist/tools/kanban-extra.js +39 -3
- package/dist/tools/kanban-extra.js.map +1 -1
- package/dist/tools/tasks.js +85 -24
- package/dist/tools/tasks.js.map +1 -1
- package/dist/tools/time.js +1 -7
- package/dist/tools/time.js.map +1 -1
- package/dist/tools/worklog.js +375 -0
- package/dist/tools/worklog.js.map +1 -0
- package/dist/workspaces.js +58 -0
- package/dist/workspaces.js.map +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -38,53 +38,88 @@ export class CareerFlowClient {
|
|
|
38
38
|
get defaultCompanyId() {
|
|
39
39
|
return this.config.companyId;
|
|
40
40
|
}
|
|
41
|
-
async get(path, query = {}) {
|
|
41
|
+
async get(path, query = {}, options = {}) {
|
|
42
42
|
const url = new URL(`${this.config.baseUrl}/${path}`);
|
|
43
43
|
for (const [key, value] of Object.entries(query)) {
|
|
44
44
|
if (value !== undefined && value !== null && value !== "") {
|
|
45
45
|
url.searchParams.set(key, String(value));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
return this.request(url.toString(), { method: "GET" });
|
|
48
|
+
return this.request(url.toString(), { method: "GET" }, options);
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Sends a JSON body. `undefined` fields are always dropped. `null` fields are
|
|
52
|
+
* dropped too unless `sendNull` is set: the backend's JsonBody middleware turns
|
|
53
|
+
* a JSON null into a present `$_POST` key, and partial-update controllers
|
|
54
|
+
* (gated by `array_key_exists`) read a present null as "clear this field".
|
|
55
|
+
* Only callers that mean "clear" opt in, so a null read back from a row and
|
|
56
|
+
* echoed into a whole-row edit keeps its old "omit" meaning.
|
|
57
|
+
*/
|
|
58
|
+
async post(path, body = {}, options = {}) {
|
|
51
59
|
const url = `${this.config.baseUrl}/${path}`;
|
|
52
60
|
const payload = {};
|
|
53
61
|
for (const [key, value] of Object.entries(body)) {
|
|
54
|
-
if (value
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
if (value === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
if (value === null && !options.sendNull)
|
|
65
|
+
continue;
|
|
66
|
+
payload[key] = value;
|
|
57
67
|
}
|
|
58
68
|
return this.request(url, {
|
|
59
69
|
method: "POST",
|
|
60
70
|
headers: { "Content-Type": "application/json" },
|
|
61
71
|
body: JSON.stringify(payload)
|
|
62
|
-
});
|
|
72
|
+
}, options);
|
|
63
73
|
}
|
|
64
|
-
async
|
|
74
|
+
async fetchOnce(url, init, timeoutMs) {
|
|
65
75
|
const controller = new AbortController();
|
|
66
|
-
const timer = setTimeout(() => controller.abort(),
|
|
67
|
-
let response;
|
|
76
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
68
77
|
try {
|
|
69
|
-
|
|
78
|
+
return await fetch(url, {
|
|
70
79
|
...init,
|
|
71
80
|
signal: controller.signal,
|
|
72
81
|
headers: {
|
|
73
82
|
...(init.headers ?? {}),
|
|
74
83
|
token: this.config.token,
|
|
75
|
-
Accept: "application/json"
|
|
84
|
+
Accept: "application/json",
|
|
85
|
+
// the backend picks its message language from this header first,
|
|
86
|
+
// so validation errors come back in English instead of Persian
|
|
87
|
+
locale: "en"
|
|
76
88
|
}
|
|
77
89
|
});
|
|
78
90
|
}
|
|
79
91
|
catch (error) {
|
|
80
92
|
if (error instanceof Error && error.name === "AbortError") {
|
|
81
|
-
throw new ApiError(`Request timed out after ${
|
|
93
|
+
throw new ApiError(`Request timed out after ${timeoutMs}ms`, 408);
|
|
82
94
|
}
|
|
83
95
|
throw new ApiError(`Could not reach CareerFlow at ${this.config.baseUrl}: ${error.message}`, 0);
|
|
84
96
|
}
|
|
85
97
|
finally {
|
|
86
98
|
clearTimeout(timer);
|
|
87
99
|
}
|
|
100
|
+
}
|
|
101
|
+
async request(url, init, options) {
|
|
102
|
+
const timeoutMs = options.timeoutMs ?? this.config.timeoutMs;
|
|
103
|
+
let response;
|
|
104
|
+
for (let attempt = 0;; attempt++) {
|
|
105
|
+
try {
|
|
106
|
+
response = await this.fetchOnce(url, init, timeoutMs);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// One retry for a transient failure. A network error before any
|
|
111
|
+
// response means the request never reached the API, so it is safe
|
|
112
|
+
// for every method. A timeout may have reached it, so only a GET
|
|
113
|
+
// (no side effect) is retried after one.
|
|
114
|
+
const retriable = attempt === 0 &&
|
|
115
|
+
!options.noRetry &&
|
|
116
|
+
error instanceof ApiError &&
|
|
117
|
+
(error.status === 0 || (error.status === 408 && init.method === "GET"));
|
|
118
|
+
if (!retriable)
|
|
119
|
+
throw error;
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
88
123
|
const text = await response.text();
|
|
89
124
|
let body;
|
|
90
125
|
try {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAmBA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGxB;IACA;IAHV,YACC,OAAe,EACN,MAAc,EACd,MAAgB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAU;QAGzB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;IACvB,CAAC;CACD;AAED;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AU,EAAE,CAAC;YACtC,MAAM,IAAI,QAAQ,CACjB,cAAc,CAAC,IAAI,CAAC,IAAI,mCAAmC,QAAQ,CAAC,MAAM,GAAG,EAC7E,QAAQ,CAAC,MAAM,EACf,IAAI,CAAC,MAAM,CACX,CAAA;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
|
package/dist/helpers.js
CHANGED
|
@@ -22,7 +22,9 @@ export function resolveCompanyId(client, provided) {
|
|
|
22
22
|
return companyId;
|
|
23
23
|
}
|
|
24
24
|
export function textResult(value) {
|
|
25
|
-
|
|
25
|
+
// compact on purpose: results stay in the conversation and are re-read every
|
|
26
|
+
// turn, and indentation alone was ~18% of a typical list result
|
|
27
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
26
28
|
return { content: [{ type: "text", text }] };
|
|
27
29
|
}
|
|
28
30
|
export function errorResult(error) {
|
|
@@ -48,11 +50,14 @@ export function safeHandler(handler) {
|
|
|
48
50
|
* rows carry ~40 columns of bookkeeping (activity flags, snapshot ids, ordering
|
|
49
51
|
* numbers) that would otherwise crowd out the useful content of a result.
|
|
50
52
|
*/
|
|
51
|
-
export function summariseTask(task) {
|
|
53
|
+
export function summariseTask(task, options = {}) {
|
|
54
|
+
const mode = options.description ?? "full";
|
|
55
|
+
const text = typeof task.description === "string" ? task.description.trim() : "";
|
|
52
56
|
return {
|
|
53
57
|
id: task.id,
|
|
54
58
|
title: task.title,
|
|
55
|
-
description:
|
|
59
|
+
description: mode === "full" ? text || undefined : undefined,
|
|
60
|
+
description_preview: mode === "preview" && text ? (text.length > 120 ? `${text.slice(0, 120)}…` : text) : undefined,
|
|
56
61
|
project_id: task.project_id,
|
|
57
62
|
project_title: task.project_title || task.project_name || undefined,
|
|
58
63
|
board_id: task.board_id,
|
|
@@ -66,14 +71,15 @@ export function summariseTask(task) {
|
|
|
66
71
|
time_minutes: task.time_minutes ?? undefined,
|
|
67
72
|
review_status: task.review_status || undefined,
|
|
68
73
|
review_score: task.review_score ?? undefined,
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
// defaults are left out: false/empty values on every row add up in a list
|
|
75
|
+
is_archived: task.is_archived ? true : undefined,
|
|
76
|
+
members: Array.isArray(task.members) && task.members.length
|
|
71
77
|
? task.members.map((m) => ({
|
|
72
78
|
user_id: m.user_id ?? m.id,
|
|
73
79
|
name: [m.firstname, m.lastname].filter(Boolean).join(" ") || m.staff_number_with_prefix
|
|
74
80
|
}))
|
|
75
81
|
: undefined,
|
|
76
|
-
labels: Array.isArray(task.labels)
|
|
82
|
+
labels: Array.isArray(task.labels) && task.labels.length
|
|
77
83
|
? task.labels.map((l) => ({ id: l.id, title: l.title }))
|
|
78
84
|
: undefined
|
|
79
85
|
};
|
|
@@ -90,6 +96,31 @@ export function summariseUser(user) {
|
|
|
90
96
|
position: user.position || user.job_title || undefined
|
|
91
97
|
};
|
|
92
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* List results for tasks: lean rows plus paging hints.
|
|
101
|
+
*
|
|
102
|
+
* Descriptions are the bulk of a task row (~40% of a search result), so a list
|
|
103
|
+
* carries a short preview unless asked for the full text; get_task has it.
|
|
104
|
+
* project_title / board_name are hoisted to the top when every row shares
|
|
105
|
+
* them, instead of being repeated per row.
|
|
106
|
+
*/
|
|
107
|
+
export function summariseTaskList(tasks, total, page, limit, includeDescription = false) {
|
|
108
|
+
const rows = tasks.map((t) => summariseTask(t, { description: includeDescription ? "full" : "preview" }));
|
|
109
|
+
const result = {
|
|
110
|
+
count: total ?? rows.length,
|
|
111
|
+
has_more: total !== undefined ? page * limit < total : rows.length === limit
|
|
112
|
+
};
|
|
113
|
+
for (const key of ["project_title", "board_name"]) {
|
|
114
|
+
const values = new Set(rows.map((r) => r[key]));
|
|
115
|
+
if (rows.length > 1 && values.size === 1 && rows[0][key] !== undefined) {
|
|
116
|
+
result[key] = rows[0][key];
|
|
117
|
+
for (const row of rows)
|
|
118
|
+
delete row[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
result.tasks = rows;
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
93
124
|
/**
|
|
94
125
|
* Fetches a single task by id alone.
|
|
95
126
|
*
|
|
@@ -97,11 +128,6 @@ export function summariseUser(user) {
|
|
|
97
128
|
* a caller working from a task number will not have. Task search accepts a bare
|
|
98
129
|
* id and returns the same row plus its project/board, so it is used as the
|
|
99
130
|
* lookup and the ids come back with the task.
|
|
100
|
-
*
|
|
101
|
-
* The read matters for more than convenience: `kanbans/tasks/edit` replaces the
|
|
102
|
-
* whole row, so any field omitted falls back to a default (is_completed -> false,
|
|
103
|
-
* priority -> "medium"). Every edit reads the task first and merges onto it — see
|
|
104
|
-
* `mergeTaskEdit` — so a partial change cannot silently clear untouched fields.
|
|
105
131
|
*/
|
|
106
132
|
export async function fetchTask(client, companyId, taskId) {
|
|
107
133
|
const response = await client.get("kanbans/tasks/search", {
|
|
@@ -117,33 +143,56 @@ export async function fetchTask(client, companyId, taskId) {
|
|
|
117
143
|
return task;
|
|
118
144
|
}
|
|
119
145
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
146
|
+
* Applies a partial edit through `kanbans/tasks/edit`.
|
|
147
|
+
*
|
|
148
|
+
* The endpoint is a partial update: apart from the four ids it requires, every
|
|
149
|
+
* field is gated by `array_key_exists` in `Kanbans::edit_task`, so only the
|
|
150
|
+
* changed fields are sent. Re-sending unchanged fields is not harmless —
|
|
151
|
+
* `label_ids` makes the controller delete and re-insert every label, which can
|
|
152
|
+
* race an edit made in the web UI. A null value is sent as null, which the
|
|
153
|
+
* controller reads as "clear this field".
|
|
122
154
|
*/
|
|
123
|
-
export function
|
|
124
|
-
const
|
|
125
|
-
? current.labels.map((l) => l.id).join(",")
|
|
126
|
-
: undefined;
|
|
127
|
-
const base = {
|
|
155
|
+
export async function editTask(client, companyId, task, changes) {
|
|
156
|
+
const body = {
|
|
128
157
|
company_id: companyId,
|
|
129
|
-
project_id:
|
|
130
|
-
board_id:
|
|
131
|
-
task_id:
|
|
132
|
-
title: current.title,
|
|
133
|
-
description: current.description ?? "",
|
|
134
|
-
is_completed: Boolean(current.is_completed),
|
|
135
|
-
start_date: current.start_date ?? null,
|
|
136
|
-
due_date: current.due_date ?? null,
|
|
137
|
-
priority: current.priority ?? "medium",
|
|
138
|
-
time_estimate_minutes: current.time_estimate_minutes ?? null,
|
|
139
|
-
label_ids: labelIds
|
|
158
|
+
project_id: task.project_id,
|
|
159
|
+
board_id: task.board_id,
|
|
160
|
+
task_id: task.id
|
|
140
161
|
};
|
|
141
162
|
for (const [key, value] of Object.entries(changes)) {
|
|
142
|
-
if (value !== undefined)
|
|
143
|
-
|
|
144
|
-
}
|
|
163
|
+
if (value !== undefined)
|
|
164
|
+
body[key] = value;
|
|
145
165
|
}
|
|
146
|
-
|
|
166
|
+
const response = await client.post("kanbans/tasks/edit", body, {
|
|
167
|
+
sendNull: true
|
|
168
|
+
});
|
|
169
|
+
return response.data?.task;
|
|
170
|
+
}
|
|
171
|
+
/** The API expects local-time "YYYY-MM-DD HH:MM:SS", not an ISO-8601 string. */
|
|
172
|
+
export function formatApiDate(date) {
|
|
173
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
174
|
+
return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
175
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Adds a next step to an error about board_id. The backend rejects a board
|
|
179
|
+
* from another project (or an archived one) as "does not exist", which gave the
|
|
180
|
+
* model nothing to act on.
|
|
181
|
+
*/
|
|
182
|
+
export function withBoardHint(error, boardId, projectId) {
|
|
183
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
184
|
+
const fields = error instanceof ApiError && error.errors && typeof error.errors === "object" ? Object.keys(error.errors) : [];
|
|
185
|
+
// the backend's message for this field is "List ID is not exist" (the UI's name for a board)
|
|
186
|
+
const aboutBoard = fields.includes("board_id") || /board|list id/i.test(message);
|
|
187
|
+
if (boardId === undefined || !aboutBoard)
|
|
188
|
+
return error;
|
|
189
|
+
const hint = ` (board_id ${boardId} is not an active board of project ${projectId ?? "?"} — ` +
|
|
190
|
+
`call list_boards with project_id ${projectId ?? "<project>"} to find one)`;
|
|
191
|
+
if (error instanceof Error) {
|
|
192
|
+
error.message += hint;
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
return new Error(message + hint);
|
|
147
196
|
}
|
|
148
197
|
/**
|
|
149
198
|
* The authenticated user's id, cached for the process lifetime.
|
|
@@ -153,6 +202,11 @@ export function mergeTaskEdit(current, companyId, changes) {
|
|
|
153
202
|
* to mean "mine". The token maps to a fixed user, so the lookup is done once.
|
|
154
203
|
*/
|
|
155
204
|
let cachedUserId;
|
|
205
|
+
/** Seeds the cache from the startup profile fetch, saving the first tool call a round trip. */
|
|
206
|
+
export function primeCurrentUserId(id) {
|
|
207
|
+
if (id !== undefined && Number.isFinite(id))
|
|
208
|
+
cachedUserId = id;
|
|
209
|
+
}
|
|
156
210
|
export async function currentUserId(client) {
|
|
157
211
|
if (cachedUserId !== undefined) {
|
|
158
212
|
return cachedUserId;
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC;;GAEG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC9B,MAAM,EAAE;KACR,GAAG,EAAE;KACL,QAAQ,EAAE;KACV,QAAQ,CACR,iFAAiF;IAChF,uDAAuD,CACxD,CAAA;AAEF;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB,EAAE,QAAiB;IAC3E,MAAM,SAAS,GAAG,QAAQ,IAAI,MAAM,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AK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QACzE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACxB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AACrB,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,KAA0B;IACnD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACzC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACrB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,11 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { loadConfig } from "./config.js";
|
|
6
6
|
import { CareerFlowClient } from "./client.js";
|
|
7
|
-
import { allows, fetchCapabilities, gateServer } from "./capabilities.js";
|
|
7
|
+
import { allows, fetchCapabilities, gateServer, PROFILES } from "./capabilities.js";
|
|
8
|
+
import { primeCurrentUserId } from "./helpers.js";
|
|
9
|
+
import { describeWorkspace, findWorkspace } from "./workspaces.js";
|
|
10
|
+
import { registerPrompts } from "./prompts.js";
|
|
11
|
+
import { registerWorklogTools } from "./tools/worklog.js";
|
|
8
12
|
import { registerTaskTools } from "./tools/tasks.js";
|
|
9
13
|
import { registerWorkspaceTools } from "./tools/workspace.js";
|
|
10
14
|
import { registerTimeTools } from "./tools/time.js";
|
|
@@ -43,7 +47,14 @@ catch {
|
|
|
43
47
|
*/
|
|
44
48
|
const toolGroups = [
|
|
45
49
|
{ name: "workspace", description: "whoami, companies, users", register: registerWorkspaceTools },
|
|
46
|
-
{
|
|
50
|
+
{
|
|
51
|
+
name: "tasks",
|
|
52
|
+
description: "tasks, comments, record_work",
|
|
53
|
+
register: (server, client) => {
|
|
54
|
+
registerWorklogTools(server, client);
|
|
55
|
+
registerTaskTools(server, client);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
47
58
|
{ name: "kanban", description: "boards, labels, checklists, attachments", register: registerKanbanExtraTools },
|
|
48
59
|
{ name: "projects", description: "projects and membership", register: registerProjectTools },
|
|
49
60
|
{ name: "time", description: "timers and time entries", register: registerTimeTools },
|
|
@@ -83,6 +94,7 @@ Usage:
|
|
|
83
94
|
npx @codegame.dev/careerflow-mcp Start the MCP server over stdio (what a client runs)
|
|
84
95
|
npx @codegame.dev/careerflow-mcp init Guided setup: asks for your token, then wires up your client
|
|
85
96
|
npx @codegame.dev/careerflow-mcp remove Undo init: removes the server entry from your client
|
|
97
|
+
npx @codegame.dev/careerflow-mcp link Save the board this folder's work is logged on
|
|
86
98
|
npx @codegame.dev/careerflow-mcp --help Show this help
|
|
87
99
|
npx @codegame.dev/careerflow-mcp --version Show the version
|
|
88
100
|
|
|
@@ -92,11 +104,26 @@ separately, hidden, and never read from the command line):
|
|
|
92
104
|
--name <name> Server name in the client config (default: careerflow)
|
|
93
105
|
--company-id <id> Default company, so tools need no company_id
|
|
94
106
|
--client <id> claude-code, claude-desktop, zcode, cursor, or other
|
|
107
|
+
--profile <name> worklog (task and time tools only) or full; asked if omitted
|
|
108
|
+
--scope <name> Claude Code only: user (all projects) or local (this
|
|
109
|
+
folder, for you only); asked if omitted
|
|
95
110
|
|
|
96
111
|
remove options (no token needed):
|
|
97
112
|
--name <name> Server name to remove (default: careerflow)
|
|
98
113
|
--client <id> claude-code, claude-desktop, zcode, or cursor
|
|
99
114
|
(without it, remove asks interactively)
|
|
115
|
+
--scope <name> Claude Code scope it was added in (default: user)
|
|
116
|
+
|
|
117
|
+
link options (run inside the repo; writes ~/.config/careerflow-mcp/workspaces.json):
|
|
118
|
+
--project <id> Project id, the UI's board or project (required)
|
|
119
|
+
--board <id> Optional list id every task goes to (default: picked
|
|
120
|
+
per task, finished work to the "Done" list)
|
|
121
|
+
--done-board <id> Optional list id finished tasks go to
|
|
122
|
+
--company-id <id> Optional; defaults to CAREERFLOW_COMPANY_ID
|
|
123
|
+
--dir <path> Folder to link (default: the current directory)
|
|
124
|
+
|
|
125
|
+
Faster startup: npm i -g @codegame.dev/careerflow-mcp, then use "careerflow-mcp"
|
|
126
|
+
as the client command instead of npx (init does this when installed globally).
|
|
100
127
|
|
|
101
128
|
Example one-liner for onboarding pages:
|
|
102
129
|
npx @codegame.dev/careerflow-mcp init --base-url https://app.example.com --name acme --client claude-code
|
|
@@ -106,6 +133,8 @@ Environment:
|
|
|
106
133
|
CAREERFLOW_BASE_URL Required. Your CareerFlow API root
|
|
107
134
|
CAREERFLOW_COMPANY_ID Optional. Default company, so tools need no company_id
|
|
108
135
|
CAREERFLOW_TIMEOUT_MS Optional. Request timeout, default 30000
|
|
136
|
+
CAREERFLOW_PROFILE Optional. worklog (record_work and the task/time tools
|
|
137
|
+
it needs, ~12 tools) or full (default)
|
|
109
138
|
CAREERFLOW_GROUPS Optional. Comma-separated tool groups to register
|
|
110
139
|
(${toolGroups.map((g) => g.name).join(", ")})
|
|
111
140
|
CAREERFLOW_EXCLUDE_GROUPS Optional. Comma-separated groups to leave out
|
|
@@ -145,88 +174,130 @@ function selectGroups(env) {
|
|
|
145
174
|
}
|
|
146
175
|
return selected;
|
|
147
176
|
}
|
|
177
|
+
/** Tools with a real, hard-to-undo effect; the instructions name the registered ones. */
|
|
178
|
+
const IRREVERSIBLE_TOOLS = [
|
|
179
|
+
"send_message",
|
|
180
|
+
"create_administrative_note",
|
|
181
|
+
"message_form_submission",
|
|
182
|
+
"create_user",
|
|
183
|
+
"set_user_status",
|
|
184
|
+
"set_user_role",
|
|
185
|
+
"request_benefit_fund_loan",
|
|
186
|
+
"update_benefit_fund_loan_status",
|
|
187
|
+
"pay_benefit_fund_loan_installment",
|
|
188
|
+
"respond_to_lottery_win"
|
|
189
|
+
];
|
|
190
|
+
function selectProfile(env) {
|
|
191
|
+
const name = (env.CAREERFLOW_PROFILE ?? "").trim().toLowerCase() || "full";
|
|
192
|
+
if (!(name in PROFILES)) {
|
|
193
|
+
throw new Error(`Unknown CAREERFLOW_PROFILE "${name}". Valid profiles: ${Object.keys(PROFILES).join(", ")}.`);
|
|
194
|
+
}
|
|
195
|
+
return { name, tools: PROFILES[name] };
|
|
196
|
+
}
|
|
197
|
+
/** Startup identity, so the model does not spend a whoami call per session. Fails open. */
|
|
198
|
+
async function fetchIdentity(client) {
|
|
199
|
+
try {
|
|
200
|
+
const response = await client.get("users/profile", {}, { timeoutMs: 3000, noRetry: true });
|
|
201
|
+
const user = (response.data ?? {});
|
|
202
|
+
const id = user.id !== undefined ? Number(user.id) : undefined;
|
|
203
|
+
const name = [user.firstname, user.lastname].filter(Boolean).join(" ") || user.staff_number_with_prefix;
|
|
204
|
+
return { id, name: name || undefined };
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function buildInstructions(options) {
|
|
211
|
+
const has = new Set(options.registered);
|
|
212
|
+
const lines = [
|
|
213
|
+
"CareerFlow workplace platform. Naming: an API project is what the UI calls a board (تابلو, " +
|
|
214
|
+
"type normal) or a project (پروژه, type special); an API board is a column the UI calls a list (لیست)."
|
|
215
|
+
];
|
|
216
|
+
if (options.sqlAvailable) {
|
|
217
|
+
lines.push("Reads, including id lookups, go through run_company_sql over the v_ai_* views; call " +
|
|
218
|
+
"list_company_sql_schema first.");
|
|
219
|
+
}
|
|
220
|
+
if (options.identity?.id !== undefined) {
|
|
221
|
+
const who = options.identity.name ? ` (${options.identity.name})` : "";
|
|
222
|
+
const company = options.companyId !== undefined ? `, default company ${options.companyId}` : "";
|
|
223
|
+
lines.push(`You are user ${options.identity.id}${who}${company}.`);
|
|
224
|
+
}
|
|
225
|
+
if (options.companyId === undefined && has.has("whoami")) {
|
|
226
|
+
lines.push("No default company is set: whoami lists the user's company ids.");
|
|
227
|
+
}
|
|
228
|
+
if (options.workspaceLine && has.has("record_work")) {
|
|
229
|
+
lines.push(options.workspaceLine);
|
|
230
|
+
}
|
|
231
|
+
else if (has.has("record_work")) {
|
|
232
|
+
lines.push("To log finished work, use record_work. No project is saved for this folder yet: ask the user " +
|
|
233
|
+
"which board or project (UI names) to use; the first record_work (or set_workspace_project) saves it.");
|
|
234
|
+
}
|
|
235
|
+
const irreversible = IRREVERSIBLE_TOOLS.filter((name) => has.has(name));
|
|
236
|
+
if (irreversible.length) {
|
|
237
|
+
lines.push(`Confirm with the user before calling ${irreversible.join(", ")}: their effect is real and hard to undo.`);
|
|
238
|
+
}
|
|
239
|
+
lines.push("A 403 means the token lacks a scope: tell the user which to add in Settings > Access Tokens.");
|
|
240
|
+
return lines.join("\n");
|
|
241
|
+
}
|
|
148
242
|
async function serve() {
|
|
149
243
|
const config = loadConfig();
|
|
150
244
|
const client = new CareerFlowClient(config);
|
|
151
245
|
const groups = selectGroups(process.env);
|
|
246
|
+
const profile = selectProfile(process.env);
|
|
152
247
|
// what this user's role and token can actually reach. null when the answer is
|
|
153
248
|
// unavailable (older API, unreachable host, opted out), which registers
|
|
154
249
|
// everything and leaves enforcement to the API, as before.
|
|
155
250
|
const skipCapabilities = ["1", "true", "yes"].includes((process.env.CAREERFLOW_ALL_TOOLS ?? "").trim().toLowerCase());
|
|
156
|
-
const capabilities =
|
|
251
|
+
const [capabilities, identity] = await Promise.all([
|
|
252
|
+
skipCapabilities ? null : fetchCapabilities(client, config.companyId),
|
|
253
|
+
fetchIdentity(client)
|
|
254
|
+
]);
|
|
255
|
+
primeCurrentUserId(identity?.id);
|
|
157
256
|
// a user who can run company SQL reads anything out of the v_ai_* views, so
|
|
158
257
|
// the fixed read-only tools that duplicate them are dropped in their favor —
|
|
159
258
|
// but only when those SQL tools are really being registered, never when the
|
|
160
|
-
// company-sql group
|
|
259
|
+
// company-sql group or the profile filtered them out, or the user cannot run
|
|
260
|
+
// SQL at all
|
|
161
261
|
const keepReadTools = ["1", "true", "yes"].includes((process.env.CAREERFLOW_KEEP_READ_TOOLS ?? "").trim().toLowerCase());
|
|
162
262
|
const sqlAvailable = !keepReadTools &&
|
|
163
263
|
groups.some((group) => group.name === "company-sql") &&
|
|
264
|
+
(!profile.tools || profile.tools.has("run_company_sql")) &&
|
|
164
265
|
Boolean(capabilities && allows(capabilities.capabilities, "company:manage"));
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"v_ai_kanban_boards.\n"
|
|
182
|
-
: "- Naming: the API and the UI name kanban things differently. An API project is the " +
|
|
183
|
-
"container; an API board is a column of tasks inside a project, which the UI calls a " +
|
|
184
|
-
"'list' (لیست). The UI itself calls projects of type 'normal' 'boards' (تابلو) and type " +
|
|
185
|
-
"'special' 'projects' (پروژه). So when a user says 'board' they usually mean an API " +
|
|
186
|
-
"project (type normal) — find it with list_projects and check the returned type; when " +
|
|
187
|
-
"they say 'list' they mean an API board — find it with list_boards.\n" +
|
|
188
|
-
"- Task writes need project and board ids: resolve them with list_projects and list_boards.\n" +
|
|
189
|
-
"- CRM writes need pipeline and stage ids: resolve them with crm_list_pipelines and crm_list_stages.\n" +
|
|
190
|
-
"- Resolve people to user ids with find_user or list_project_members before assigning work.\n";
|
|
191
|
-
const server = new McpServer({
|
|
192
|
-
name: "careerflow",
|
|
193
|
-
version
|
|
194
|
-
}, {
|
|
195
|
-
instructions: "Tools for CareerFlow, a workplace platform: tasks and kanban boards, projects, time " +
|
|
196
|
-
"tracking, chat, CRM (contacts/deals/activities), HR (payroll, disciplinary and " +
|
|
197
|
-
"administrative notes, careers, onboarding), the benefit fund (loans and lotteries), " +
|
|
198
|
-
"forms, CMS, and company/user administration.\n\n" +
|
|
199
|
-
"Guidance:\n" +
|
|
200
|
-
"- Call whoami first when a request depends on who 'I' or 'me' is, or before any tool " +
|
|
201
|
-
"that takes company_id — whoami's response already includes every company the user " +
|
|
202
|
-
"belongs to (and resolves company_id outright if there's only one), so don't call a " +
|
|
203
|
-
"company-scoped tool without a company_id and wait for it to fail first.\n" +
|
|
204
|
-
resolverGuidance +
|
|
205
|
-
"- Some tools have a real, hard-to-undo effect and say so in their own description — " +
|
|
206
|
-
"send_message, create_administrative_note, and message_form_submission deliver to real " +
|
|
207
|
-
"people; create_user, set_user_status, and set_user_role change real accounts; " +
|
|
208
|
-
"request_benefit_fund_loan, update_benefit_fund_loan_status, " +
|
|
209
|
-
"pay_benefit_fund_loan_installment, and respond_to_lottery_win touch real money. Confirm " +
|
|
210
|
-
"details with the user before calling any of these.\n" +
|
|
211
|
-
"- A 403 means the token lacks a scope; tell the user which scope to add in " +
|
|
212
|
-
"Settings > Access Tokens rather than retrying."
|
|
266
|
+
// Dry run against a recorder: the instructions name only tools that will
|
|
267
|
+
// really be registered, and they must be fixed before the server exists.
|
|
268
|
+
const dryReport = { registered: [], skipped: [], skippedForSql: [] };
|
|
269
|
+
const recorder = gateServer({ registerTool: () => undefined }, capabilities?.capabilities ?? null, dryReport, sqlAvailable, profile.tools);
|
|
270
|
+
for (const group of groups) {
|
|
271
|
+
group.register(recorder, client);
|
|
272
|
+
}
|
|
273
|
+
const workspace = findWorkspace(process.cwd());
|
|
274
|
+
const server = new McpServer({ name: "careerflow", version }, {
|
|
275
|
+
instructions: buildInstructions({
|
|
276
|
+
registered: dryReport.registered,
|
|
277
|
+
sqlAvailable,
|
|
278
|
+
identity,
|
|
279
|
+
companyId: config.companyId,
|
|
280
|
+
workspaceLine: describeWorkspace(workspace)
|
|
281
|
+
})
|
|
213
282
|
});
|
|
214
283
|
const report = { registered: [], skipped: [], skippedForSql: [] };
|
|
215
|
-
const gated = gateServer(server, capabilities?.capabilities ?? null, report, sqlAvailable);
|
|
284
|
+
const gated = gateServer(server, capabilities?.capabilities ?? null, report, sqlAvailable, profile.tools);
|
|
216
285
|
for (const group of groups) {
|
|
217
286
|
group.register(gated, client);
|
|
218
287
|
}
|
|
288
|
+
registerPrompts(server, new Set(report.registered));
|
|
219
289
|
const transport = new StdioServerTransport();
|
|
220
290
|
await server.connect(transport);
|
|
221
291
|
// stdout carries the MCP protocol stream, so anything human-facing must go to
|
|
222
292
|
// stderr or it corrupts the transport
|
|
223
293
|
const reach = capabilities
|
|
224
294
|
? `, tools: ${report.registered.length} registered / ${report.skipped.length} hidden by ${capabilities.auth === "token" ? "role + token scopes" : "role"}`
|
|
225
|
-
:
|
|
295
|
+
: `, tools: ${report.registered.length} registered`;
|
|
226
296
|
const sqlNote = report.skippedForSql.length
|
|
227
297
|
? `, ${report.skippedForSql.length} read-only tools replaced by run_company_sql`
|
|
228
298
|
: "";
|
|
229
|
-
|
|
299
|
+
const workspaceNote = workspace ? `, workspace: project ${workspace.entry.project_id}` : "";
|
|
300
|
+
console.error(`careerflow-mcp connected (api: ${config.baseUrl}, profile: ${profile.name}, groups: ${groups.map((g) => g.name).join(", ")}${reach}${sqlNote}${workspaceNote})`);
|
|
230
301
|
}
|
|
231
302
|
const [, , command] = process.argv;
|
|
232
303
|
if (command === "--help" || command === "-h") {
|
|
@@ -243,6 +314,14 @@ else if (command === "init") {
|
|
|
243
314
|
process.exit(1);
|
|
244
315
|
});
|
|
245
316
|
}
|
|
317
|
+
else if (command === "link") {
|
|
318
|
+
import("./setup.js")
|
|
319
|
+
.then(({ runLink }) => runLink(process.argv.slice(3)))
|
|
320
|
+
.catch((error) => {
|
|
321
|
+
console.error(`careerflow-mcp link failed: ${error.message}`);
|
|
322
|
+
process.exit(1);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
246
325
|
else if (command === "remove") {
|
|
247
326
|
import("./setup.js")
|
|
248
327
|
.then(({ runRemove }) => runRemove(process.argv.slice(3)))
|