@apify/actors-mcp-server 0.11.7-beta.1 → 0.11.7-beta.11
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/dist/index_internals.d.ts +7 -12
- package/dist/index_internals.d.ts.map +1 -1
- package/dist/index_internals.js +6 -11
- package/dist/index_internals.js.map +1 -1
- package/dist/mcp/actors.d.ts +0 -4
- package/dist/mcp/actors.d.ts.map +1 -1
- package/dist/mcp/actors.js +0 -13
- package/dist/mcp/actors.js.map +1 -1
- package/dist/mcp/server.d.ts +3 -33
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +103 -645
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/task_execution.d.ts +42 -0
- package/dist/mcp/task_execution.d.ts.map +1 -0
- package/dist/mcp/task_execution.js +310 -0
- package/dist/mcp/task_execution.js.map +1 -0
- package/dist/mcp/tool_call_error_mapper.d.ts +45 -0
- package/dist/mcp/tool_call_error_mapper.d.ts.map +1 -0
- package/dist/mcp/tool_call_error_mapper.js +59 -0
- package/dist/mcp/tool_call_error_mapper.js.map +1 -0
- package/dist/mcp/tool_call_telemetry.d.ts +37 -0
- package/dist/mcp/tool_call_telemetry.d.ts.map +1 -0
- package/dist/mcp/tool_call_telemetry.js +85 -0
- package/dist/mcp/tool_call_telemetry.js.map +1 -0
- package/dist/mcp/tool_dispatch.d.ts +49 -0
- package/dist/mcp/tool_dispatch.d.ts.map +1 -0
- package/dist/mcp/tool_dispatch.js +208 -0
- package/dist/mcp/tool_dispatch.js.map +1 -0
- package/dist/payments/const.d.ts +1 -0
- package/dist/payments/const.d.ts.map +1 -1
- package/dist/payments/const.js +1 -0
- package/dist/payments/const.js.map +1 -1
- package/dist/payments/skyfire.d.ts.map +1 -1
- package/dist/payments/skyfire.js +5 -6
- package/dist/payments/skyfire.js.map +1 -1
- package/dist/tools/actors/call_actor.d.ts +0 -3
- package/dist/tools/actors/call_actor.d.ts.map +1 -1
- package/dist/tools/actors/call_actor.js +2 -11
- package/dist/tools/actors/call_actor.js.map +1 -1
- package/dist/tools/actors/fetch_actor_details.d.ts +1 -7
- package/dist/tools/actors/fetch_actor_details.d.ts.map +1 -1
- package/dist/tools/actors/fetch_actor_details.js +14 -22
- package/dist/tools/actors/fetch_actor_details.js.map +1 -1
- package/dist/tools/actors/search_actors.d.ts +1 -6
- package/dist/tools/actors/search_actors.d.ts.map +1 -1
- package/dist/tools/actors/search_actors.js +17 -24
- package/dist/tools/actors/search_actors.js.map +1 -1
- package/dist/tools/dev/report_problem.d.ts +13 -0
- package/dist/tools/dev/report_problem.d.ts.map +1 -1
- package/dist/tools/dev/report_problem.js +14 -0
- package/dist/tools/dev/report_problem.js.map +1 -1
- package/dist/tools/docs/search_apify_docs.d.ts.map +1 -1
- package/dist/tools/docs/search_apify_docs.js +1 -0
- package/dist/tools/docs/search_apify_docs.js.map +1 -1
- package/dist/tools/runs/get_actor_run.d.ts +1 -6
- package/dist/tools/runs/get_actor_run.d.ts.map +1 -1
- package/dist/tools/runs/get_actor_run.js +17 -24
- package/dist/tools/runs/get_actor_run.js.map +1 -1
- package/dist/tools/storage/get_dataset.d.ts.map +1 -1
- package/dist/tools/storage/get_dataset.js +6 -5
- package/dist/tools/storage/get_dataset.js.map +1 -1
- package/dist/tools/storage/get_dataset_items.d.ts.map +1 -1
- package/dist/tools/storage/get_dataset_items.js +6 -8
- package/dist/tools/storage/get_dataset_items.js.map +1 -1
- package/dist/tools/storage/get_dataset_list.d.ts.map +1 -1
- package/dist/tools/storage/get_dataset_list.js +8 -9
- package/dist/tools/storage/get_dataset_list.js.map +1 -1
- package/dist/tools/storage/get_dataset_schema.d.ts.map +1 -1
- package/dist/tools/storage/get_dataset_schema.js +6 -4
- package/dist/tools/storage/get_dataset_schema.js.map +1 -1
- package/dist/tools/storage/get_key_value_store.js +3 -3
- package/dist/tools/storage/get_key_value_store.js.map +1 -1
- package/dist/tools/storage/get_key_value_store_keys.js +4 -4
- package/dist/tools/storage/get_key_value_store_keys.js.map +1 -1
- package/dist/tools/storage/get_key_value_store_list.d.ts.map +1 -1
- package/dist/tools/storage/get_key_value_store_list.js +8 -9
- package/dist/tools/storage/get_key_value_store_list.js.map +1 -1
- package/dist/tools/storage/get_key_value_store_record.d.ts.map +1 -1
- package/dist/tools/storage/get_key_value_store_record.js +3 -2
- package/dist/tools/storage/get_key_value_store_record.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +0 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/actor_details.d.ts.map +1 -1
- package/dist/utils/actor_details.js +10 -3
- package/dist/utils/actor_details.js.map +1 -1
- package/dist/utils/logging.d.ts +2 -0
- package/dist/utils/logging.d.ts.map +1 -1
- package/dist/utils/logging.js +45 -1
- package/dist/utils/logging.js.map +1 -1
- package/dist/utils/payment_errors.d.ts +7 -1
- package/dist/utils/payment_errors.d.ts.map +1 -1
- package/dist/utils/payment_errors.js +10 -0
- package/dist/utils/payment_errors.js.map +1 -1
- package/dist/web/dist/actor-run-widget.js +0 -3
- package/dist/web/dist/search-actors-widget.js +0 -3
- package/package.json +2 -2
- package/dist/web/dist/actor-detail-widget.js +0 -4551
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FAILURE_CATEGORY, TOOL_STATUS } from '../const.js';
|
|
2
|
+
import { isPermissionApprovalError } from '../utils/apify_errors.js';
|
|
3
|
+
import { getHttpStatusCode } from '../utils/logging.js';
|
|
4
|
+
import { getToolCallErrorUserText } from '../utils/mcp.js';
|
|
5
|
+
import { buildPaymentRequiredResponse, buildPermissionApprovalResponse, isX402PaymentRequiredError, } from '../utils/payment_errors.js';
|
|
6
|
+
import { classifyFailureCategory, getToolStatusFromError } from '../utils/tool_status.js';
|
|
7
|
+
import { buildActorFields } from '../utils/tools.js';
|
|
8
|
+
/** Discriminants of `ToolCallErrorResult` — reference these, never string literals. */
|
|
9
|
+
export const TOOL_CALL_ERROR_KIND = {
|
|
10
|
+
PAYMENT: 'payment',
|
|
11
|
+
APPROVAL: 'approval',
|
|
12
|
+
EXECUTION: 'execution',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Classifies a tool-call error into a 402 payment / permission-approval / generic execution result.
|
|
16
|
+
* Pure: never throws, logs, or touches the task store. An HTTP-range-coded error — including an
|
|
17
|
+
* `McpError` with code 402 — classifies as PAYMENT, since `getHttpStatusCode` falls through to `.code`.
|
|
18
|
+
*/
|
|
19
|
+
export function buildToolCallErrorResult(error, params) {
|
|
20
|
+
const { toolName, actorName, actorId, isAborted } = params;
|
|
21
|
+
const httpStatus = getHttpStatusCode(error);
|
|
22
|
+
if (isX402PaymentRequiredError(error)) {
|
|
23
|
+
return {
|
|
24
|
+
kind: TOOL_CALL_ERROR_KIND.PAYMENT,
|
|
25
|
+
toolStatus: TOOL_STATUS.SOFT_FAIL,
|
|
26
|
+
callDiagnostics: {
|
|
27
|
+
failure_category: FAILURE_CATEGORY.INVALID_INPUT,
|
|
28
|
+
failure_http_status: 402,
|
|
29
|
+
...buildActorFields(actorName, actorId),
|
|
30
|
+
},
|
|
31
|
+
response: buildPaymentRequiredResponse(error),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (isPermissionApprovalError(error)) {
|
|
35
|
+
return {
|
|
36
|
+
kind: TOOL_CALL_ERROR_KIND.APPROVAL,
|
|
37
|
+
toolStatus: TOOL_STATUS.SOFT_FAIL,
|
|
38
|
+
callDiagnostics: {
|
|
39
|
+
failure_category: FAILURE_CATEGORY.PERMISSION_APPROVAL_REQUIRED,
|
|
40
|
+
failure_http_status: error.statusCode,
|
|
41
|
+
...buildActorFields(actorName, actorId),
|
|
42
|
+
},
|
|
43
|
+
response: buildPermissionApprovalResponse(error),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const failureDetail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
47
|
+
return {
|
|
48
|
+
kind: TOOL_CALL_ERROR_KIND.EXECUTION,
|
|
49
|
+
toolStatus: getToolStatusFromError(error, isAborted),
|
|
50
|
+
callDiagnostics: {
|
|
51
|
+
failure_category: classifyFailureCategory(error),
|
|
52
|
+
...(httpStatus !== undefined ? { failure_http_status: httpStatus } : {}),
|
|
53
|
+
failure_detail: failureDetail,
|
|
54
|
+
...buildActorFields(actorName, actorId),
|
|
55
|
+
},
|
|
56
|
+
userText: getToolCallErrorUserText(toolName, error),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=tool_call_error_mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_call_error_mapper.js","sourceRoot":"","sources":["../../src/mcp/tool_call_error_mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EACH,4BAA4B,EAC5B,+BAA+B,EAC/B,0BAA0B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAUrD,uFAAuF;AACvF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;CAChB,CAAC;AAyBX;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc,EAAE,MAA2B;IAChF,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC3D,MAAM,UAAU,GAAG,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AAE,CAAC;YACxE,cAAc,EAAE,aAAa;YAC7B,GAAG,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC;SAC1C;QACD,QAAQ,EAAE,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CAAC;KACtD,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CallDiagnostics, ToolCallTelemetryProperties, ToolStatus } from '../types.js';
|
|
2
|
+
import type { ActorsMcpServer } from './server.js';
|
|
3
|
+
type PrepareTelemetryDataParams = {
|
|
4
|
+
toolName: string;
|
|
5
|
+
mcpSessionId: string | undefined;
|
|
6
|
+
apifyToken: string;
|
|
7
|
+
apifyMcpServer: ActorsMcpServer;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates telemetry data for a tool call.
|
|
11
|
+
*/
|
|
12
|
+
export declare function prepareTelemetryData(params: PrepareTelemetryDataParams): Promise<{
|
|
13
|
+
telemetryData: ToolCallTelemetryProperties | null;
|
|
14
|
+
userId: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Logs tool call completion at INFO level and tracks telemetry.
|
|
18
|
+
* Computes duration once so both the log line and telemetry event use the same value.
|
|
19
|
+
* Response bytes and resource ids are derived here from the raw `result` (+ `args`) so every
|
|
20
|
+
* call site stays a plain hand-off — no path can forget to compute or strip them.
|
|
21
|
+
*/
|
|
22
|
+
type LogToolCallAndTelemetryParams = {
|
|
23
|
+
toolName: string;
|
|
24
|
+
mcpSessionId: string | undefined;
|
|
25
|
+
toolStatus: ToolStatus;
|
|
26
|
+
startTime: number;
|
|
27
|
+
taskId?: string;
|
|
28
|
+
telemetryData: ToolCallTelemetryProperties | null;
|
|
29
|
+
userId: string | null;
|
|
30
|
+
callDiagnostics?: CallDiagnostics;
|
|
31
|
+
args?: Record<string, unknown>;
|
|
32
|
+
result?: unknown;
|
|
33
|
+
apifyMcpServer: ActorsMcpServer;
|
|
34
|
+
};
|
|
35
|
+
export declare function logToolCallAndTelemetry(params: LogToolCallAndTelemetryParams): void;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=tool_call_telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_call_telemetry.d.ts","sourceRoot":"","sources":["../../src/mcp/tool_call_telemetry.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,0BAA0B,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,MAAM,EAAE,0BAA0B,GACnC,OAAO,CAAC;IAAE,aAAa,EAAE,2BAA2B,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CA8BvF;AAED;;;;;GAKG;AACH,KAAK,6BAA6B,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,2BAA2B,GAAG,IAAI,CAAC;IAClD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,6BAA6B,GAAG,IAAI,CAmDnF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import log from '@apify/log';
|
|
2
|
+
import { ApifyClient } from '../apify_client.js';
|
|
3
|
+
import { HELPER_TOOLS, TOOL_STATUS } from '../const.js';
|
|
4
|
+
import { buildReportedProblemProperties, trackReportedProblem, trackToolCall } from '../telemetry.js';
|
|
5
|
+
import { computeToolResponseBytes } from '../utils/mcp.js';
|
|
6
|
+
import { deriveResourceIds } from '../utils/tool_status.js';
|
|
7
|
+
import { getUserInfoCached } from '../utils/userid_cache.js';
|
|
8
|
+
import { getPackageVersion } from '../utils/version.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates telemetry data for a tool call.
|
|
11
|
+
*/
|
|
12
|
+
export async function prepareTelemetryData(params) {
|
|
13
|
+
var _a, _b, _c, _d, _e;
|
|
14
|
+
const { toolName, mcpSessionId, apifyToken, apifyMcpServer } = params;
|
|
15
|
+
if (!apifyMcpServer.telemetryEnabled) {
|
|
16
|
+
return { telemetryData: null, userId: null };
|
|
17
|
+
}
|
|
18
|
+
// Get userId from cache or fetch from API
|
|
19
|
+
let userId = null;
|
|
20
|
+
if (apifyToken) {
|
|
21
|
+
const apifyClient = new ApifyClient({ token: apifyToken });
|
|
22
|
+
({ userId } = await getUserInfoCached(apifyToken, apifyClient));
|
|
23
|
+
log.debug('Telemetry: fetched userId', { userId, mcpSessionId });
|
|
24
|
+
}
|
|
25
|
+
const capabilities = (_b = (_a = apifyMcpServer.options.initializeRequestData) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.capabilities;
|
|
26
|
+
const initializeParams = (_c = apifyMcpServer.options.initializeRequestData) === null || _c === void 0 ? void 0 : _c.params;
|
|
27
|
+
const telemetryData = {
|
|
28
|
+
app: 'mcp',
|
|
29
|
+
app_version: getPackageVersion() || '',
|
|
30
|
+
mcp_client_name: ((_d = initializeParams === null || initializeParams === void 0 ? void 0 : initializeParams.clientInfo) === null || _d === void 0 ? void 0 : _d.name) || '',
|
|
31
|
+
mcp_client_version: ((_e = initializeParams === null || initializeParams === void 0 ? void 0 : initializeParams.clientInfo) === null || _e === void 0 ? void 0 : _e.version) || '',
|
|
32
|
+
mcp_protocol_version: (initializeParams === null || initializeParams === void 0 ? void 0 : initializeParams.protocolVersion) || '',
|
|
33
|
+
mcp_client_capabilities: capabilities || null,
|
|
34
|
+
mcp_session_id: mcpSessionId || '',
|
|
35
|
+
transport_type: apifyMcpServer.options.transportType || '',
|
|
36
|
+
tool_name: toolName,
|
|
37
|
+
tool_status: TOOL_STATUS.SUCCEEDED, // Will be updated in finally
|
|
38
|
+
tool_exec_time_ms: 0, // Will be calculated in finally
|
|
39
|
+
};
|
|
40
|
+
return { telemetryData, userId };
|
|
41
|
+
}
|
|
42
|
+
export function logToolCallAndTelemetry(params) {
|
|
43
|
+
const durationMs = Date.now() - params.startTime;
|
|
44
|
+
// `result` is undefined only on short-circuit paths that never produced a payload (e.g. a
|
|
45
|
+
// cancelled task); skip byte accounting there. `null`/`{}` still measure as zero bytes.
|
|
46
|
+
const responseBytes = params.result === undefined ? undefined : computeToolResponseBytes(params.result);
|
|
47
|
+
log.info('Tool call completed', {
|
|
48
|
+
toolName: params.toolName,
|
|
49
|
+
mcpSessionId: params.mcpSessionId,
|
|
50
|
+
toolStatus: params.toolStatus,
|
|
51
|
+
durationMs,
|
|
52
|
+
...(responseBytes !== undefined && {
|
|
53
|
+
responseContentBytes: responseBytes.contentBytes,
|
|
54
|
+
responseStructuredContentBytes: responseBytes.structuredContentBytes,
|
|
55
|
+
responseFileBytes: responseBytes.fileBytes,
|
|
56
|
+
}),
|
|
57
|
+
...(params.taskId !== undefined && { taskId: params.taskId }),
|
|
58
|
+
});
|
|
59
|
+
if (params.telemetryData) {
|
|
60
|
+
const finalizedTelemetryData = {
|
|
61
|
+
...params.telemetryData,
|
|
62
|
+
tool_status: params.toolStatus,
|
|
63
|
+
tool_exec_time_ms: durationMs,
|
|
64
|
+
...(responseBytes && {
|
|
65
|
+
tool_response_content_bytes: responseBytes.contentBytes,
|
|
66
|
+
tool_response_structured_content_bytes: responseBytes.structuredContentBytes,
|
|
67
|
+
tool_response_file_bytes: responseBytes.fileBytes,
|
|
68
|
+
}),
|
|
69
|
+
// Always include actor_name/actor_id; failure-specific fields are only present when callDiagnostics has them.
|
|
70
|
+
...params.callDiagnostics,
|
|
71
|
+
// Resource ids are read once here from the args + the tool's public output; no tool
|
|
72
|
+
// threads them back. Applied uniformly, last. See deriveResourceIds.
|
|
73
|
+
...deriveResourceIds(params.args, params.result),
|
|
74
|
+
};
|
|
75
|
+
trackToolCall(params.userId, params.apifyMcpServer.telemetryEnv, finalizedTelemetryData);
|
|
76
|
+
// A successful report-problem call also emits a dedicated feedback event carrying the
|
|
77
|
+
// submission. A downstream Segment destination fans it out to Slack/GitHub.
|
|
78
|
+
if (params.toolName === HELPER_TOOLS.PROBLEM_REPORT &&
|
|
79
|
+
params.toolStatus === TOOL_STATUS.SUCCEEDED &&
|
|
80
|
+
params.args) {
|
|
81
|
+
trackReportedProblem(params.userId, params.apifyMcpServer.telemetryEnv, buildReportedProblemProperties(finalizedTelemetryData, params.args));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=tool_call_telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_call_telemetry.js","sourceRoot":"","sources":["../../src/mcp/tool_call_telemetry.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEtG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO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;IAEH,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACvB,MAAM,sBAAsB,GAAgC;YACxD,GAAG,MAAM,CAAC,aAAa;YACvB,WAAW,EAAE,MAAM,CAAC,UAAU;YAC9B,iBAAiB,EAAE,UAAU;YAC7B,GAAG,CAAC,aAAa,IAAI;gBACjB,2BAA2B,EAAE,aAAa,CAAC,YAAY;gBACvD,sCAAsC,EAAE,aAAa,CAAC,sBAAsB;gBAC5E,wBAAwB,EAAE,aAAa,CAAC,SAAS;aACpD,CAAC;YACF,8GAA8G;YAC9G,GAAG,MAAM,CAAC,eAAe;YACzB,oFAAoF;YACpF,qEAAqE;YACrE,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;SACnD,CAAC;QACF,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;QAEzF,sFAAsF;QACtF,4EAA4E;QAC5E,IACI,MAAM,CAAC,QAAQ,KAAK,YAAY,CAAC,cAAc;YAC/C,MAAM,CAAC,UAAU,KAAK,WAAW,CAAC,SAAS;YAC3C,MAAM,CAAC,IAAI,EACb,CAAC;YACC,oBAAoB,CAChB,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,cAAc,CAAC,YAAY,EAClC,8BAA8B,CAAC,sBAAsB,EAAE,MAAM,CAAC,IAAI,CAAC,CACtE,CAAC;QACN,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
2
|
+
import type { Notification, Request } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import type { ApifyClient } from '../apify_client.js';
|
|
4
|
+
import type { CallDiagnostics, ToolEntry, ToolStatus } from '../types.js';
|
|
5
|
+
import type { createProgressTracker } from '../utils/progress.js';
|
|
6
|
+
import type { ActorsMcpServer } from './server.js';
|
|
7
|
+
/**
|
|
8
|
+
* Runs a validated tool call through the single tool-type dispatch switch and returns the raw
|
|
9
|
+
* result plus derived telemetry. The exhaustive switch turns a future 4th TOOL_TYPE into a compile
|
|
10
|
+
* error (same `satisfies never` idiom as getToolFullName) instead of a silent runtime fall-through.
|
|
11
|
+
* Both the sync `CallToolRequestSchema` handler and `executeToolAndUpdateTask` call this after their
|
|
12
|
+
* own pre-dispatch validation and keep their own try/catch + buildToolCallErrorResult around it.
|
|
13
|
+
* INTERNAL and ACTOR execution errors propagate to the caller's catch; the ACTOR_MCP case keeps its
|
|
14
|
+
* own inner catch and returns a soft-fail result instead of throwing.
|
|
15
|
+
*
|
|
16
|
+
* `extractToolTelemetry` (via `applyToolTelemetry`) runs once here, in the INTERNAL and ACTOR
|
|
17
|
+
* cases, and strips `toolTelemetry` in place, so callers must not re-strip. ACTOR_MCP sets
|
|
18
|
+
* telemetry manually instead. The caller constructs `progressTracker`; dispatch consumes it and stops
|
|
19
|
+
* it in the branch `finally`. The abort source is `extra.signal`: the request signal for sync; the
|
|
20
|
+
* task caller passes a `taskExtra` whose `signal` is the cancel watcher's, so a client disconnect
|
|
21
|
+
* never cancels a task. `shouldForwardNotifications` gates only the ACTOR_MCP raw-notification
|
|
22
|
+
* forwarder (true for sync, false for task, whose originating request is already answered).
|
|
23
|
+
* `taskMode` is a passthrough to `tool.call` / `executeActorTool`, never a dispatch selector.
|
|
24
|
+
*/
|
|
25
|
+
export declare function dispatchToolCall(params: {
|
|
26
|
+
tool: ToolEntry;
|
|
27
|
+
toolArgs: Record<string, unknown>;
|
|
28
|
+
logSafeArgs: unknown;
|
|
29
|
+
apifyToken: string;
|
|
30
|
+
apifyClient: ApifyClient;
|
|
31
|
+
apifyMcpServer: ActorsMcpServer;
|
|
32
|
+
mcpSessionId: string | undefined;
|
|
33
|
+
progressToken: string | number | undefined;
|
|
34
|
+
progressTracker: ReturnType<typeof createProgressTracker>;
|
|
35
|
+
shouldForwardNotifications: boolean;
|
|
36
|
+
extra: RequestHandlerExtra<Request, Notification>;
|
|
37
|
+
actorName?: string;
|
|
38
|
+
actorId?: string;
|
|
39
|
+
taskMode: boolean;
|
|
40
|
+
logContext?: {
|
|
41
|
+
messageSuffix: string;
|
|
42
|
+
fields: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
}): Promise<{
|
|
45
|
+
result: Record<string, unknown>;
|
|
46
|
+
toolStatus: ToolStatus;
|
|
47
|
+
callDiagnostics: CallDiagnostics;
|
|
48
|
+
}>;
|
|
49
|
+
//# sourceMappingURL=tool_dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_dispatch.d.ts","sourceRoot":"","sources":["../../src/mcp/tool_dispatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAWhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,WAAW,CAAC;IACzB,cAAc,EAAE,eAAe,CAAC;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3C,eAAe,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;IAC1D,0BAA0B,EAAE,OAAO,CAAC;IACpC,KAAK,EAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAGlB,UAAU,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CAC3E,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,eAAe,EAAE,eAAe,CAAA;CAAE,CAAC,CAqNzG"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { CallToolResultSchema, ErrorCode, McpError, ServerNotificationSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import dedent from 'dedent';
|
|
3
|
+
import log from '@apify/log';
|
|
4
|
+
import { FAILURE_CATEGORY, TOOL_STATUS } from '../const.js';
|
|
5
|
+
import { actorExecutor } from '../tools/actors/actor_executor.js';
|
|
6
|
+
import { TOOL_TYPE } from '../types.js';
|
|
7
|
+
import { remoteMcpFailureDetail } from '../utils/apify_errors.js';
|
|
8
|
+
import { logHttpError } from '../utils/logging.js';
|
|
9
|
+
import { respondErrorNoTelemetry } from '../utils/mcp.js';
|
|
10
|
+
import { applyToolTelemetry, classifyFailureCategory, getToolStatusFromError } from '../utils/tool_status.js';
|
|
11
|
+
import { buildActorFields } from '../utils/tools.js';
|
|
12
|
+
import { connectMCPClient } from './client.js';
|
|
13
|
+
import { EXTERNAL_TOOL_CALL_TIMEOUT_MSEC } from './const.js';
|
|
14
|
+
/**
|
|
15
|
+
* Runs a validated tool call through the single tool-type dispatch switch and returns the raw
|
|
16
|
+
* result plus derived telemetry. The exhaustive switch turns a future 4th TOOL_TYPE into a compile
|
|
17
|
+
* error (same `satisfies never` idiom as getToolFullName) instead of a silent runtime fall-through.
|
|
18
|
+
* Both the sync `CallToolRequestSchema` handler and `executeToolAndUpdateTask` call this after their
|
|
19
|
+
* own pre-dispatch validation and keep their own try/catch + buildToolCallErrorResult around it.
|
|
20
|
+
* INTERNAL and ACTOR execution errors propagate to the caller's catch; the ACTOR_MCP case keeps its
|
|
21
|
+
* own inner catch and returns a soft-fail result instead of throwing.
|
|
22
|
+
*
|
|
23
|
+
* `extractToolTelemetry` (via `applyToolTelemetry`) runs once here, in the INTERNAL and ACTOR
|
|
24
|
+
* cases, and strips `toolTelemetry` in place, so callers must not re-strip. ACTOR_MCP sets
|
|
25
|
+
* telemetry manually instead. The caller constructs `progressTracker`; dispatch consumes it and stops
|
|
26
|
+
* it in the branch `finally`. The abort source is `extra.signal`: the request signal for sync; the
|
|
27
|
+
* task caller passes a `taskExtra` whose `signal` is the cancel watcher's, so a client disconnect
|
|
28
|
+
* never cancels a task. `shouldForwardNotifications` gates only the ACTOR_MCP raw-notification
|
|
29
|
+
* forwarder (true for sync, false for task, whose originating request is already answered).
|
|
30
|
+
* `taskMode` is a passthrough to `tool.call` / `executeActorTool`, never a dispatch selector.
|
|
31
|
+
*/
|
|
32
|
+
export async function dispatchToolCall(params) {
|
|
33
|
+
var _a, _b, _c, _d;
|
|
34
|
+
const { tool, toolArgs, logSafeArgs, apifyToken, apifyClient, apifyMcpServer, mcpSessionId, progressToken, progressTracker, shouldForwardNotifications, extra, actorName, actorId, taskMode, logContext, } = params;
|
|
35
|
+
let result = {};
|
|
36
|
+
let toolStatus = TOOL_STATUS.SUCCEEDED;
|
|
37
|
+
// Always populate actor fields so they're tracked on both success and failure paths.
|
|
38
|
+
let callDiagnostics = { ...buildActorFields(actorName, actorId) };
|
|
39
|
+
switch (tool.type) {
|
|
40
|
+
case TOOL_TYPE.INTERNAL: {
|
|
41
|
+
try {
|
|
42
|
+
log.info(`Calling internal tool${(_a = logContext === null || logContext === void 0 ? void 0 : logContext.messageSuffix) !== null && _a !== void 0 ? _a : ''}`, {
|
|
43
|
+
...logContext === null || logContext === void 0 ? void 0 : logContext.fields,
|
|
44
|
+
toolName: tool.name,
|
|
45
|
+
mcpSessionId,
|
|
46
|
+
input: logSafeArgs,
|
|
47
|
+
});
|
|
48
|
+
const res = (await tool.call({
|
|
49
|
+
args: toolArgs,
|
|
50
|
+
extra,
|
|
51
|
+
apifyMcpServer,
|
|
52
|
+
mcpServer: apifyMcpServer.server,
|
|
53
|
+
apifyToken,
|
|
54
|
+
apifyClient,
|
|
55
|
+
progressTracker,
|
|
56
|
+
mcpSessionId,
|
|
57
|
+
taskMode,
|
|
58
|
+
}));
|
|
59
|
+
// Extract diagnostics and strip internal fields from res before returning to client.
|
|
60
|
+
({ toolStatus, callDiagnostics } = applyToolTelemetry(res, actorName, actorId, callDiagnostics));
|
|
61
|
+
result = res;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
progressTracker === null || progressTracker === void 0 ? void 0 : progressTracker.stop();
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case TOOL_TYPE.ACTOR_MCP: {
|
|
69
|
+
// This case never throws: connect/exec failures resolve to a soft-fail `result`
|
|
70
|
+
// (isError body) below instead. As a task, that means the outer completeTask
|
|
71
|
+
// stores it via the 'completed' path (isError body) — deliberately matching sync's
|
|
72
|
+
// own soft-fail semantics, unlike ACTOR/INTERNAL, whose thrown errors land in the
|
|
73
|
+
// task caller's 'failed' path.
|
|
74
|
+
let client = null;
|
|
75
|
+
try {
|
|
76
|
+
client = await connectMCPClient(tool.serverUrl, apifyToken, mcpSessionId);
|
|
77
|
+
if (!client) {
|
|
78
|
+
const msg = dedent `
|
|
79
|
+
Failed to connect to MCP server at "${tool.serverUrl}".
|
|
80
|
+
Please verify the server URL is correct and accessible, and ensure you have a valid Apify token with appropriate permissions.
|
|
81
|
+
`;
|
|
82
|
+
log.softFail(msg, { mcpSessionId, failureCategory: FAILURE_CATEGORY.INTERNAL_ERROR });
|
|
83
|
+
await apifyMcpServer.server.sendLoggingMessage({ level: 'error', data: msg });
|
|
84
|
+
toolStatus = TOOL_STATUS.SOFT_FAIL;
|
|
85
|
+
callDiagnostics = { ...callDiagnostics, failure_category: FAILURE_CATEGORY.INTERNAL_ERROR };
|
|
86
|
+
result = respondErrorNoTelemetry(msg);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
// Only set up notification handlers if progressToken is provided by the client.
|
|
90
|
+
// Gated off for tasks (shouldForwardNotifications=false): the originating request is
|
|
91
|
+
// already answered, so forwarding against its progressToken would misroute.
|
|
92
|
+
if (shouldForwardNotifications && progressToken !== undefined && progressToken !== null) {
|
|
93
|
+
// Set up notification handlers for the client
|
|
94
|
+
for (const schema of ServerNotificationSchema.options) {
|
|
95
|
+
const method = schema.shape.method.value;
|
|
96
|
+
// Forward notifications from the proxy client to the server
|
|
97
|
+
client.setNotificationHandler(schema, async (notification) => {
|
|
98
|
+
log.debug('Sending MCP notification', {
|
|
99
|
+
method,
|
|
100
|
+
mcpSessionId,
|
|
101
|
+
notification,
|
|
102
|
+
});
|
|
103
|
+
await extra.sendNotification(notification);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
log.info(`Calling Actor-MCP${(_b = logContext === null || logContext === void 0 ? void 0 : logContext.messageSuffix) !== null && _b !== void 0 ? _b : ''}`, {
|
|
108
|
+
...logContext === null || logContext === void 0 ? void 0 : logContext.fields,
|
|
109
|
+
toolName: tool.name,
|
|
110
|
+
actorMcpToolName: tool.originToolName,
|
|
111
|
+
actorId: tool.actorId,
|
|
112
|
+
mcpSessionId,
|
|
113
|
+
input: logSafeArgs,
|
|
114
|
+
});
|
|
115
|
+
const res = await client.callTool({
|
|
116
|
+
name: tool.originToolName,
|
|
117
|
+
arguments: toolArgs,
|
|
118
|
+
// Without forwarding there is no route back for remote progress — don't
|
|
119
|
+
// hand the remote a token nobody listens to.
|
|
120
|
+
...(shouldForwardNotifications ? { _meta: { progressToken } } : {}),
|
|
121
|
+
}, CallToolResultSchema, {
|
|
122
|
+
timeout: EXTERNAL_TOOL_CALL_TIMEOUT_MSEC,
|
|
123
|
+
});
|
|
124
|
+
// TODO: actor-mcp responses are opaque — isError could be a user input problem
|
|
125
|
+
// (e.g. invalid query) or a genuine server failure. We can't distinguish without
|
|
126
|
+
// parsing the error text. Defaulting to INTERNAL_ERROR for now; revisit when
|
|
127
|
+
// actor-mcp gets deeper telemetry treatment.
|
|
128
|
+
if ('isError' in res && res.isError) {
|
|
129
|
+
toolStatus = TOOL_STATUS.SOFT_FAIL;
|
|
130
|
+
callDiagnostics = {
|
|
131
|
+
failure_category: FAILURE_CATEGORY.INTERNAL_ERROR,
|
|
132
|
+
...buildActorFields(actorName, actorId),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
result = { ...res };
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
toolStatus = getToolStatusFromError(error, Boolean((_c = extra.signal) === null || _c === void 0 ? void 0 : _c.aborted));
|
|
139
|
+
const failureDetail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
|
|
140
|
+
callDiagnostics = {
|
|
141
|
+
failure_category: classifyFailureCategory(error),
|
|
142
|
+
failure_detail: failureDetail,
|
|
143
|
+
...buildActorFields(actorName, actorId),
|
|
144
|
+
};
|
|
145
|
+
logHttpError(error, `Failed to call MCP tool '${tool.originToolName}' on Actor '${tool.actorId}'`, {
|
|
146
|
+
actorId: tool.actorId,
|
|
147
|
+
toolName: tool.originToolName,
|
|
148
|
+
failureCategory: callDiagnostics.failure_category,
|
|
149
|
+
});
|
|
150
|
+
result = respondErrorNoTelemetry(`Failed to call MCP tool '${tool.originToolName}' on Actor '${tool.actorId}': ${remoteMcpFailureDetail(error)}`);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (client)
|
|
154
|
+
await client.close();
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case TOOL_TYPE.ACTOR: {
|
|
159
|
+
try {
|
|
160
|
+
log.info(`Calling Actor${(_d = logContext === null || logContext === void 0 ? void 0 : logContext.messageSuffix) !== null && _d !== void 0 ? _d : ''}`, {
|
|
161
|
+
...logContext === null || logContext === void 0 ? void 0 : logContext.fields,
|
|
162
|
+
toolName: tool.name,
|
|
163
|
+
actorName: tool.actorFullName,
|
|
164
|
+
mcpSessionId,
|
|
165
|
+
input: logSafeArgs,
|
|
166
|
+
});
|
|
167
|
+
const executorResult = await actorExecutor.executeActorTool({
|
|
168
|
+
actorFullName: tool.actorFullName,
|
|
169
|
+
input: toolArgs,
|
|
170
|
+
apifyClient,
|
|
171
|
+
callOptions: { memory: tool.memoryMbytes },
|
|
172
|
+
progressTracker,
|
|
173
|
+
abortSignal: extra.signal,
|
|
174
|
+
mcpSessionId,
|
|
175
|
+
datasetItemsSchema: tool.datasetItemsSchema,
|
|
176
|
+
taskMode,
|
|
177
|
+
});
|
|
178
|
+
if (!executorResult) {
|
|
179
|
+
toolStatus = TOOL_STATUS.ABORTED;
|
|
180
|
+
// Receivers of cancellation notifications SHOULD NOT send a response for the cancelled request
|
|
181
|
+
// https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/cancellation#behavior-requirements
|
|
182
|
+
result = {};
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
// Mirror the INTERNAL branch: read the telemetry the executor embedded on error
|
|
186
|
+
// results (e.g. respondUserError → SOFT_FAIL/INVALID_INPUT), strip it from the wire,
|
|
187
|
+
// and set failure_category so the report-problem nudge picks the softer variant.
|
|
188
|
+
({ toolStatus, callDiagnostics } = applyToolTelemetry(executorResult, actorName, actorId, callDiagnostics));
|
|
189
|
+
result = executorResult;
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
if (progressTracker) {
|
|
193
|
+
progressTracker.stop();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
default:
|
|
199
|
+
// Exhaustiveness guard mirroring getToolFullName: a new TOOL_TYPE member makes `tool`
|
|
200
|
+
// non-`never` here and fails `satisfies never` at compile time. Unreachable at runtime —
|
|
201
|
+
// ToolEntry is a closed 3-way union. Unlike the pre-extraction fall-through (which also
|
|
202
|
+
// listed available tools, called log.softFail, and sent a logging message before
|
|
203
|
+
// throwing), this just throws InvalidParams with no side effects.
|
|
204
|
+
throw new McpError(ErrorCode.InvalidParams, `Unknown tool type "${tool.type}"`);
|
|
205
|
+
}
|
|
206
|
+
return { result, toolStatus, callDiagnostics };
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=tool_dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_dispatch.js","sourceRoot":"","sources":["../../src/mcp/tool_dispatch.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,wBAAwB,GAC3B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC9G,OAAO,EAAE,gBAAgB,EAAE,MAAM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CAAC;YACD,MAAM;QACV,CAAC;QAED;YACI,sFAAsF;YACtF,yFAAyF;YACzF,wFAAwF;YACxF,iFAAiF;YACjF,kEAAkE;YAClE,MAAM,IAAI,QAAQ,CACd,SAAS,CAAC,aAAa,EACvB,sBAAuB,IAAkC,CAAC,IAAI,GAAG,CACpE,CAAC;IACV,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/payments/const.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type HelperToolName } from '../const.js';
|
|
2
2
|
export declare const PAYMENT_PROTOCOL_HEADER = "x-apify-payment-protocol";
|
|
3
|
+
export declare const SKYFIRE_PAY_ID_KEY = "skyfire-pay-id";
|
|
3
4
|
export declare const SKYFIRE_TOOL_INSTRUCTIONS: string;
|
|
4
5
|
export declare const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = "Skyfire PAY JWT token used for billing purposes. This must be the JWT token string returned by the create-pay-token tool (starts with \"ey\"), NOT a token ID or UUID.";
|
|
5
6
|
export declare const SKYFIRE_README_CONTENT: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/payments/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAKlE,eAAO,MAAM,yBAAyB,QAAi2B,CAAC;AAEx4B,eAAO,MAAM,mCAAmC,2KAAyK,CAAC;AAE1N,eAAO,MAAM,sBAAsB,QAAs8B,CAAC;AAE1+B;;;GAGG;AACH,eAAO,MAAM,qBAAqB,qBAWhC,CAAC"}
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/payments/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAKlE,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD,eAAO,MAAM,yBAAyB,QAAi2B,CAAC;AAEx4B,eAAO,MAAM,mCAAmC,2KAAyK,CAAC;AAE1N,eAAO,MAAM,sBAAsB,QAAs8B,CAAC;AAE1+B;;;GAGG;AACH,eAAO,MAAM,qBAAqB,qBAWhC,CAAC"}
|
package/dist/payments/const.js
CHANGED
|
@@ -2,6 +2,7 @@ import { HELPER_TOOLS } from '../const.js';
|
|
|
2
2
|
export const PAYMENT_PROTOCOL_HEADER = 'x-apify-payment-protocol';
|
|
3
3
|
const SKYFIRE_MIN_CHARGE_USD = 5.0;
|
|
4
4
|
const SKYFIRE_SELLER_ID = process.env.SKYFIRE_SELLER_SERVICE_ID;
|
|
5
|
+
export const SKYFIRE_PAY_ID_KEY = 'skyfire-pay-id';
|
|
5
6
|
export const SKYFIRE_TOOL_INSTRUCTIONS = `To run the Actor, you need to provide a Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. You first need to create the Skyfire PAY token by calling the \`create-pay-token\` tool from the Skyfire MCP server and then provide the created JWT token in the \`skyfire-pay-id\` input property when calling Actor tool. IMPORTANT: The value you pass to \`skyfire-pay-id\` must be the JWT token string itself (it starts with "ey"), NOT an ID or UUID. The Skyfire PAY token is used for billing purposes and needs to be charged with at least ${SKYFIRE_MIN_CHARGE_USD} USD.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When retrieving Actor output using the \`get-dataset-items\` tool, you also need to provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`;
|
|
6
7
|
export const SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION = `Skyfire PAY JWT token used for billing purposes. This must be the JWT token string returned by the create-pay-token tool (starts with "ey"), NOT a token ID or UUID.`;
|
|
7
8
|
export const SKYFIRE_README_CONTENT = `The Apify MCP Server allows clients to interact with Apify Actors, storage, and documentation. Before running any Apify Actor, you need to set up a Skyfire PAY token for billing purposes. To set up the PAY token you need to use the create-pay-token tool from the Skyfire MCP server. The PAY token must be charged with a minimum of ${SKYFIRE_MIN_CHARGE_USD} USD to be valid.${SKYFIRE_SELLER_ID ? ` The Skyfire seller ID for Apify MCP server is "${SKYFIRE_SELLER_ID}".` : ''} When running an Actor using the call-actor tool, you must provide the Skyfire PAY JWT token in the \`skyfire-pay-id\` input property. IMPORTANT: The value for \`skyfire-pay-id\` must be the actual JWT token string (starting with "ey") returned by the create-pay-token tool, NOT a token ID or UUID. Similarly, when retrieving Actor output using the get-dataset-items tool, you must also provide the same Skyfire PAY JWT token (starting with "ey") in the \`skyfire-pay-id\` input property.`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/payments/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,aAAa,CAAC;AAEhE,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC;AAElE,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;AAEhE,MAAM,CAAC,MAAM,yBAAyB,GAAG,miBAAmiB,sBAAsB,QAAQ,iBAAiB,CAAC,CAAC,CAAC,mDAAmD,iBAAiB,IAAI,CAAC,CAAC,CAAC,EAAE,4LAA4L,CAAC;AAEx4B,MAAM,CAAC,MAAM,mCAAmC,GAAG,sKAAsK,CAAC;AAE1N,MAAM,CAAC,MAAM,sBAAsB,GAAG,8UAA8U,sBAAsB,oBAAoB,iBAAiB,CAAC,CAAC,CAAC,mDAAmD,iBAAiB,IAAI,CAAC,CAAC,CAAC,EAAE,0eAA0e,CAAC;AAE1+B;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAiB;IACzD,YAAY,CAAC,UAAU;IACvB,YAAY,CA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,CAAC,wBAAwB;IACrC,YAAY,CAAC,0BAA0B;CAC1C,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skyfire.d.ts","sourceRoot":"","sources":["../../src/payments/skyfire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"skyfire.d.ts","sourceRoot":"","sources":["../../src/payments/skyfire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAU7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC1D,QAAQ,CAAC,EAAE,EAAG,SAAS,CAAU;IACjC,QAAQ,CAAC,qBAAqB,QAAQ;WAEzB,MAAM,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAItD,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS;IAwB9C,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IAO7D,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc;IAWhE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAK3E,aAAa,IAAI,MAAM,GAAG,IAAI;IAI9B,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;CAO3C"}
|
package/dist/payments/skyfire.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { redactSkyfirePayId } from '../utils/logging.js';
|
|
2
2
|
import { cloneToolEntry } from '../utils/tools.js';
|
|
3
|
-
import { PAYMENT_PROTOCOL_HEADER, SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_README_CONTENT, SKYFIRE_TOOL_INSTRUCTIONS, } from './const.js';
|
|
4
|
-
const SKYFIRE_PAY_ID_KEY = 'skyfire-pay-id';
|
|
3
|
+
import { PAYMENT_PROTOCOL_HEADER, SKYFIRE_PAY_ID_KEY, SKYFIRE_PAY_ID_PROPERTY_DESCRIPTION, SKYFIRE_README_CONTENT, SKYFIRE_TOOL_INSTRUCTIONS, } from './const.js';
|
|
5
4
|
/**
|
|
6
5
|
* Skyfire payment provider.
|
|
7
6
|
*
|
|
@@ -70,10 +69,10 @@ export class SkyfirePaymentProvider {
|
|
|
70
69
|
return SKYFIRE_README_CONTENT;
|
|
71
70
|
}
|
|
72
71
|
redactForLogging(args) {
|
|
73
|
-
// TODO: redactSkyfirePayId is still
|
|
74
|
-
// Once
|
|
75
|
-
// remove the standalone function and
|
|
76
|
-
//
|
|
72
|
+
// TODO: redactSkyfirePayId is still used directly by other in-repo callers
|
|
73
|
+
// (e.g. tools/actors/actor_executor.ts). Once those callers migrate to
|
|
74
|
+
// `paymentProvider.redactForLogging()`, remove the standalone function and
|
|
75
|
+
// centralize the redaction logic entirely inside this provider.
|
|
77
76
|
return redactSkyfirePayId(args);
|
|
78
77
|
}
|
|
79
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skyfire.js","sourceRoot":"","sources":["../../src/payments/skyfire.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACH,uBAAuB,EACvB,mCAAmC,EACnC,sBAAsB,EACtB,yBAAyB,GAC5B,MAAM,YAAY,CAAC;AAGpB
|
|
1
|
+
{"version":3,"file":"skyfire.js","sourceRoot":"","sources":["../../src/payments/skyfire.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAA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IAAI,CAAC;QAClK,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,iBAAiB,CAAC,IAA6B;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO;gBACH,CAAC,kBAAkB,CAAC,EAAE,KAAK;gBAC3B,CAAC,uBAAuB,CAAC,EAAE,SAAS;aACvC,CAAC;QACN,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;IAED,mBAAmB,CAAC,IAA6B;QAC7C,MAAM,EAAE,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QACzD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,aAAa;QACT,OAAO,sBAAsB,CAAC;IAClC,CAAC;IAED,gBAAgB,CAAC,IAAa;QAC1B,2EAA2E;QAC3E,uEAAuE;QACvE,2EAA2E;QAC3E,gEAAgE;QAChE,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ApifyApiError } from 'apify-client';
|
|
2
1
|
import { z } from 'zod';
|
|
3
2
|
import { HELPER_TOOLS } from '../../const.js';
|
|
4
3
|
import type { PaymentProvider } from '../../payments/types.js';
|
|
@@ -20,8 +19,6 @@ type CallActorErrorResponseParams = {
|
|
|
20
19
|
};
|
|
21
20
|
export declare function buildCallActorDescription(): string;
|
|
22
21
|
export declare function buildCallActorAppsDescription(): string;
|
|
23
|
-
/** Exported for native actor tool error handling in server.ts — no logging, no telemetry. */
|
|
24
|
-
export declare function buildPermissionApprovalResponse(error: ApifyApiError): ToolResponse;
|
|
25
22
|
export declare function buildCallActorErrorResponse(params: CallActorErrorResponseParams): ToolResponse;
|
|
26
23
|
export declare const callOptionsSchema: z.ZodObject<{
|
|
27
24
|
memory: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call_actor.d.ts","sourceRoot":"","sources":["../../../src/tools/actors/call_actor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"call_actor.d.ts","sourceRoot":"","sources":["../../../src/tools/actors/call_actor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAKH,YAAY,EACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAa,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAc1G,OAAO,EAKH,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAqB5B,eAAO,MAAM,oCAAoC,2JAAuJ,CAAC;AAEzM,gEAAgE;AAChE,eAAO,MAAM,6BAA6B,+MAEmD,CAAC;AAE9F,0EAA0E;AAC1E,eAAO,MAAM,wBAAwB,QAMqD,CAAC;AAE3F,yDAAyD;AACzD,eAAO,MAAM,2BAA2B,+EACwB,CAAC;AAEjE,KAAK,4BAA4B,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,OAAO,YAAY,CAAC,iBAAiB,CAAC;CAC9D,CAAC;AAqCF,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED,wBAAgB,6BAA6B,IAAI,MAAM,CAEtD;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,4BAA4B,GAAG,YAAY,CAqD9F;AAED,eAAO,MAAM,iBAAiB;;;;;;iBA2B5B,CAAC;AAEH,sFAAsF;AACtF,eAAO,MAAM,aAAa;;;;;;;;;;;iBAsBxB,CAAC;AAEH,eA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EAAE,SAAS,CAAA;CAAE,CAAC,CAiF1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACrC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3B,OAAO,CACJ;IAAE,aAAa,EAAE,YAAY,CAAA;CAAE,GAC/B;IACI,MAAM,EAAE,mBAAmB,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC,CACN,CAyCA;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CA8ExF;AA+BD,oCAAoC;AACpC,eAAO,MAAM,gBAAgB,EAAE,SAA4D,CAAC;AAE5F;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAgE,CAAC"}
|
|
@@ -12,7 +12,8 @@ import { ACTOR_RUN_LIMIT_MESSAGE, isActorRunLimitError, isMemoryQuotaError, isPe
|
|
|
12
12
|
import { getConsoleLinkContext } from '../../utils/console_link.js';
|
|
13
13
|
import { wrapJsonText } from '../../utils/encode_text.js';
|
|
14
14
|
import { logHttpError } from '../../utils/logging.js';
|
|
15
|
-
import { respondAborted,
|
|
15
|
+
import { respondAborted, respondRaw, respondServerError, respondUserError, } from '../../utils/mcp.js';
|
|
16
|
+
import { buildPermissionApprovalTexts } from '../../utils/payment_errors.js';
|
|
16
17
|
import { classifyFailureCategory, extractAjvErrorDetails } from '../../utils/tool_status.js';
|
|
17
18
|
import { extractActorId } from '../../utils/tools.js';
|
|
18
19
|
import { actorNameToToolName, isActorBlockedUnderPaymentProvider } from '../actor_tool_naming.js';
|
|
@@ -78,16 +79,6 @@ export function buildCallActorDescription() {
|
|
|
78
79
|
export function buildCallActorAppsDescription() {
|
|
79
80
|
return buildCallActorDescriptionSections(true);
|
|
80
81
|
}
|
|
81
|
-
/** Text lines for a permission-approval response: the error message plus an optional approval URL. */
|
|
82
|
-
function buildPermissionApprovalTexts(error) {
|
|
83
|
-
var _a;
|
|
84
|
-
const approvalUrl = typeof ((_a = error.data) === null || _a === void 0 ? void 0 : _a.approvalUrl) === 'string' ? error.data.approvalUrl : undefined;
|
|
85
|
-
return [error.message, ...(approvalUrl ? [`Approve here: ${approvalUrl}`] : [])];
|
|
86
|
-
}
|
|
87
|
-
/** Exported for native actor tool error handling in server.ts — no logging, no telemetry. */
|
|
88
|
-
export function buildPermissionApprovalResponse(error) {
|
|
89
|
-
return respondErrorNoTelemetry(buildPermissionApprovalTexts(error));
|
|
90
|
-
}
|
|
91
82
|
export function buildCallActorErrorResponse(params) {
|
|
92
83
|
const { actorName, error, actorId, mcpSessionId, actorGetDetailsTool } = params;
|
|
93
84
|
if (isPermissionApprovalError(error)) {
|