@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/index.js
CHANGED
|
@@ -20,8 +20,37 @@ function publicMcpErrorMessage(message, fallbackMessage = "Fload could not compl
|
|
|
20
20
|
}
|
|
21
21
|
return normalized;
|
|
22
22
|
}
|
|
23
|
+
var SCOPE_PATTERN = /^(read|write):[a-z]{2,20}$/;
|
|
24
|
+
function insufficientScopeOf(status, wwwAuthenticate, body) {
|
|
25
|
+
if (status !== 403) return null;
|
|
26
|
+
const fromHeader = wwwAuthenticate?.includes("insufficient_scope") ? /scope="([^"]*)"/.exec(wwwAuthenticate)?.[1] : void 0;
|
|
27
|
+
const record = body && typeof body === "object" ? body : {};
|
|
28
|
+
if (fromHeader === void 0 && record.error !== "insufficient_scope") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const scope = fromHeader ?? (typeof record.scope === "string" ? record.scope : "");
|
|
32
|
+
return SCOPE_PATTERN.test(scope) ? scope : "";
|
|
33
|
+
}
|
|
34
|
+
function insufficientScopeMessage(scope) {
|
|
35
|
+
const permission = scope ? `the ${scope} permission` : "the permission this needs";
|
|
36
|
+
return `This API key does not have ${permission}. Create a key that includes it in Fload: Settings \u2192 API keys.`;
|
|
37
|
+
}
|
|
23
38
|
|
|
24
39
|
// src/api-client.ts
|
|
40
|
+
function refusalError(response, error) {
|
|
41
|
+
const scope = insufficientScopeOf(
|
|
42
|
+
response.status,
|
|
43
|
+
response.headers.get("www-authenticate"),
|
|
44
|
+
error
|
|
45
|
+
);
|
|
46
|
+
if (scope !== null) return new Error(insufficientScopeMessage(scope));
|
|
47
|
+
return new Error(
|
|
48
|
+
publicMcpErrorMessage(
|
|
49
|
+
error.publicMessage || error.message || response.statusText,
|
|
50
|
+
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
25
54
|
var FloadApiClient = class {
|
|
26
55
|
constructor(baseUrl, apiKey) {
|
|
27
56
|
this.baseUrl = baseUrl;
|
|
@@ -42,11 +71,7 @@ var FloadApiClient = class {
|
|
|
42
71
|
});
|
|
43
72
|
if (!response.ok) {
|
|
44
73
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
45
|
-
|
|
46
|
-
error.publicMessage || error.message || response.statusText,
|
|
47
|
-
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
48
|
-
);
|
|
49
|
-
throw new Error(safeError);
|
|
74
|
+
throw refusalError(response, error);
|
|
50
75
|
}
|
|
51
76
|
return response.json();
|
|
52
77
|
}
|
|
@@ -82,6 +107,12 @@ var FloadApiClient = class {
|
|
|
82
107
|
body: body ? JSON.stringify(body) : void 0
|
|
83
108
|
});
|
|
84
109
|
const parsed = await response.json().catch(() => null);
|
|
110
|
+
const scope = insufficientScopeOf(
|
|
111
|
+
response.status,
|
|
112
|
+
response.headers.get("www-authenticate"),
|
|
113
|
+
parsed
|
|
114
|
+
);
|
|
115
|
+
if (scope !== null) throw new Error(insufficientScopeMessage(scope));
|
|
85
116
|
return { ok: response.ok, status: response.status, body: parsed };
|
|
86
117
|
}
|
|
87
118
|
async patch(path, body) {
|
|
@@ -110,11 +141,7 @@ var FloadApiClient = class {
|
|
|
110
141
|
});
|
|
111
142
|
if (!response.ok) {
|
|
112
143
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
113
|
-
|
|
114
|
-
error.publicMessage || error.message || response.statusText,
|
|
115
|
-
response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
|
|
116
|
-
);
|
|
117
|
-
throw new Error(safeError);
|
|
144
|
+
throw refusalError(response, error);
|
|
118
145
|
}
|
|
119
146
|
return response.text();
|
|
120
147
|
}
|
|
@@ -1318,7 +1345,10 @@ var listPendingActionsSchema = z8.object({
|
|
|
1318
1345
|
limit: z8.number().int().min(1).max(100).default(50).describe("Maximum number of actions to return")
|
|
1319
1346
|
});
|
|
1320
1347
|
var approveActionSchema = z8.object({
|
|
1321
|
-
actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)")
|
|
1348
|
+
actionId: z8.string().describe("The inbox item ID to approve (from list_pending_actions)"),
|
|
1349
|
+
wholeGroup: z8.boolean().optional().describe(
|
|
1350
|
+
"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."
|
|
1351
|
+
)
|
|
1322
1352
|
});
|
|
1323
1353
|
var rejectActionSchema = z8.object({
|
|
1324
1354
|
actionId: z8.string().describe("The inbox item ID to reject (from list_pending_actions)"),
|
|
@@ -1423,6 +1453,10 @@ function refusedMessage(result) {
|
|
|
1423
1453
|
}
|
|
1424
1454
|
async function approveAction(input, client) {
|
|
1425
1455
|
try {
|
|
1456
|
+
if (input.wholeGroup) {
|
|
1457
|
+
const grouped = await approveGroup(client, input.actionId);
|
|
1458
|
+
if (grouped) return grouped;
|
|
1459
|
+
}
|
|
1426
1460
|
const { command, result } = await commandItem(
|
|
1427
1461
|
client,
|
|
1428
1462
|
input.actionId,
|
|
@@ -1445,6 +1479,80 @@ async function approveAction(input, client) {
|
|
|
1445
1479
|
return toolError(error);
|
|
1446
1480
|
}
|
|
1447
1481
|
}
|
|
1482
|
+
async function groupOf(client, item) {
|
|
1483
|
+
if (!item.proposalBatch || item.status !== "needs_approval") return [item];
|
|
1484
|
+
const isSibling = (other) => typeof other === "object" && other !== null && other.status === "needs_approval" && other.proposalBatch === item.proposalBatch && other.assetId === item.assetId && other.id !== item.id;
|
|
1485
|
+
const siblings = [];
|
|
1486
|
+
let cursor;
|
|
1487
|
+
do {
|
|
1488
|
+
const response = await client.get("/api/actions/items", {
|
|
1489
|
+
view: "open",
|
|
1490
|
+
limit: 100,
|
|
1491
|
+
...item.assetId ? { assetId: item.assetId } : {},
|
|
1492
|
+
...cursor ? { cursor } : {}
|
|
1493
|
+
});
|
|
1494
|
+
siblings.push(...(response.items ?? []).filter(isSibling));
|
|
1495
|
+
cursor = response.nextCursor;
|
|
1496
|
+
} while (cursor);
|
|
1497
|
+
return [item, ...siblings];
|
|
1498
|
+
}
|
|
1499
|
+
async function approveGroup(client, actionId) {
|
|
1500
|
+
const detail = await client.get(
|
|
1501
|
+
`/api/actions/items/${encodeURIComponent(actionId)}`
|
|
1502
|
+
);
|
|
1503
|
+
if (!detail.item) throw new Error("Action not found");
|
|
1504
|
+
const group = await groupOf(client, detail.item);
|
|
1505
|
+
if (group.length <= 1) return null;
|
|
1506
|
+
const approvable = group.filter(
|
|
1507
|
+
(item) => item.allowedCommands?.includes("approve")
|
|
1508
|
+
);
|
|
1509
|
+
const skipped = group.filter((item) => !approvable.includes(item)).map((item) => item.id);
|
|
1510
|
+
if (approvable.length === 0)
|
|
1511
|
+
return toolText(
|
|
1512
|
+
{
|
|
1513
|
+
success: false,
|
|
1514
|
+
actionId,
|
|
1515
|
+
skipped,
|
|
1516
|
+
message: "Nothing in this card can be approved right now."
|
|
1517
|
+
},
|
|
1518
|
+
true
|
|
1519
|
+
);
|
|
1520
|
+
const answer = await client.postForAnswer(
|
|
1521
|
+
"/api/actions/commands",
|
|
1522
|
+
{
|
|
1523
|
+
command: "approve",
|
|
1524
|
+
idempotencyKey: `mcp:approve-group:${actionId}:${randomUUID()}`,
|
|
1525
|
+
targets: approvable.map((item) => ({
|
|
1526
|
+
itemId: item.id,
|
|
1527
|
+
...item.currentRevisionId ? { revisionId: item.currentRevisionId } : {}
|
|
1528
|
+
}))
|
|
1529
|
+
}
|
|
1530
|
+
);
|
|
1531
|
+
const results = (answer.body?.results ?? []).map((result) => ({
|
|
1532
|
+
itemId: result.itemId,
|
|
1533
|
+
result: result.result,
|
|
1534
|
+
...result.error ? {
|
|
1535
|
+
error: publicMcpErrorMessage(
|
|
1536
|
+
result.error,
|
|
1537
|
+
"Fload could not apply this change."
|
|
1538
|
+
)
|
|
1539
|
+
} : {}
|
|
1540
|
+
}));
|
|
1541
|
+
const approved = results.filter(
|
|
1542
|
+
(r) => r.result === "applied" || r.result === "replayed"
|
|
1543
|
+
).length;
|
|
1544
|
+
return toolText(
|
|
1545
|
+
{
|
|
1546
|
+
success: approved > 0,
|
|
1547
|
+
actionId,
|
|
1548
|
+
approved,
|
|
1549
|
+
results,
|
|
1550
|
+
...skipped.length ? { skipped } : {},
|
|
1551
|
+
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."
|
|
1552
|
+
},
|
|
1553
|
+
approved === 0
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1448
1556
|
async function rejectAction(input, client) {
|
|
1449
1557
|
try {
|
|
1450
1558
|
const { command, result } = await commandItem(
|
|
@@ -1886,9 +1994,26 @@ async function getConversationMessages(input, client) {
|
|
|
1886
1994
|
};
|
|
1887
1995
|
}
|
|
1888
1996
|
}
|
|
1997
|
+
var FREE_CONVERSATION_LABEL = "Free: your first conversation";
|
|
1998
|
+
var FREE_CONVERSATION_ENDED_NOTICE = "Your free first conversation has ended; messages now use credits.";
|
|
1999
|
+
function answerCostOf(data) {
|
|
2000
|
+
if (!data || typeof data !== "object") return null;
|
|
2001
|
+
const usage = data;
|
|
2002
|
+
const free = usage.freeConversation;
|
|
2003
|
+
if (free && typeof free.messagesLeft === "number") {
|
|
2004
|
+
return {
|
|
2005
|
+
free: true,
|
|
2006
|
+
label: FREE_CONVERSATION_LABEL,
|
|
2007
|
+
messagesLeft: free.messagesLeft,
|
|
2008
|
+
...free.ended === true ? { notice: FREE_CONVERSATION_ENDED_NOTICE } : {}
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
return typeof usage.credits === "number" ? { free: false, credits: usage.credits } : null;
|
|
2012
|
+
}
|
|
1889
2013
|
function parseUiMessageStream(raw) {
|
|
1890
2014
|
let reply = "";
|
|
1891
2015
|
const toolsUsed = [];
|
|
2016
|
+
let cost = null;
|
|
1892
2017
|
for (const line of raw.split("\n")) {
|
|
1893
2018
|
if (!line.startsWith("data:")) continue;
|
|
1894
2019
|
const payload = line.slice(5).trim();
|
|
@@ -1899,11 +2024,13 @@ function parseUiMessageStream(raw) {
|
|
|
1899
2024
|
reply += String(event.delta ?? event.textDelta ?? "");
|
|
1900
2025
|
} else if (typeof event.type === "string" && event.type === "tool-input-start" && typeof event.toolName === "string") {
|
|
1901
2026
|
toolsUsed.push(event.toolName);
|
|
2027
|
+
} else if (event.type === "data-usage") {
|
|
2028
|
+
cost = answerCostOf(event.data) ?? cost;
|
|
1902
2029
|
}
|
|
1903
2030
|
} catch {
|
|
1904
2031
|
}
|
|
1905
2032
|
}
|
|
1906
|
-
return { reply, toolsUsed };
|
|
2033
|
+
return { reply, toolsUsed, cost };
|
|
1907
2034
|
}
|
|
1908
2035
|
async function sendChatMessage(input, client) {
|
|
1909
2036
|
try {
|
|
@@ -1944,7 +2071,7 @@ async function sendChatMessage(input, client) {
|
|
|
1944
2071
|
};
|
|
1945
2072
|
}
|
|
1946
2073
|
const raw = await client.postStream("/api/chat", body);
|
|
1947
|
-
const { reply, toolsUsed } = parseUiMessageStream(raw);
|
|
2074
|
+
const { reply, toolsUsed, cost } = parseUiMessageStream(raw);
|
|
1948
2075
|
return {
|
|
1949
2076
|
content: [
|
|
1950
2077
|
{
|
|
@@ -1953,6 +2080,8 @@ async function sendChatMessage(input, client) {
|
|
|
1953
2080
|
conversationId,
|
|
1954
2081
|
reply: reply || "The assistant returned no text response.",
|
|
1955
2082
|
toolsUsed,
|
|
2083
|
+
// FLO-2669: the credits the answer used, or that it was free.
|
|
2084
|
+
...cost ? { cost } : {},
|
|
1956
2085
|
tip: "Pass this conversationId to continue the conversation or to get_conversation_messages for the full transcript."
|
|
1957
2086
|
})
|
|
1958
2087
|
}
|
|
@@ -2284,19 +2413,22 @@ function registerTools(server, client, options = {}) {
|
|
|
2284
2413
|
tool(
|
|
2285
2414
|
"send_chat_message",
|
|
2286
2415
|
"Send chat message",
|
|
2287
|
-
"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.",
|
|
2416
|
+
"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).",
|
|
2288
2417
|
sendChatMessageSchema,
|
|
2289
2418
|
sendChatMessage,
|
|
2290
2419
|
{ readOnlyHint: false, destructiveHint: false, openWorldHint: true }
|
|
2291
2420
|
);
|
|
2292
2421
|
}
|
|
2293
2422
|
|
|
2423
|
+
// src/version.ts
|
|
2424
|
+
var FLOAD_MCP_VERSION = "0.12.2";
|
|
2425
|
+
|
|
2294
2426
|
// src/server.ts
|
|
2295
2427
|
async function createMcpServer(_config, client) {
|
|
2296
2428
|
console.error("[Fload MCP] Server initializing...");
|
|
2297
2429
|
const server = new McpServer({
|
|
2298
2430
|
name: "fload",
|
|
2299
|
-
version:
|
|
2431
|
+
version: FLOAD_MCP_VERSION
|
|
2300
2432
|
});
|
|
2301
2433
|
registerTools(server, client);
|
|
2302
2434
|
console.error("[Fload MCP] Registered tools");
|