@apify/actors-mcp-server 0.12.1-beta.0 → 0.12.1-beta.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/dist/dev_server.d.ts +19 -0
- package/dist/dev_server.d.ts.map +1 -1
- package/dist/dev_server.js +27 -11
- package/dist/dev_server.js.map +1 -1
- package/dist/mcp/client_context.d.ts +11 -0
- package/dist/mcp/client_context.d.ts.map +1 -0
- package/dist/mcp/client_context.js +24 -0
- package/dist/mcp/client_context.js.map +1 -0
- package/dist/mcp/errors.d.ts +19 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +43 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -12
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +49 -60
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/task_execution.d.ts +2 -0
- package/dist/mcp/task_execution.d.ts.map +1 -1
- package/dist/mcp/task_execution.js +2 -1
- package/dist/mcp/task_execution.js.map +1 -1
- package/dist/mcp/tool_call_engine.d.ts +2 -0
- package/dist/mcp/tool_call_engine.d.ts.map +1 -1
- package/dist/mcp/tool_call_engine.js +2 -2
- package/dist/mcp/tool_call_engine.js.map +1 -1
- package/dist/mcp/tool_call_telemetry.d.ts +2 -0
- package/dist/mcp/tool_call_telemetry.d.ts.map +1 -1
- package/dist/mcp/tool_call_telemetry.js +7 -9
- package/dist/mcp/tool_call_telemetry.js.map +1 -1
- package/dist/prompts/prompt_service.d.ts +26 -0
- package/dist/prompts/prompt_service.d.ts.map +1 -0
- package/dist/prompts/prompt_service.js +37 -0
- package/dist/prompts/prompt_service.js.map +1 -0
- package/dist/resources/api_resources.d.ts +3 -2
- package/dist/resources/api_resources.d.ts.map +1 -1
- package/dist/resources/api_resources.js +15 -13
- package/dist/resources/api_resources.js.map +1 -1
- package/dist/resources/resource_service.d.ts.map +1 -1
- package/dist/resources/resource_service.js +2 -2
- package/dist/resources/resource_service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/mcp_clients.d.ts +3 -3
- package/dist/utils/mcp_clients.d.ts.map +1 -1
- package/dist/utils/mcp_clients.js +6 -6
- package/dist/utils/mcp_clients.js.map +1 -1
- package/package.json +1 -1
package/dist/dev_server.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import type { InitializeRequestParams } from '@modelcontextprotocol/sdk/types.js';
|
|
1
2
|
import express from 'express';
|
|
2
3
|
export declare function createExpressApp(): express.Express;
|
|
4
|
+
/**
|
|
5
|
+
* Finds the `initialize` message in a (possibly batched) request body, matching on `method`
|
|
6
|
+
* alone like the pre-refactor `isInitializeRequest` did. This must stay a loose tag check: a
|
|
7
|
+
* body with `method: 'initialize'` but malformed/incomplete `params` still needs to enter the
|
|
8
|
+
* initialize branch below so the SDK's own initialize-schema validation produces the accurate
|
|
9
|
+
* protocol error, instead of falling through to the generic "Mcp-Session-Id header is required"
|
|
10
|
+
* 400 from the no-session branch.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractInitializeMessage(body: unknown): {
|
|
13
|
+
method: string;
|
|
14
|
+
params?: unknown;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Type-safe extraction of `initialize` params for `buildMcpClientContext`/request-origin.
|
|
18
|
+
* Malformed params parse to `undefined` (client context stays unset) rather than being cast
|
|
19
|
+
* unchecked — the SDK validates the full request separately once it takes over below.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseInitializeParams(params: unknown): InitializeRequestParams | undefined;
|
|
3
22
|
//# sourceMappingURL=dev_server.d.ts.map
|
package/dist/dev_server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev_server.d.ts","sourceRoot":"","sources":["../src/dev_server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev_server.d.ts","sourceRoot":"","sources":["../src/dev_server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAGlF,OAAO,OAAO,MAAM,SAAS,CAAC;AA+E9B,wBAAgB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAmMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAMxG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAG1F"}
|
package/dist/dev_server.js
CHANGED
|
@@ -7,10 +7,12 @@ import { randomUUID } from 'node:crypto';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental/tasks/stores/in-memory.js';
|
|
9
9
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
10
|
+
import { InitializeRequestParamsSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
10
11
|
import express from 'express';
|
|
11
12
|
import log from '@apify/log';
|
|
12
13
|
import { parseBooleanOrNull } from '@apify/utilities';
|
|
13
14
|
import { ApifyClient } from './apify_client.js';
|
|
15
|
+
import { buildMcpClientContext } from './mcp/client_context.js';
|
|
14
16
|
import { ActorsMcpServer } from './mcp/server.js';
|
|
15
17
|
import { resolvePaymentProvider } from './payments/index.js';
|
|
16
18
|
import { injectMcpSessionId } from './utils/mcp.js';
|
|
@@ -114,12 +116,13 @@ export function createExpressApp() {
|
|
|
114
116
|
try {
|
|
115
117
|
// Check for existing session ID
|
|
116
118
|
const sessionId = req.headers['mcp-session-id'];
|
|
119
|
+
const initializeMessage = extractInitializeMessage(req.body);
|
|
117
120
|
let transport;
|
|
118
121
|
if (sessionId && transports[sessionId]) {
|
|
119
122
|
// Reuse existing transport
|
|
120
123
|
transport = transports[sessionId];
|
|
121
124
|
}
|
|
122
|
-
else if (!sessionId &&
|
|
125
|
+
else if (!sessionId && initializeMessage) {
|
|
123
126
|
// Extract telemetry query parameters
|
|
124
127
|
const urlParams = new URL(req.url, `http://${req.headers.host}`).searchParams;
|
|
125
128
|
const telemetryEnabledParam = urlParams.get('telemetry-enabled');
|
|
@@ -145,10 +148,9 @@ export function createExpressApp() {
|
|
|
145
148
|
paymentProvider,
|
|
146
149
|
token: apifyToken,
|
|
147
150
|
});
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
const requestOrigin = getRequestOriginForClient(req.body);
|
|
151
|
+
// Client info is already available here — unlike stdio.ts, which loads tools
|
|
152
|
+
// before initialization.
|
|
153
|
+
const requestOrigin = getRequestOriginForClient(buildMcpClientContext(parseInitializeParams(initializeMessage.params)));
|
|
152
154
|
const apifyClient = new ApifyClient({ token: apifyToken, requestOrigin });
|
|
153
155
|
// Fetch actor metadata and queue mode-agnostic sources. Composed with
|
|
154
156
|
// the final mode inside the initialize request handler.
|
|
@@ -259,12 +261,26 @@ export function createExpressApp() {
|
|
|
259
261
|
});
|
|
260
262
|
return app;
|
|
261
263
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Finds the `initialize` message in a (possibly batched) request body, matching on `method`
|
|
266
|
+
* alone like the pre-refactor `isInitializeRequest` did. This must stay a loose tag check: a
|
|
267
|
+
* body with `method: 'initialize'` but malformed/incomplete `params` still needs to enter the
|
|
268
|
+
* initialize branch below so the SDK's own initialize-schema validation produces the accurate
|
|
269
|
+
* protocol error, instead of falling through to the generic "Mcp-Session-Id header is required"
|
|
270
|
+
* 400 from the no-session branch.
|
|
271
|
+
*/
|
|
272
|
+
export function extractInitializeMessage(body) {
|
|
273
|
+
const messages = Array.isArray(body) ? body : [body];
|
|
274
|
+
return messages.find((msg) => typeof msg === 'object' && msg !== null && msg.method === 'initialize');
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Type-safe extraction of `initialize` params for `buildMcpClientContext`/request-origin.
|
|
278
|
+
* Malformed params parse to `undefined` (client context stays unset) rather than being cast
|
|
279
|
+
* unchecked — the SDK validates the full request separately once it takes over below.
|
|
280
|
+
*/
|
|
281
|
+
export function parseInitializeParams(params) {
|
|
282
|
+
const result = InitializeRequestParamsSchema.safeParse(params);
|
|
283
|
+
return result.success ? result.data : undefined;
|
|
268
284
|
}
|
|
269
285
|
// --- Entry point: start the server when run directly ---
|
|
270
286
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
package/dist/dev_server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev_server.js","sourceRoot":"","sources":["../src/dev_server.ts"],"names":[],"mappings":"AAAA;;GAEG;;;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kEAAkE,CAAC;AACrG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"dev_server.js","sourceRoot":"","sources":["../src/dev_server.ts"],"names":[],"mappings":"AAAA;;GAEG;;;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kEAAkE,CAAC;AACrG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEnF,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kB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CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,kBAAkB,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IAE9C,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAE/B,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;QAC/B,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,GAAG,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClientCapabilities, Implementation, InitializeRequestParams } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
export type McpClientContext = {
|
|
3
|
+
readonly protocolVersion?: string;
|
|
4
|
+
readonly clientInfo?: Readonly<Implementation>;
|
|
5
|
+
readonly capabilities?: Readonly<ClientCapabilities> & Readonly<Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
type McpInitializeParams = Partial<Pick<InitializeRequestParams, 'protocolVersion' | 'clientInfo' | 'capabilities'>>;
|
|
8
|
+
export declare function buildMcpClientContext(params: McpInitializeParams | undefined): McpClientContext | undefined;
|
|
9
|
+
export declare function isUiSupportedByClient(context: McpClientContext | undefined): boolean;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=client_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_context.d.ts","sourceRoot":"","sources":["../../src/mcp/client_context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAEtH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5F,CAAC;AAEF,KAAK,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,iBAAiB,GAAG,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC;AAErH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAW3G;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GAAG,OAAO,CAKpF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The ext-apps package exposes `./server` via conditional exports only (no `./server/index.js`
|
|
2
|
+
// wildcard), so we can't satisfy the `import/extensions` rule on this subpath.
|
|
3
|
+
// eslint-disable-next-line import/extensions
|
|
4
|
+
import { getUiCapability, RESOURCE_MIME_TYPE } from '@modelcontextprotocol/ext-apps/server';
|
|
5
|
+
export function buildMcpClientContext(params) {
|
|
6
|
+
if (!params)
|
|
7
|
+
return undefined;
|
|
8
|
+
return {
|
|
9
|
+
...(params.protocolVersion !== undefined && { protocolVersion: params.protocolVersion }),
|
|
10
|
+
// The SDK's `Implementation`/`clientInfo` shape carries optional nested fields (`icons[]`,
|
|
11
|
+
// `title`, `websiteUrl`, `description`) beyond {name, version}, so clone it the same way as
|
|
12
|
+
// capabilities — a shallow spread would share those nested objects/arrays by reference.
|
|
13
|
+
...(params.clientInfo !== undefined && { clientInfo: structuredClone(params.clientInfo) }),
|
|
14
|
+
...(params.capabilities !== undefined && { capabilities: structuredClone(params.capabilities) }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function isUiSupportedByClient(context) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
// `Readonly<ClientCapabilities>` and the ext-apps helper's capabilities type describe the same
|
|
20
|
+
// runtime object; this cast only crosses their type boundary.
|
|
21
|
+
const uiCapability = getUiCapability(context === null || context === void 0 ? void 0 : context.capabilities);
|
|
22
|
+
return (_b = (_a = uiCapability === null || uiCapability === void 0 ? void 0 : uiCapability.mimeTypes) === null || _a === void 0 ? void 0 : _a.includes(RESOURCE_MIME_TYPE)) !== null && _b !== void 0 ? _b : false;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=client_context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_context.js","sourceRoot":"","sources":["../../src/mcp/client_context.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,+EAA+E;AAC/E,6CAA6C;AAC7C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAW5F,MAAM,UAAU,qBAAqB,CAAC,MAAuC;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAE9B,OAAO;QACH,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QACxF,2FAA2F;QAC3F,4FAA4F;QAC5F,wFAAwF;QACxF,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1F,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,eAAe,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;KACnG,CAAC;AACN,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAqC;;IACvE,+FAA+F;IAC/F,8DAA8D;IAC9D,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAqD,CAAC,CAAC;IACrG,OAAO,MAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,SAAS,0CAAE,QAAQ,CAAC,kBAAkB,CAAC,mCAAI,KAAK,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol-neutral domain errors for the prompt and resource services. They carry the message and
|
|
3
|
+
* optional `data` payload but no protocol error code — the `server.ts` boundary maps each 1:1 to a
|
|
4
|
+
* v1 `McpError` right before serialization, and a future v2 adapter maps them to its own error type.
|
|
5
|
+
* This module imports nothing from any MCP SDK.
|
|
6
|
+
*/
|
|
7
|
+
/** A request/resource-level fault (bad URI, missing token, non-Apify origin, 3xx/4xx except 429). */
|
|
8
|
+
export declare class InvalidParamsError extends Error {
|
|
9
|
+
readonly data?: unknown | undefined;
|
|
10
|
+
readonly name = "InvalidParamsError";
|
|
11
|
+
constructor(message: string, data?: unknown | undefined);
|
|
12
|
+
}
|
|
13
|
+
/** A transient/upstream fault (429, 5xx, network or mid-stream drop). */
|
|
14
|
+
export declare class InternalError extends Error {
|
|
15
|
+
readonly data?: unknown | undefined;
|
|
16
|
+
readonly name = "InternalError";
|
|
17
|
+
constructor(message: string, data?: unknown | undefined);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/mcp/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qGAAqG;AACrG,qBAAa,kBAAmB,SAAQ,KAAK;aAKrB,IAAI,CAAC,EAAE,OAAO;IAJlC,SAAkB,IAAI,wBAAwB;gBAG1C,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,OAAO,YAAA;CAIrC;AAED,yEAAyE;AACzE,qBAAa,aAAc,SAAQ,KAAK;aAKhB,IAAI,CAAC,EAAE,OAAO;IAJlC,SAAkB,IAAI,mBAAmB;gBAGrC,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,OAAO,YAAA;CAIrC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol-neutral domain errors for the prompt and resource services. They carry the message and
|
|
3
|
+
* optional `data` payload but no protocol error code — the `server.ts` boundary maps each 1:1 to a
|
|
4
|
+
* v1 `McpError` right before serialization, and a future v2 adapter maps them to its own error type.
|
|
5
|
+
* This module imports nothing from any MCP SDK.
|
|
6
|
+
*/
|
|
7
|
+
/** A request/resource-level fault (bad URI, missing token, non-Apify origin, 3xx/4xx except 429). */
|
|
8
|
+
export class InvalidParamsError extends Error {
|
|
9
|
+
constructor(message, data) {
|
|
10
|
+
super(message);
|
|
11
|
+
Object.defineProperty(this, "data", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: data
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "name", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: 'InvalidParamsError'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** A transient/upstream fault (429, 5xx, network or mid-stream drop). */
|
|
26
|
+
export class InternalError extends Error {
|
|
27
|
+
constructor(message, data) {
|
|
28
|
+
super(message);
|
|
29
|
+
Object.defineProperty(this, "data", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: data
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "name", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: 'InternalError'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/mcp/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qGAAqG;AACrG,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzC,YACI,OAAe,EACC,IAAc;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFf;;;;mBAAgB,IAAI;WAAU;QAJhB;;;;mBAAO,oBAAoB;WAAC;IAO9C,CAAC;CACJ;AAED,yEAAyE;AACzE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGpC,YACI,OAAe,EACC,IAAc;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFf;;;;mBAAgB,IAAI;WAAU;QAJhB;;;;mBAAO,eAAe;WAAC;IAOzC,CAAC;CACJ"}
|
package/dist/mcp/server.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class ActorsMcpServer {
|
|
|
20
20
|
readonly options: ActorsMcpServerOptions;
|
|
21
21
|
readonly taskStore: TaskStore;
|
|
22
22
|
readonly actorStore?: ActorStore;
|
|
23
|
+
private clientContext;
|
|
23
24
|
/**
|
|
24
25
|
* Resolved server mode. Preliminary value at construction (`'auto'` → `DEFAULT`).
|
|
25
26
|
* Finalized inside the `initialize` request handler (see constructor) once the
|
|
@@ -142,7 +143,6 @@ export declare class ActorsMcpServer {
|
|
|
142
143
|
/**
|
|
143
144
|
* Loads missing toolNames from a provided list of tool names.
|
|
144
145
|
* Skips toolNames that are already loaded and loads only the missing ones.
|
|
145
|
-
* @param toolNames - Array of tool names to ensure are loaded
|
|
146
146
|
*/
|
|
147
147
|
loadToolsByName(toolNames: string[], apifyClient: ApifyClient): Promise<void>;
|
|
148
148
|
/**
|
|
@@ -191,21 +191,13 @@ export declare class ActorsMcpServer {
|
|
|
191
191
|
* Token-scoped client for resources/read (the API proxy needs auth). Deliberately token-only:
|
|
192
192
|
* unlike the CallTool path it does NOT forward provider/payment headers, so a payment-only
|
|
193
193
|
* session (x402/Skyfire, no Apify token) has no client and every read fails by design.
|
|
194
|
-
* Still carries the request-origin tag
|
|
194
|
+
* Still carries the request-origin tag from the client context captured by this point.
|
|
195
195
|
*/
|
|
196
196
|
private resolveApifyClient;
|
|
197
197
|
private setupResourceHandlers;
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
private listPrompts;
|
|
202
|
-
/**
|
|
203
|
-
* Builds the prompts/get result: find → not-found → validate → render.
|
|
204
|
-
* Throws {@link McpError} for an unknown prompt name or invalid arguments (v1 behavior).
|
|
205
|
-
*/
|
|
206
|
-
private getPrompt;
|
|
207
|
-
/**
|
|
208
|
-
* Sets up MCP request handlers for prompts.
|
|
199
|
+
* Sets up MCP request handlers for prompts. The prompt service throws domain errors; the
|
|
200
|
+
* boundary maps them to `McpError` so wire output is unchanged.
|
|
209
201
|
*/
|
|
210
202
|
private setupPromptHandlers;
|
|
211
203
|
/**
|
package/dist/mcp/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4DAA4D,CAAC;AAE5F,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAyB/E,OAAO,EAAE,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OAAO,CAAC,qBAAqB;IA2B7B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;YACW,cAAc;IAU5B;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,iBAAiB;IA8QzB;;OAEG;YACW,cAAc;IA4CtB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB/B"}
|
package/dist/mcp/server.js
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
* Model Context Protocol (MCP) server for Apify Actors
|
|
3
3
|
*/
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
|
-
// The ext-apps package exposes `./server` via conditional exports only (no `./server/index.js`
|
|
6
|
-
// wildcard), so we can't satisfy the `import/extensions` rule on this subpath.
|
|
7
|
-
// eslint-disable-next-line import/extensions
|
|
8
|
-
import { getUiCapability, RESOURCE_MIME_TYPE } from '@modelcontextprotocol/ext-apps/server';
|
|
9
5
|
import { InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental/tasks/stores/in-memory.js';
|
|
10
6
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
11
7
|
import { CallToolRequestSchema, CancelTaskRequestSchema, ErrorCode, GetPromptRequestSchema, GetTaskPayloadRequestSchema, GetTaskRequestSchema, InitializeRequestSchema, ListPromptsRequestSchema, ListResourcesRequestSchema, ListResourceTemplatesRequestSchema, ListTasksRequestSchema, ListToolsRequestSchema, McpError, ReadResourceRequestSchema, RELATED_TASK_META_KEY, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
@@ -14,6 +10,7 @@ import { parseBooleanOrNull } from '@apify/utilities';
|
|
|
14
10
|
import { ApifyClient } from '../apify_client.js';
|
|
15
11
|
import { DEFAULT_TELEMETRY_ENABLED, DEFAULT_TELEMETRY_ENV, FAILURE_CATEGORY, HELPER_TOOLS, TOOL_STATUS, } from '../const.js';
|
|
16
12
|
import { prompts } from '../prompts/index.js';
|
|
13
|
+
import { createPromptService } from '../prompts/prompt_service.js';
|
|
17
14
|
import { createResourceService } from '../resources/resource_service.js';
|
|
18
15
|
import { resolveAvailableWidgets } from '../resources/widgets.js';
|
|
19
16
|
import { getServerInfo } from '../server_card.js';
|
|
@@ -27,29 +24,31 @@ import { getServerInstructions } from '../utils/server-instructions/index.js';
|
|
|
27
24
|
import { parseServerMode, resolveServerMode } from '../utils/server_mode.js';
|
|
28
25
|
import { buildActorFields, getToolFullName, getToolPublicFieldOnly } from '../utils/tools.js';
|
|
29
26
|
import { getActors, getToolsForServerMode, toolNamesToInput } from '../utils/tools_loader.js';
|
|
27
|
+
import { buildMcpClientContext, isUiSupportedByClient } from './client_context.js';
|
|
30
28
|
import { LOG_LEVEL_MAP } from './const.js';
|
|
29
|
+
import { InternalError, InvalidParamsError } from './errors.js';
|
|
31
30
|
import { emitTaskStatusNotification, executeToolAndUpdateTask } from './task_execution.js';
|
|
32
31
|
import { buildPreflightFailureOutcome, classifyToolCallError, executeSyncToolCall, prepareToolCall, } from './tool_call_engine.js';
|
|
33
32
|
import { logToolCallAndTelemetry, prepareTelemetryData } from './tool_call_telemetry.js';
|
|
34
33
|
import { parseInputParamsFromUrl, storeTaskResultOrSkipIfExpired } from './utils.js';
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* Uses {@link getUiCapability} from `@modelcontextprotocol/ext-apps/server` to
|
|
40
|
-
* read the `io.modelcontextprotocol/ui` extension from client capabilities — the
|
|
41
|
-
* canonical way per the MCP Apps spec.
|
|
35
|
+
* Legacy protocol boundary: project a service's domain error to its v1 `McpError`, copying `message`
|
|
36
|
+
* and `data` unchanged so the wire output (code, message, presence of `data`) is byte-identical.
|
|
37
|
+
* Non-domain errors pass through untouched.
|
|
42
38
|
*/
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
function toLegacyMcpError(error) {
|
|
40
|
+
if (error instanceof InvalidParamsError)
|
|
41
|
+
return new McpError(ErrorCode.InvalidParams, error.message, error.data);
|
|
42
|
+
if (error instanceof InternalError)
|
|
43
|
+
return new McpError(ErrorCode.InternalError, error.message, error.data);
|
|
44
|
+
return error;
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* Create Apify MCP server
|
|
50
48
|
*/
|
|
51
49
|
export class ActorsMcpServer {
|
|
52
50
|
constructor(options = {}) {
|
|
51
|
+
var _a;
|
|
53
52
|
Object.defineProperty(this, "server", {
|
|
54
53
|
enumerable: true,
|
|
55
54
|
configurable: true,
|
|
@@ -98,6 +97,12 @@ export class ActorsMcpServer {
|
|
|
98
97
|
writable: true,
|
|
99
98
|
value: void 0
|
|
100
99
|
});
|
|
100
|
+
Object.defineProperty(this, "clientContext", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: void 0
|
|
105
|
+
});
|
|
101
106
|
/**
|
|
102
107
|
* Resolved server mode. Preliminary value at construction (`'auto'` → `DEFAULT`).
|
|
103
108
|
* Finalized inside the `initialize` request handler (see constructor) once the
|
|
@@ -171,6 +176,7 @@ export class ActorsMcpServer {
|
|
|
171
176
|
value: false
|
|
172
177
|
});
|
|
173
178
|
this.options = options;
|
|
179
|
+
this.clientContext = buildMcpClientContext((_a = options.initializeRequestData) === null || _a === void 0 ? void 0 : _a.params);
|
|
174
180
|
// for stdio use in memory task store if not provided, otherwise use provided task store
|
|
175
181
|
if (this.options.transportType === 'stdio' && !this.options.taskStore) {
|
|
176
182
|
this.taskStore = new InMemoryTaskStore();
|
|
@@ -274,7 +280,9 @@ export class ActorsMcpServer {
|
|
|
274
280
|
const sdkInitHandler = this.server._oninitialize.bind(this.server);
|
|
275
281
|
this.server.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
276
282
|
var _a;
|
|
277
|
-
this.
|
|
283
|
+
this.clientContext = buildMcpClientContext(request.params);
|
|
284
|
+
this.options.initializeRequestData = request;
|
|
285
|
+
this.clientSupportsUi = isUiSupportedByClient(this.clientContext);
|
|
278
286
|
if (this.serverModeOption === 'auto') {
|
|
279
287
|
const resolved = resolveServerMode('auto', this.clientSupportsUi);
|
|
280
288
|
if (resolved !== this.serverMode) {
|
|
@@ -282,9 +290,6 @@ export class ActorsMcpServer {
|
|
|
282
290
|
}
|
|
283
291
|
this.serverModeResolved = true;
|
|
284
292
|
}
|
|
285
|
-
// Setting this makes `clientKnown` true, so the queued compose below (and any later
|
|
286
|
-
// load) resolves the tool set for this client and applies the per-client blocklist.
|
|
287
|
-
this.options.initializeRequestData = request;
|
|
288
293
|
log.info('Resolved server mode for client capabilities', {
|
|
289
294
|
serverMode: this.serverMode,
|
|
290
295
|
serverModeOption: this.serverModeOption,
|
|
@@ -305,7 +310,7 @@ export class ActorsMcpServer {
|
|
|
305
310
|
* recovery path). Only client-gated tools wait for this so the per-client blocklist can be
|
|
306
311
|
* applied; client-agnostic tools compose regardless. */
|
|
307
312
|
get clientKnown() {
|
|
308
|
-
return this.
|
|
313
|
+
return this.clientContext != null;
|
|
309
314
|
}
|
|
310
315
|
/**
|
|
311
316
|
* Compose the tool list for the current connection: resolve mode-specific tools, then drop
|
|
@@ -333,9 +338,7 @@ export class ActorsMcpServer {
|
|
|
333
338
|
* survive a load that never sees an initialize.
|
|
334
339
|
*/
|
|
335
340
|
isReportProblemServable() {
|
|
336
|
-
return
|
|
337
|
-
this.clientKnown &&
|
|
338
|
-
!isReportProblemBlockedForClient(this.options.initializeRequestData));
|
|
341
|
+
return this.telemetryEnabled && this.clientKnown && !isReportProblemBlockedForClient(this.clientContext);
|
|
339
342
|
}
|
|
340
343
|
composePendingToolsForClient() {
|
|
341
344
|
if (this.pendingToolsUntilClientKnown.length === 0)
|
|
@@ -439,7 +442,6 @@ export class ActorsMcpServer {
|
|
|
439
442
|
/**
|
|
440
443
|
* Loads missing toolNames from a provided list of tool names.
|
|
441
444
|
* Skips toolNames that are already loaded and loads only the missing ones.
|
|
442
|
-
* @param toolNames - Array of tool names to ensure are loaded
|
|
443
445
|
*/
|
|
444
446
|
async loadToolsByName(toolNames, apifyClient) {
|
|
445
447
|
const loadedTools = new Set(this.listAllToolNames());
|
|
@@ -608,12 +610,12 @@ export class ActorsMcpServer {
|
|
|
608
610
|
* Token-scoped client for resources/read (the API proxy needs auth). Deliberately token-only:
|
|
609
611
|
* unlike the CallTool path it does NOT forward provider/payment headers, so a payment-only
|
|
610
612
|
* session (x402/Skyfire, no Apify token) has no client and every read fails by design.
|
|
611
|
-
* Still carries the request-origin tag
|
|
613
|
+
* Still carries the request-origin tag from the client context captured by this point.
|
|
612
614
|
*/
|
|
613
615
|
resolveApifyClient(params) {
|
|
614
616
|
const token = this.resolveApifyToken(params._meta);
|
|
615
617
|
return token
|
|
616
|
-
? new ApifyClient({ token, requestOrigin: getRequestOriginForClient(this.
|
|
618
|
+
? new ApifyClient({ token, requestOrigin: getRequestOriginForClient(this.clientContext) })
|
|
617
619
|
: undefined;
|
|
618
620
|
}
|
|
619
621
|
setupResourceHandlers() {
|
|
@@ -626,49 +628,32 @@ export class ActorsMcpServer {
|
|
|
626
628
|
return await resourceService.listResources();
|
|
627
629
|
});
|
|
628
630
|
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
629
|
-
|
|
631
|
+
try {
|
|
632
|
+
return await resourceService.readResource(request.params.uri, this.resolveApifyClient(request.params));
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
throw toLegacyMcpError(error);
|
|
636
|
+
}
|
|
630
637
|
});
|
|
631
638
|
this.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
|
|
632
639
|
return await resourceService.listResourceTemplates();
|
|
633
640
|
});
|
|
634
641
|
}
|
|
635
642
|
/**
|
|
636
|
-
*
|
|
637
|
-
|
|
638
|
-
listPrompts() {
|
|
639
|
-
return { prompts };
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Builds the prompts/get result: find → not-found → validate → render.
|
|
643
|
-
* Throws {@link McpError} for an unknown prompt name or invalid arguments (v1 behavior).
|
|
644
|
-
*/
|
|
645
|
-
getPrompt(name, args) {
|
|
646
|
-
const prompt = prompts.find((p) => p.name === name);
|
|
647
|
-
if (!prompt) {
|
|
648
|
-
throw new McpError(ErrorCode.InvalidParams, `Prompt ${name} not found. Available prompts: ${prompts.map((p) => p.name).join(', ')}`);
|
|
649
|
-
}
|
|
650
|
-
if (!prompt.ajvValidate(args)) {
|
|
651
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${name}: args: ${JSON.stringify(args)} error: ${JSON.stringify(prompt.ajvValidate.errors)}`);
|
|
652
|
-
}
|
|
653
|
-
return {
|
|
654
|
-
description: prompt.description,
|
|
655
|
-
messages: [
|
|
656
|
-
{
|
|
657
|
-
role: 'user',
|
|
658
|
-
content: {
|
|
659
|
-
type: 'text',
|
|
660
|
-
text: prompt.render(args || {}),
|
|
661
|
-
},
|
|
662
|
-
},
|
|
663
|
-
],
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Sets up MCP request handlers for prompts.
|
|
643
|
+
* Sets up MCP request handlers for prompts. The prompt service throws domain errors; the
|
|
644
|
+
* boundary maps them to `McpError` so wire output is unchanged.
|
|
668
645
|
*/
|
|
669
646
|
setupPromptHandlers() {
|
|
670
|
-
|
|
671
|
-
this.server.setRequestHandler(
|
|
647
|
+
const promptService = createPromptService(prompts);
|
|
648
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, () => promptService.listPrompts());
|
|
649
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
650
|
+
try {
|
|
651
|
+
return promptService.getPrompt(request.params.name, request.params.arguments);
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
throw toLegacyMcpError(error);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
672
657
|
}
|
|
673
658
|
/**
|
|
674
659
|
* Fetches a task by ID, softFail-logging and throwing a client-facing McpError if it doesn't exist.
|
|
@@ -795,12 +780,14 @@ export class ActorsMcpServer {
|
|
|
795
780
|
// Keep actor context available to the outer catch.
|
|
796
781
|
let actorName;
|
|
797
782
|
let actorId;
|
|
783
|
+
const { clientContext } = this;
|
|
798
784
|
// Start with the raw name so early failures still have telemetry.
|
|
799
785
|
const { telemetryData, userId } = await prepareTelemetryData({
|
|
800
786
|
toolName: name,
|
|
801
787
|
mcpSessionId,
|
|
802
788
|
apifyToken,
|
|
803
789
|
apifyMcpServer: this,
|
|
790
|
+
clientContext,
|
|
804
791
|
});
|
|
805
792
|
try {
|
|
806
793
|
const prepared = await prepareToolCall({
|
|
@@ -813,6 +800,7 @@ export class ActorsMcpServer {
|
|
|
813
800
|
isTaskRequest: Boolean(request.params.task),
|
|
814
801
|
mcpSessionId,
|
|
815
802
|
telemetryData,
|
|
803
|
+
clientContext,
|
|
816
804
|
extra,
|
|
817
805
|
});
|
|
818
806
|
if ('result' in prepared) {
|
|
@@ -926,6 +914,7 @@ export class ActorsMcpServer {
|
|
|
926
914
|
actorName,
|
|
927
915
|
actorId,
|
|
928
916
|
apifyMcpServer: this,
|
|
917
|
+
clientContext,
|
|
929
918
|
}).catch((error) =>
|
|
930
919
|
// Benign task-expiry is handled in-method (see the catch block and
|
|
931
920
|
// storeTaskResultOrSkipIfExpired); anything reaching here is genuinely unexpected.
|