@fload-ai/mcp 0.11.0 → 0.12.2
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 +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +37 -10
- package/dist/api-client.js.map +2 -2
- package/dist/bin.js +147 -15
- package/dist/bin.js.map +3 -3
- package/dist/index.js +147 -15
- package/dist/index.js.map +3 -3
- package/dist/public-errors.d.ts +2 -0
- package/dist/public-errors.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/tools/actions.d.ts +1 -0
- package/dist/tools/actions.d.ts.map +1 -1
- package/dist/tools/chat.d.ts +12 -0
- package/dist/tools/chat.d.ts.map +1 -1
- package/dist/tools/index.js +108 -4
- package/dist/tools/index.js.map +2 -2
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +20 -19
package/dist/bin.js
CHANGED
|
@@ -1253,6 +1253,21 @@ function publicMcpErrorMessage(message, fallbackMessage = "Fload could not compl
|
|
|
1253
1253
|
}
|
|
1254
1254
|
return normalized;
|
|
1255
1255
|
}
|
|
1256
|
+
var SCOPE_PATTERN = /^(read|write):[a-z]{2,20}$/;
|
|
1257
|
+
function insufficientScopeOf(status, wwwAuthenticate, body) {
|
|
1258
|
+
if (status !== 403) return null;
|
|
1259
|
+
const fromHeader = wwwAuthenticate?.includes("insufficient_scope") ? /scope="([^"]*)"/.exec(wwwAuthenticate)?.[1] : void 0;
|
|
1260
|
+
const record = body && typeof body === "object" ? body : {};
|
|
1261
|
+
if (fromHeader === void 0 && record.error !== "insufficient_scope") {
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
const scope = fromHeader ?? (typeof record.scope === "string" ? record.scope : "");
|
|
1265
|
+
return SCOPE_PATTERN.test(scope) ? scope : "";
|
|
1266
|
+
}
|
|
1267
|
+
function insufficientScopeMessage(scope) {
|
|
1268
|
+
const permission = scope ? `the ${scope} permission` : "the permission this needs";
|
|
1269
|
+
return `This API key does not have ${permission}. Create a key that includes it in Fload: Settings \u2192 API keys.`;
|
|
1270
|
+
}
|
|
1256
1271
|
|
|
1257
1272
|
// src/tools/actions.ts
|
|
1258
1273
|
var listPendingActionsSchema = z9.object({
|
|
@@ -1263,7 +1278,10 @@ var listPendingActionsSchema = z9.object({
|
|
|
1263
1278
|
limit: z9.number().int().min(1).max(100).default(50).describe("Maximum number of actions to return")
|
|
1264
1279
|
});
|
|
1265
1280
|
var approveActionSchema = z9.object({
|
|
1266
|
-
actionId: z9.string().describe("The inbox item ID to approve (from list_pending_actions)")
|
|
1281
|
+
actionId: z9.string().describe("The inbox item ID to approve (from list_pending_actions)"),
|
|
1282
|
+
wholeGroup: z9.boolean().optional().describe(
|
|
1283
|
+
"Approve every language of this item's card at once: the items still waiting for approval that share its proposalBatch (one listing change across locales, as the inbox shows it as one card with one Approve). Languages that cannot be approved now are left as they are and listed."
|
|
1284
|
+
)
|
|
1267
1285
|
});
|
|
1268
1286
|
var rejectActionSchema = z9.object({
|
|
1269
1287
|
actionId: z9.string().describe("The inbox item ID to reject (from list_pending_actions)"),
|
|
@@ -1368,6 +1386,10 @@ function refusedMessage(result) {
|
|
|
1368
1386
|
}
|
|
1369
1387
|
async function approveAction(input, client) {
|
|
1370
1388
|
try {
|
|
1389
|
+
if (input.wholeGroup) {
|
|
1390
|
+
const grouped = await approveGroup(client, input.actionId);
|
|
1391
|
+
if (grouped) return grouped;
|
|
1392
|
+
}
|
|
1371
1393
|
const { command, result } = await commandItem(
|
|
1372
1394
|
client,
|
|
1373
1395
|
input.actionId,
|
|
@@ -1390,6 +1412,80 @@ async function approveAction(input, client) {
|
|
|
1390
1412
|
return toolError(error);
|
|
1391
1413
|
}
|
|
1392
1414
|
}
|
|
1415
|
+
async function groupOf(client, item) {
|
|
1416
|
+
if (!item.proposalBatch || item.status !== "needs_approval") return [item];
|
|
1417
|
+
const isSibling = (other) => typeof other === "object" && other !== null && other.status === "needs_approval" && other.proposalBatch === item.proposalBatch && other.assetId === item.assetId && other.id !== item.id;
|
|
1418
|
+
const siblings = [];
|
|
1419
|
+
let cursor;
|
|
1420
|
+
do {
|
|
1421
|
+
const response = await client.get("/api/actions/items", {
|
|
1422
|
+
view: "open",
|
|
1423
|
+
limit: 100,
|
|
1424
|
+
...item.assetId ? { assetId: item.assetId } : {},
|
|
1425
|
+
...cursor ? { cursor } : {}
|
|
1426
|
+
});
|
|
1427
|
+
siblings.push(...(response.items ?? []).filter(isSibling));
|
|
1428
|
+
cursor = response.nextCursor;
|
|
1429
|
+
} while (cursor);
|
|
1430
|
+
return [item, ...siblings];
|
|
1431
|
+
}
|
|
1432
|
+
async function approveGroup(client, actionId) {
|
|
1433
|
+
const detail = await client.get(
|
|
1434
|
+
`/api/actions/items/${encodeURIComponent(actionId)}`
|
|
1435
|
+
);
|
|
1436
|
+
if (!detail.item) throw new Error("Action not found");
|
|
1437
|
+
const group = await groupOf(client, detail.item);
|
|
1438
|
+
if (group.length <= 1) return null;
|
|
1439
|
+
const approvable = group.filter(
|
|
1440
|
+
(item) => item.allowedCommands?.includes("approve")
|
|
1441
|
+
);
|
|
1442
|
+
const skipped = group.filter((item) => !approvable.includes(item)).map((item) => item.id);
|
|
1443
|
+
if (approvable.length === 0)
|
|
1444
|
+
return toolText(
|
|
1445
|
+
{
|
|
1446
|
+
success: false,
|
|
1447
|
+
actionId,
|
|
1448
|
+
skipped,
|
|
1449
|
+
message: "Nothing in this card can be approved right now."
|
|
1450
|
+
},
|
|
1451
|
+
true
|
|
1452
|
+
);
|
|
1453
|
+
const answer = await client.postForAnswer(
|
|
1454
|
+
"/api/actions/commands",
|
|
1455
|
+
{
|
|
1456
|
+
command: "approve",
|
|
1457
|
+
idempotencyKey: `mcp:approve-group:${actionId}:${randomUUID()}`,
|
|
1458
|
+
targets: approvable.map((item) => ({
|
|
1459
|
+
itemId: item.id,
|
|
1460
|
+
...item.currentRevisionId ? { revisionId: item.currentRevisionId } : {}
|
|
1461
|
+
}))
|
|
1462
|
+
}
|
|
1463
|
+
);
|
|
1464
|
+
const results = (answer.body?.results ?? []).map((result) => ({
|
|
1465
|
+
itemId: result.itemId,
|
|
1466
|
+
result: result.result,
|
|
1467
|
+
...result.error ? {
|
|
1468
|
+
error: publicMcpErrorMessage(
|
|
1469
|
+
result.error,
|
|
1470
|
+
"Fload could not apply this change."
|
|
1471
|
+
)
|
|
1472
|
+
} : {}
|
|
1473
|
+
}));
|
|
1474
|
+
const approved = results.filter(
|
|
1475
|
+
(r) => r.result === "applied" || r.result === "replayed"
|
|
1476
|
+
).length;
|
|
1477
|
+
return toolText(
|
|
1478
|
+
{
|
|
1479
|
+
success: approved > 0,
|
|
1480
|
+
actionId,
|
|
1481
|
+
approved,
|
|
1482
|
+
results,
|
|
1483
|
+
...skipped.length ? { skipped } : {},
|
|
1484
|
+
message: approved > 0 ? `Approved ${approved} of ${group.length}. Fload delivers them after a short undo window; the inbox shows where each is.` : "The approval could not be recorded."
|
|
1485
|
+
},
|
|
1486
|
+
approved === 0
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1393
1489
|
async function rejectAction(input, client) {
|
|
1394
1490
|
try {
|
|
1395
1491
|
const { command, result } = await commandItem(
|
|
@@ -1831,9 +1927,26 @@ async function getConversationMessages(input, client) {
|
|
|
1831
1927
|
};
|
|
1832
1928
|
}
|
|
1833
1929
|
}
|
|
1930
|
+
var FREE_CONVERSATION_LABEL = "Free: your first conversation";
|
|
1931
|
+
var FREE_CONVERSATION_ENDED_NOTICE = "Your free first conversation has ended; messages now use credits.";
|
|
1932
|
+
function answerCostOf(data) {
|
|
1933
|
+
if (!data || typeof data !== "object") return null;
|
|
1934
|
+
const usage = data;
|
|
1935
|
+
const free = usage.freeConversation;
|
|
1936
|
+
if (free && typeof free.messagesLeft === "number") {
|
|
1937
|
+
return {
|
|
1938
|
+
free: true,
|
|
1939
|
+
label: FREE_CONVERSATION_LABEL,
|
|
1940
|
+
messagesLeft: free.messagesLeft,
|
|
1941
|
+
...free.ended === true ? { notice: FREE_CONVERSATION_ENDED_NOTICE } : {}
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
return typeof usage.credits === "number" ? { free: false, credits: usage.credits } : null;
|
|
1945
|
+
}
|
|
1834
1946
|
function parseUiMessageStream(raw) {
|
|
1835
1947
|
let reply = "";
|
|
1836
1948
|
const toolsUsed = [];
|
|
1949
|
+
let cost = null;
|
|
1837
1950
|
for (const line of raw.split("\n")) {
|
|
1838
1951
|
if (!line.startsWith("data:")) continue;
|
|
1839
1952
|
const payload = line.slice(5).trim();
|
|
@@ -1844,11 +1957,13 @@ function parseUiMessageStream(raw) {
|
|
|
1844
1957
|
reply += String(event.delta ?? event.textDelta ?? "");
|
|
1845
1958
|
} else if (typeof event.type === "string" && event.type === "tool-input-start" && typeof event.toolName === "string") {
|
|
1846
1959
|
toolsUsed.push(event.toolName);
|
|
1960
|
+
} else if (event.type === "data-usage") {
|
|
1961
|
+
cost = answerCostOf(event.data) ?? cost;
|
|
1847
1962
|
}
|
|
1848
1963
|
} catch {
|
|
1849
1964
|
}
|
|
1850
1965
|
}
|
|
1851
|
-
return { reply, toolsUsed };
|
|
1966
|
+
return { reply, toolsUsed, cost };
|
|
1852
1967
|
}
|
|
1853
1968
|
async function sendChatMessage(input, client) {
|
|
1854
1969
|
try {
|
|
@@ -1889,7 +2004,7 @@ async function sendChatMessage(input, client) {
|
|
|
1889
2004
|
};
|
|
1890
2005
|
}
|
|
1891
2006
|
const raw = await client.postStream("/api/chat", body);
|
|
1892
|
-
const { reply, toolsUsed } = parseUiMessageStream(raw);
|
|
2007
|
+
const { reply, toolsUsed, cost } = parseUiMessageStream(raw);
|
|
1893
2008
|
return {
|
|
1894
2009
|
content: [
|
|
1895
2010
|
{
|
|
@@ -1898,6 +2013,8 @@ async function sendChatMessage(input, client) {
|
|
|
1898
2013
|
conversationId,
|
|
1899
2014
|
reply: reply || "The assistant returned no text response.",
|
|
1900
2015
|
toolsUsed,
|
|
2016
|
+
// FLO-2669: the credits the answer used, or that it was free.
|
|
2017
|
+
...cost ? { cost } : {},
|
|
1901
2018
|
tip: "Pass this conversationId to continue the conversation or to get_conversation_messages for the full transcript."
|
|
1902
2019
|
})
|
|
1903
2020
|
}
|
|
@@ -2229,19 +2346,22 @@ function registerTools(server, client, options = {}) {
|
|
|
2229
2346
|
tool(
|
|
2230
2347
|
"send_chat_message",
|
|
2231
2348
|
"Send chat message",
|
|
2232
|
-
"Send a message to the Fload AI chat assistant. Starts a new conversation if no conversationId is provided, or continues an existing one. Optionally specify an agentType to route to a specialized agent (review, aso). Adds a message to your chat history \u2014 not publicly visible.",
|
|
2349
|
+
"Send a message to the Fload AI chat assistant. Starts a new conversation if no conversationId is provided, or continues an existing one. Optionally specify an agentType to route to a specialized agent (review, aso). Adds a message to your chat history \u2014 not publicly visible. The result's `cost` says what the answer used: `credits`, or `free: true` with the free answers left when a new organization's free first conversation carried it (and a `notice` on the answer that ended it).",
|
|
2233
2350
|
sendChatMessageSchema,
|
|
2234
2351
|
sendChatMessage,
|
|
2235
2352
|
{ readOnlyHint: false, destructiveHint: false, openWorldHint: true }
|
|
2236
2353
|
);
|
|
2237
2354
|
}
|
|
2238
2355
|
|
|
2356
|
+
// src/version.ts
|
|
2357
|
+
var FLOAD_MCP_VERSION = "0.12.2";
|
|
2358
|
+
|
|
2239
2359
|
// src/server.ts
|
|
2240
2360
|
async function createMcpServer(_config, client) {
|
|
2241
2361
|
console.error("[Fload MCP] Server initializing...");
|
|
2242
2362
|
const server = new McpServer({
|
|
2243
2363
|
name: "fload",
|
|
2244
|
-
version:
|
|
2364
|
+
version: FLOAD_MCP_VERSION
|
|
2245
2365
|
});
|
|
2246
2366
|
registerTools(server, client);
|
|
2247
2367
|
console.error("[Fload MCP] Registered tools");
|
|
@@ -2249,6 +2369,20 @@ async function createMcpServer(_config, client) {
|
|
|
2249
2369
|
}
|
|
2250
2370
|
|
|
2251
2371
|
// src/api-client.ts
|
|
2372
|
+
function refusalError(response, error) {
|
|
2373
|
+
const scope = insufficientScopeOf(
|
|
2374
|
+
response.status,
|
|
2375
|
+
response.headers.get("www-authenticate"),
|
|
2376
|
+
error
|
|
2377
|
+
);
|
|
2378
|
+
if (scope !== null) return new Error(insufficientScopeMessage(scope));
|
|
2379
|
+
return new Error(
|
|
2380
|
+
publicMcpErrorMessage(
|
|
2381
|
+
error.publicMessage || error.message || response.statusText,
|
|
2382
|
+
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
2383
|
+
)
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2252
2386
|
var FloadApiClient = class {
|
|
2253
2387
|
constructor(baseUrl, apiKey) {
|
|
2254
2388
|
this.baseUrl = baseUrl;
|
|
@@ -2269,11 +2403,7 @@ var FloadApiClient = class {
|
|
|
2269
2403
|
});
|
|
2270
2404
|
if (!response.ok) {
|
|
2271
2405
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
2272
|
-
|
|
2273
|
-
error.publicMessage || error.message || response.statusText,
|
|
2274
|
-
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
2275
|
-
);
|
|
2276
|
-
throw new Error(safeError);
|
|
2406
|
+
throw refusalError(response, error);
|
|
2277
2407
|
}
|
|
2278
2408
|
return response.json();
|
|
2279
2409
|
}
|
|
@@ -2309,6 +2439,12 @@ var FloadApiClient = class {
|
|
|
2309
2439
|
body: body ? JSON.stringify(body) : void 0
|
|
2310
2440
|
});
|
|
2311
2441
|
const parsed = await response.json().catch(() => null);
|
|
2442
|
+
const scope = insufficientScopeOf(
|
|
2443
|
+
response.status,
|
|
2444
|
+
response.headers.get("www-authenticate"),
|
|
2445
|
+
parsed
|
|
2446
|
+
);
|
|
2447
|
+
if (scope !== null) throw new Error(insufficientScopeMessage(scope));
|
|
2312
2448
|
return { ok: response.ok, status: response.status, body: parsed };
|
|
2313
2449
|
}
|
|
2314
2450
|
async patch(path, body) {
|
|
@@ -2337,11 +2473,7 @@ var FloadApiClient = class {
|
|
|
2337
2473
|
});
|
|
2338
2474
|
if (!response.ok) {
|
|
2339
2475
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
2340
|
-
|
|
2341
|
-
error.publicMessage || error.message || response.statusText,
|
|
2342
|
-
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
2343
|
-
);
|
|
2344
|
-
throw new Error(safeError);
|
|
2476
|
+
throw refusalError(response, error);
|
|
2345
2477
|
}
|
|
2346
2478
|
return response.text();
|
|
2347
2479
|
}
|