@linkedapi/mcp 1.0.1 → 2.0.1
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/.github/workflows/merge-main.yaml +13 -13
- package/.github/workflows/pr-main.yaml +6 -6
- package/README.md +1 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +1 -1
- package/dist/linked-api-server.d.ts +3 -3
- package/dist/linked-api-server.d.ts.map +1 -1
- package/dist/linked-api-server.js +37 -55
- package/dist/linked-api-server.js.map +1 -1
- package/dist/linked-api-tools.d.ts +5 -7
- package/dist/linked-api-tools.d.ts.map +1 -1
- package/dist/linked-api-tools.js.map +1 -1
- package/dist/prompts/index.d.ts +2 -2
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +3 -1
- package/dist/prompts/index.js.map +1 -1
- package/dist/tools/get-api-usage-stats.d.ts +0 -2
- package/dist/tools/get-api-usage-stats.d.ts.map +1 -1
- package/dist/tools/get-api-usage-stats.js.map +1 -1
- package/dist/tools/get-conversation.d.ts +4 -7
- package/dist/tools/get-conversation.d.ts.map +1 -1
- package/dist/tools/get-conversation.js +7 -23
- package/dist/tools/get-conversation.js.map +1 -1
- package/dist/tools/get-workflow-result.d.ts +6 -6
- package/dist/tools/get-workflow-result.d.ts.map +1 -1
- package/dist/tools/get-workflow-result.js +37 -13
- package/dist/tools/get-workflow-result.js.map +1 -1
- package/dist/tools/nv-get-conversation.d.ts +4 -7
- package/dist/tools/nv-get-conversation.d.ts.map +1 -1
- package/dist/tools/nv-get-conversation.js +7 -23
- package/dist/tools/nv-get-conversation.js.map +1 -1
- package/dist/types/linked-api-tool-result.type.d.ts +6 -0
- package/dist/types/linked-api-tool-result.type.d.ts.map +1 -0
- package/dist/types/linked-api-tool-result.type.js +3 -0
- package/dist/types/linked-api-tool-result.type.js.map +1 -0
- package/dist/utils/handle-linked-api-error.d.ts.map +1 -1
- package/dist/utils/handle-linked-api-error.js +0 -19
- package/dist/utils/handle-linked-api-error.js.map +1 -1
- package/dist/utils/linked-api-tool.d.ts +5 -7
- package/dist/utils/linked-api-tool.d.ts.map +1 -1
- package/dist/utils/linked-api-tool.js +4 -9
- package/dist/utils/linked-api-tool.js.map +1 -1
- package/dist/utils/types.d.ts +0 -6
- package/dist/utils/types.d.ts.map +1 -1
- package/package.json +2 -5
- package/src/index.ts +0 -29
- package/src/linked-api-server.ts +44 -66
- package/src/linked-api-tools.ts +5 -13
- package/src/prompts/index.ts +3 -1
- package/src/tools/get-api-usage-stats.ts +0 -2
- package/src/tools/get-conversation.ts +9 -30
- package/src/tools/get-workflow-result.ts +63 -24
- package/src/tools/nv-get-conversation.ts +9 -30
- package/src/types/linked-api-tool-result.type.ts +12 -0
- package/src/utils/handle-linked-api-error.ts +1 -20
- package/src/utils/linked-api-tool.ts +11 -25
- package/src/utils/types.ts +0 -6
- package/dist/utils/execute-with-progress.d.ts +0 -13
- package/dist/utils/execute-with-progress.d.ts.map +0 -1
- package/dist/utils/execute-with-progress.js +0 -85
- package/dist/utils/execute-with-progress.js.map +0 -1
- package/src/utils/execute-with-progress.ts +0 -111
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute-with-progress.d.ts","sourceRoot":"","sources":["../../src/utils/execute-with-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAKxD,UAAU,2BAA2B,CAAC,OAAO,EAAE,OAAO;IACpD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,6BAA6B,KAAK,IAAI,CAAC;IACpE,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,EAC1D,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,MAAM,EACN,UAAU,EACV,aAAa,GACd,EAAE,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CA2DnF"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeWithProgress = executeWithProgress;
|
|
4
|
-
const node_1 = require("@linkedapi/node");
|
|
5
|
-
const WORKFLOW_PROGRESS_TOTAL = 100;
|
|
6
|
-
const MIN_PROGRESS_INTERVAL = 10000;
|
|
7
|
-
async function executeWithProgress({ progressCallback, operation, workflowTimeout, params, workflowId, progressToken, }) {
|
|
8
|
-
let progress = 0;
|
|
9
|
-
progressCallback({
|
|
10
|
-
progressToken,
|
|
11
|
-
progress,
|
|
12
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
13
|
-
message: `Starting Linked API workflow ${operation.operationName}. The action may enter the cloud-browser queue and take several minutes.`,
|
|
14
|
-
});
|
|
15
|
-
const interval = setInterval(() => {
|
|
16
|
-
if (progress < 50) {
|
|
17
|
-
progress += 5;
|
|
18
|
-
}
|
|
19
|
-
else if (progress < 98) {
|
|
20
|
-
progress += 1;
|
|
21
|
-
}
|
|
22
|
-
progressCallback({
|
|
23
|
-
progressToken,
|
|
24
|
-
progress,
|
|
25
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
26
|
-
message: `Waiting for workflow ${operation.operationName}. Linked API is still processing it in the background.`,
|
|
27
|
-
});
|
|
28
|
-
}, Math.max(workflowTimeout / 20, MIN_PROGRESS_INTERVAL));
|
|
29
|
-
try {
|
|
30
|
-
if (!workflowId) {
|
|
31
|
-
workflowId = await operation.execute(params);
|
|
32
|
-
progressCallback({
|
|
33
|
-
progressToken,
|
|
34
|
-
progress,
|
|
35
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
36
|
-
message: `Workflow ${operation.operationName} is queued or running in the background. workflowId: ${workflowId}.`,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const result = await operation.result(workflowId, {
|
|
40
|
-
timeout: workflowTimeout,
|
|
41
|
-
});
|
|
42
|
-
clearInterval(interval);
|
|
43
|
-
progressCallback({
|
|
44
|
-
progressToken,
|
|
45
|
-
progress: WORKFLOW_PROGRESS_TOTAL,
|
|
46
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
47
|
-
message: `Workflow ${operation.operationName} completed successfully`,
|
|
48
|
-
});
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
clearInterval(interval);
|
|
53
|
-
if (error instanceof node_1.LinkedApiWorkflowTimeoutError) {
|
|
54
|
-
throw generateTimeoutError(error);
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function generateTimeoutError(error) {
|
|
60
|
-
const restoreMessage = `Workflow is still running in Linked API's cloud-browser queue or background worker.
|
|
61
|
-
|
|
62
|
-
This is not a failure. The original tool already started the workflow, so retrying it can create duplicate queued work.
|
|
63
|
-
|
|
64
|
-
ACTION REQUIRED (MCP CLIENT):
|
|
65
|
-
- Do not retry the original tool; the workflow is already running
|
|
66
|
-
- Call the get_workflow_result tool with the parameters below and keep listening until completion
|
|
67
|
-
|
|
68
|
-
PARAMETERS TO USE:
|
|
69
|
-
- workflowId: ${error.workflowId}
|
|
70
|
-
- operationName: ${error.operationName}
|
|
71
|
-
|
|
72
|
-
GENERIC MCP CALL EXAMPLE:
|
|
73
|
-
{
|
|
74
|
-
"name": "get_workflow_result",
|
|
75
|
-
"arguments": {
|
|
76
|
-
"workflowId": "${error.workflowId}",
|
|
77
|
-
"operationName": "${error.operationName}"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
Background processing keeps the MCP client responsive while the workflow completes.`;
|
|
82
|
-
error.message = restoreMessage;
|
|
83
|
-
return error;
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=execute-with-progress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute-with-progress.js","sourceRoot":"","sources":["../../src/utils/execute-with-progress.ts"],"names":[],"mappings":";;AAgBA,kDAkEC;AAlFD,0CAA4F;AAI5F,MAAM,uBAAuB,GAAG,GAAY,CAAC;AAC7C,MAAM,qBAAqB,GAAG,KAAc,CAAC;AAWtC,KAAK,UAAU,mBAAmB,CAAmB,EAC1D,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,MAAM,EACN,UAAU,EACV,aAAa,GACiC;IAC9C,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,gBAAgB,CAAC;QACf,aAAa;QACb,QAAQ;QACR,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,gCAAgC,SAAS,CAAC,aAAa,0EAA0E;KAC3I,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,WAAW,CAC1B,GAAG,EAAE;QACH,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;YAClB,QAAQ,IAAI,CAAC,CAAC;QAChB,CAAC;aAAM,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;YACzB,QAAQ,IAAI,CAAC,CAAC;QAChB,CAAC;QAED,gBAAgB,CAAC;YACf,aAAa;YACb,QAAQ;YACR,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,wBAAwB,SAAS,CAAC,aAAa,wDAAwD;SACjH,CAAC,CAAC;IACL,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,EAAE,EAAE,qBAAqB,CAAC,CACtD,CAAC;IAEF,IAAI,CAAC;QACH,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,UAAU,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,MAAiB,CAAC,CAAC;YACxD,gBAAgB,CAAC;gBACf,aAAa;gBACb,QAAQ;gBACR,KAAK,EAAE,uBAAuB;gBAC9B,OAAO,EAAE,YAAY,SAAS,CAAC,aAAa,wDAAwD,UAAU,GAAG;aAClH,CAAC,CAAC;QACL,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE;YAChD,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;QACH,aAAa,CAAC,QAAQ,CAAC,CAAC;QAExB,gBAAgB,CAAC;YACf,aAAa;YACb,QAAQ,EAAE,uBAAuB;YACjC,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,YAAY,SAAS,CAAC,aAAa,yBAAyB;SACtE,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxB,IAAI,KAAK,YAAY,oCAA6B,EAAE,CAAC;YACnD,MAAM,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAoC;IAChE,MAAM,cAAc,GAAG;;;;;;;;;gBAST,KAAK,CAAC,UAAU;mBACb,KAAK,CAAC,aAAa;;;;;;qBAMjB,KAAK,CAAC,UAAU;wBACb,KAAK,CAAC,aAAa;;;;oFAIyC,CAAC;IAEnF,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { LinkedApiWorkflowTimeoutError, Operation, TMappedResponse } from '@linkedapi/node';
|
|
2
|
-
|
|
3
|
-
import { LinkedApiProgressNotification } from './types';
|
|
4
|
-
|
|
5
|
-
const WORKFLOW_PROGRESS_TOTAL = 100 as const;
|
|
6
|
-
const MIN_PROGRESS_INTERVAL = 10000 as const;
|
|
7
|
-
|
|
8
|
-
interface TExecuteWithProgressOptions<TParams, TResult> {
|
|
9
|
-
progressCallback: (progress: LinkedApiProgressNotification) => void;
|
|
10
|
-
operation: Operation<TParams, TResult>;
|
|
11
|
-
workflowTimeout: number;
|
|
12
|
-
params?: TParams;
|
|
13
|
-
workflowId?: string;
|
|
14
|
-
progressToken?: string | number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function executeWithProgress<TParams, TResult>({
|
|
18
|
-
progressCallback,
|
|
19
|
-
operation,
|
|
20
|
-
workflowTimeout,
|
|
21
|
-
params,
|
|
22
|
-
workflowId,
|
|
23
|
-
progressToken,
|
|
24
|
-
}: TExecuteWithProgressOptions<TParams, TResult>): Promise<TMappedResponse<TResult>> {
|
|
25
|
-
let progress = 0;
|
|
26
|
-
|
|
27
|
-
progressCallback({
|
|
28
|
-
progressToken,
|
|
29
|
-
progress,
|
|
30
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
31
|
-
message: `Starting Linked API workflow ${operation.operationName}. The action may enter the cloud-browser queue and take several minutes.`,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const interval = setInterval(
|
|
35
|
-
() => {
|
|
36
|
-
if (progress < 50) {
|
|
37
|
-
progress += 5;
|
|
38
|
-
} else if (progress < 98) {
|
|
39
|
-
progress += 1;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
progressCallback({
|
|
43
|
-
progressToken,
|
|
44
|
-
progress,
|
|
45
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
46
|
-
message: `Waiting for workflow ${operation.operationName}. Linked API is still processing it in the background.`,
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
Math.max(workflowTimeout / 20, MIN_PROGRESS_INTERVAL),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
if (!workflowId) {
|
|
54
|
-
workflowId = await operation.execute(params as TParams);
|
|
55
|
-
progressCallback({
|
|
56
|
-
progressToken,
|
|
57
|
-
progress,
|
|
58
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
59
|
-
message: `Workflow ${operation.operationName} is queued or running in the background. workflowId: ${workflowId}.`,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
const result = await operation.result(workflowId, {
|
|
63
|
-
timeout: workflowTimeout,
|
|
64
|
-
});
|
|
65
|
-
clearInterval(interval);
|
|
66
|
-
|
|
67
|
-
progressCallback({
|
|
68
|
-
progressToken,
|
|
69
|
-
progress: WORKFLOW_PROGRESS_TOTAL,
|
|
70
|
-
total: WORKFLOW_PROGRESS_TOTAL,
|
|
71
|
-
message: `Workflow ${operation.operationName} completed successfully`,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return result;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
clearInterval(interval);
|
|
77
|
-
if (error instanceof LinkedApiWorkflowTimeoutError) {
|
|
78
|
-
throw generateTimeoutError(error);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function generateTimeoutError(error: LinkedApiWorkflowTimeoutError): LinkedApiWorkflowTimeoutError {
|
|
86
|
-
const restoreMessage = `Workflow is still running in Linked API's cloud-browser queue or background worker.
|
|
87
|
-
|
|
88
|
-
This is not a failure. The original tool already started the workflow, so retrying it can create duplicate queued work.
|
|
89
|
-
|
|
90
|
-
ACTION REQUIRED (MCP CLIENT):
|
|
91
|
-
- Do not retry the original tool; the workflow is already running
|
|
92
|
-
- Call the get_workflow_result tool with the parameters below and keep listening until completion
|
|
93
|
-
|
|
94
|
-
PARAMETERS TO USE:
|
|
95
|
-
- workflowId: ${error.workflowId}
|
|
96
|
-
- operationName: ${error.operationName}
|
|
97
|
-
|
|
98
|
-
GENERIC MCP CALL EXAMPLE:
|
|
99
|
-
{
|
|
100
|
-
"name": "get_workflow_result",
|
|
101
|
-
"arguments": {
|
|
102
|
-
"workflowId": "${error.workflowId}",
|
|
103
|
-
"operationName": "${error.operationName}"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
Background processing keeps the MCP client responsive while the workflow completes.`;
|
|
108
|
-
|
|
109
|
-
error.message = restoreMessage;
|
|
110
|
-
return error;
|
|
111
|
-
}
|