@apify/actors-mcp-server 0.1.1-beta.1 → 0.1.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.
Files changed (48) hide show
  1. package/dist/actorDefinition.d.ts +14 -0
  2. package/dist/actorDefinition.d.ts.map +1 -0
  3. package/{src/actorDefinition.ts → dist/actorDefinition.js} +8 -12
  4. package/dist/actorDefinition.js.map +1 -0
  5. package/dist/const.d.ts +13 -0
  6. package/dist/const.d.ts.map +1 -0
  7. package/{src/const.ts → dist/const.js} +7 -8
  8. package/dist/const.js.map +1 -0
  9. package/dist/examples/clientSse.d.ts +8 -0
  10. package/dist/examples/clientSse.d.ts.map +1 -0
  11. package/{src/examples/clientSse.ts → dist/examples/clientSse.js} +25 -45
  12. package/dist/examples/clientSse.js.map +1 -0
  13. package/dist/examples/clientStdio.d.ts +8 -0
  14. package/dist/examples/clientStdio.d.ts.map +1 -0
  15. package/{src/examples/clientStdio.ts → dist/examples/clientStdio.js} +5 -24
  16. package/dist/examples/clientStdio.js.map +1 -0
  17. package/dist/examples/clientStdioChat.d.ts +23 -0
  18. package/dist/examples/clientStdioChat.d.ts.map +1 -0
  19. package/{src/examples/clientStdioChat.ts → dist/examples/clientStdioChat.js} +37 -63
  20. package/dist/examples/clientStdioChat.js.map +1 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/{src/index.ts → dist/index.js} +2 -6
  24. package/dist/index.js.map +1 -0
  25. package/dist/input.d.ts +8 -0
  26. package/dist/input.d.ts.map +1 -0
  27. package/dist/input.js +14 -0
  28. package/dist/input.js.map +1 -0
  29. package/dist/logger.d.ts +3 -0
  30. package/dist/logger.d.ts.map +1 -0
  31. package/{src/logger.ts → dist/logger.js} +1 -2
  32. package/dist/logger.js.map +1 -0
  33. package/dist/main.d.ts +2 -0
  34. package/dist/main.d.ts.map +1 -0
  35. package/dist/main.js +104 -0
  36. package/dist/main.js.map +1 -0
  37. package/dist/server.d.ts +31 -0
  38. package/dist/server.d.ts.map +1 -0
  39. package/{src/server.ts → dist/server.js} +23 -47
  40. package/dist/server.js.map +1 -0
  41. package/{src/types.ts → dist/types.d.ts} +1 -3
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +2 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +3 -3
  46. package/src/examples/client_sse.py +0 -48
  47. package/src/input.ts +0 -16
  48. package/src/main.ts +0 -115
@@ -0,0 +1,14 @@
1
+ import type { Tool } from './types';
2
+ /**
3
+ * Fetches actor input schemas by actor full names and creates MCP tools.
4
+ *
5
+ * This function retrieves the input schemas for the specified actors and compiles them into MCP tools.
6
+ * It uses the AJV library to validate the input schemas.
7
+ *
8
+ * Tool name can't contain /, so it is replaced with _
9
+ *
10
+ * @param {string[]} actors - An array of actor full names.
11
+ * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
12
+ */
13
+ export declare function getActorsAsTools(actors: string[]): Promise<Tool[]>;
14
+ //# sourceMappingURL=actorDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actorDefinition.d.ts","sourceRoot":"","sources":["../src/actorDefinition.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,IAAI,EAAE,MAAM,SAAS,CAAC;AAkD7D;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAqBxE"}
@@ -1,9 +1,6 @@
1
1
  import { Ajv } from 'ajv';
2
2
  import { ApifyClient } from 'apify-client';
3
-
4
3
  import { log } from './logger.js';
5
- import type { ActorDefinitionWithDesc, Tool } from './types';
6
-
7
4
  /**
8
5
  * Get actor input schema by actor name.
9
6
  * First, fetch the actor details to get the default build tag and buildId.
@@ -11,14 +8,13 @@ import type { ActorDefinitionWithDesc, Tool } from './types';
11
8
  * @param {string} actorFullName - The full name of the actor.
12
9
  * @returns {Promise<ActorDefinitionWithDesc | null>} - The actor definition with description or null if not found.
13
10
  */
14
- async function fetchActorDefinition(actorFullName: string): Promise<ActorDefinitionWithDesc | null> {
11
+ async function fetchActorDefinition(actorFullName) {
15
12
  if (!process.env.APIFY_TOKEN) {
16
13
  log.error('APIFY_TOKEN is required but not set. Please set it as an environment variable');
17
14
  return null;
18
15
  }
19
16
  const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
20
17
  const actorClient = client.actor(actorFullName);
21
-
22
18
  try {
23
19
  // Fetch actor details
24
20
  const actor = await actorClient.get();
@@ -26,13 +22,11 @@ async function fetchActorDefinition(actorFullName: string): Promise<ActorDefinit
26
22
  log.error(`Failed to fetch input schema for actor: ${actorFullName}. Actor not found.`);
27
23
  return null;
28
24
  }
29
-
30
25
  // fnesveda: The default build is not necessarily tagged, you can specify any build number as default build.
31
26
  // There will be a new API endpoint to fetch a default build.
32
27
  // For now, we'll use the tagged build, it will work for 90% of Actors. Later, we can update this.
33
28
  const tag = actor.defaultRunOptions?.build || '';
34
29
  const buildId = actor.taggedBuilds?.[tag]?.buildId || '';
35
-
36
30
  if (!buildId) {
37
31
  log.error(`Failed to fetch input schema for actor: ${actorFullName}. Build ID not found.`);
38
32
  return null;
@@ -40,18 +34,18 @@ async function fetchActorDefinition(actorFullName: string): Promise<ActorDefinit
40
34
  // Fetch build details and return the input schema
41
35
  const buildDetails = await client.build(buildId).get();
42
36
  if (buildDetails?.actorDefinition) {
43
- const actorDefinitions = buildDetails?.actorDefinition as ActorDefinitionWithDesc;
37
+ const actorDefinitions = buildDetails?.actorDefinition;
44
38
  actorDefinitions.description = actor.description || '';
45
39
  actorDefinitions.name = actorFullName;
46
40
  return actorDefinitions;
47
41
  }
48
42
  return null;
49
- } catch (error) {
43
+ }
44
+ catch (error) {
50
45
  log.error(`Failed to fetch input schema for actor: ${actorFullName} with error ${error}.`);
51
46
  return null;
52
47
  }
53
48
  }
54
-
55
49
  /**
56
50
  * Fetches actor input schemas by actor full names and creates MCP tools.
57
51
  *
@@ -63,7 +57,7 @@ async function fetchActorDefinition(actorFullName: string): Promise<ActorDefinit
63
57
  * @param {string[]} actors - An array of actor full names.
64
58
  * @returns {Promise<Tool[]>} - A promise that resolves to an array of MCP tools.
65
59
  */
66
- export async function getActorsAsTools(actors: string[]): Promise<Tool[]> {
60
+ export async function getActorsAsTools(actors) {
67
61
  // Fetch input schemas in parallel
68
62
  const ajv = new Ajv({ coerceTypes: 'array', strict: false });
69
63
  const results = await Promise.all(actors.map(fetchActorDefinition));
@@ -78,10 +72,12 @@ export async function getActorsAsTools(actors: string[]): Promise<Tool[]> {
78
72
  inputSchema: result.input || {},
79
73
  ajvValidate: ajv.compile(result.input || {}),
80
74
  });
81
- } catch (validationError) {
75
+ }
76
+ catch (validationError) {
82
77
  log.error(`Failed to compile AJV schema for actor: ${result.name}. Error: ${validationError}`);
83
78
  }
84
79
  }
85
80
  }
86
81
  return tools;
87
82
  }
83
+ //# sourceMappingURL=actorDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actorDefinition.js","sourceRoot":"","sources":["../src/actorDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC;;;;;;GAMG;AACH,KAAK,UAAU,oBAAoB,CAAC,aAAqB;IACrD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,+EAA+E,CAAC,CAAC;QAC3F,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEhD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AG,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC3B,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC;oBACP,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;oBACnC,SAAS,EAAE,MAAM,CAAC,IAAI;oBACtB,WAAW,EAAE,MAAM,CAAC,WAAW;oBAC/B,WAAW,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;oBAC/B,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;iBAC/C,CAAC,CAAC;YACP,CAAC;YAAC,OAAO,eAAe,EAAE,CAAC;gBACvB,GAAG,CAAC,KAAK,CAAC,2CAA2C,MAAM,CAAC,IAAI,YAAY,eAAe,EAAE,CAAC,CAAC;YACnG,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare const SERVER_NAME = "apify-mcp-server";
2
+ export declare const SERVER_VERSION = "0.1.0";
3
+ export declare const defaults: {
4
+ actors: string[];
5
+ };
6
+ export declare const ACTOR_OUTPUT_MAX_CHARS_PER_ITEM = 2000;
7
+ export declare const ACTOR_OUTPUT_TRUNCATED_MESSAGE: string;
8
+ export declare enum Routes {
9
+ ROOT = "/",
10
+ SSE = "/sse",
11
+ MESSAGE = "/message"
12
+ }
13
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAC9C,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,eAAO,MAAM,QAAQ;;CAMpB,CAAC;AAEF,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AACrD,eAAO,MAAM,8BAA8B,QACS,CAAC;AAErD,oBAAY,MAAM;IACd,IAAI,MAAM;IACV,GAAG,SAAS;IACZ,OAAO,aAAa;CACvB"}
@@ -1,6 +1,5 @@
1
1
  export const SERVER_NAME = 'apify-mcp-server';
2
2
  export const SERVER_VERSION = '0.1.0';
3
-
4
3
  export const defaults = {
5
4
  actors: [
6
5
  'apify/instagram-scraper',
@@ -8,13 +7,13 @@ export const defaults = {
8
7
  'lukaskrivka/google-maps-with-contact-details',
9
8
  ],
10
9
  };
11
-
12
10
  export const ACTOR_OUTPUT_MAX_CHARS_PER_ITEM = 2_000;
13
11
  export const ACTOR_OUTPUT_TRUNCATED_MESSAGE = `Output was truncated because it will not fit into context.`
14
12
  + ` There is no reason to call this tool again!`;
15
-
16
- export enum Routes {
17
- ROOT = '/',
18
- SSE = '/sse',
19
- MESSAGE = '/message',
20
- }
13
+ export var Routes;
14
+ (function (Routes) {
15
+ Routes["ROOT"] = "/";
16
+ Routes["SSE"] = "/sse";
17
+ Routes["MESSAGE"] = "/message";
18
+ })(Routes || (Routes = {}));
19
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,MAAM,EAAE;QACJ,yBAAyB;QACzB,uBAAuB;QACvB,8CAA8C;KACjD;CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAG,KAAK,CAAC;AACrD,MAAM,CAAC,MAAM,8BAA8B,GAAG,4DAA4D;MACpG,8CAA8C,CAAC;AAErD,MAAM,CAAN,IAAY,MAIX;AAJD,WAAY,MAAM;IACd,oBAAU,CAAA;IACV,sBAAY,CAAA;IACZ,8BAAoB,CAAA;AACxB,CAAC,EAJW,MAAM,KAAN,MAAM,QAIjB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Connect to the MCP server using SSE transport and call a tool.
3
+ * The Actors MCP Server will load default Actors.
4
+ *
5
+ * !!! This example needs to be fixed as it does not work !!!
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=clientSse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientSse.d.ts","sourceRoot":"","sources":["../../src/examples/clientSse.ts"],"names":[],"mappings":"AACA;;;;;GAKG"}
@@ -5,96 +5,76 @@
5
5
  *
6
6
  * !!! This example needs to be fixed as it does not work !!!
7
7
  */
8
-
9
8
  import path from 'path';
10
9
  import { fileURLToPath } from 'url';
11
-
12
10
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
13
11
  import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
14
12
  import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
15
13
  import dotenv from 'dotenv';
16
14
  import { EventSource } from 'eventsource';
17
-
18
15
  // Resolve dirname equivalent in ES module
19
16
  const filename = fileURLToPath(import.meta.url);
20
17
  const dirname = path.dirname(filename);
21
-
22
18
  dotenv.config({ path: path.resolve(dirname, '../../.env') });
23
-
24
19
  const SERVER_URL = 'https://actors-mcp-server/sse';
25
20
  // We need to change forward slash / to underscore _ in the tool name as Anthropic does not allow forward slashes in the tool name
26
21
  const SELECTED_TOOL = 'apify_rag-web-browser';
27
-
28
22
  if (!process.env.APIFY_TOKEN) {
29
23
  console.error('APIFY_TOKEN is required but not set in the environment variables.');
30
24
  process.exit(1);
31
25
  }
32
-
33
26
  if (typeof globalThis.EventSource === 'undefined') {
34
- globalThis.EventSource = EventSource as unknown as typeof globalThis.EventSource;
27
+ globalThis.EventSource = EventSource;
35
28
  }
36
-
37
- async function main(): Promise<void> {
38
- const transport = new SSEClientTransport(
39
- new URL(SERVER_URL),
40
- {
41
- requestInit: {
42
- headers: {
43
- authorization: `Bearer ${process.env.APIFY_TOKEN}`,
44
- },
29
+ async function main() {
30
+ const transport = new SSEClientTransport(new URL(SERVER_URL), {
31
+ requestInit: {
32
+ headers: {
33
+ authorization: `Bearer ${process.env.APIFY_TOKEN}`,
45
34
  },
46
- eventSourceInit: {
47
- // The EventSource package augments EventSourceInit with a "fetch" parameter.
48
- // You can use this to set additional headers on the outgoing request.
49
- // Based on this example: https://github.com/modelcontextprotocol/typescript-sdk/issues/118
50
- async fetch(input: Request | URL | string, init?: RequestInit) {
51
- const headers = new Headers(init?.headers || {});
52
- headers.set('authorization', `Bearer ${process.env.APIFY_TOKEN}`);
53
- return fetch(input, { ...init, headers });
54
- },
55
- // We have to cast to "any" to use it, since it's non-standard
56
- } as any, // eslint-disable-line @typescript-eslint/no-explicit-any
57
35
  },
58
- );
59
- const client = new Client(
60
- { name: 'example-client', version: '1.0.0' },
61
- { capabilities: {} },
62
- );
63
-
36
+ eventSourceInit: {
37
+ // The EventSource package augments EventSourceInit with a "fetch" parameter.
38
+ // You can use this to set additional headers on the outgoing request.
39
+ // Based on this example: https://github.com/modelcontextprotocol/typescript-sdk/issues/118
40
+ async fetch(input, init) {
41
+ const headers = new Headers(init?.headers || {});
42
+ headers.set('authorization', `Bearer ${process.env.APIFY_TOKEN}`);
43
+ return fetch(input, { ...init, headers });
44
+ },
45
+ // We have to cast to "any" to use it, since it's non-standard
46
+ }, // eslint-disable-line @typescript-eslint/no-explicit-any
47
+ });
48
+ const client = new Client({ name: 'example-client', version: '1.0.0' }, { capabilities: {} });
64
49
  try {
65
50
  // Connect to the MCP server
66
51
  await client.connect(transport);
67
-
68
52
  // List available tools
69
53
  const tools = await client.listTools();
70
54
  console.log('Available tools:', tools);
71
-
72
55
  if (tools.tools.length === 0) {
73
56
  console.log('No tools available');
74
57
  return;
75
58
  }
76
-
77
59
  const selectedTool = tools.tools.find((tool) => tool.name === SELECTED_TOOL);
78
60
  if (!selectedTool) {
79
61
  console.error(`The specified tool: ${selectedTool} is not available. Exiting.`);
80
62
  return;
81
63
  }
82
-
83
64
  // Call a tool
84
65
  console.log('Calling actor ...');
85
- const result = await client.callTool(
86
- { name: SELECTED_TOOL, arguments: { query: 'web browser for Anthropic' } },
87
- CallToolResultSchema,
88
- );
66
+ const result = await client.callTool({ name: SELECTED_TOOL, arguments: { query: 'web browser for Anthropic' } }, CallToolResultSchema);
89
67
  console.log('Tool result:', JSON.stringify(result, null, 2));
90
- } catch (error: unknown) {
68
+ }
69
+ catch (error) {
91
70
  if (error instanceof Error) {
92
71
  console.error('Error:', error.message);
93
72
  console.error(error.stack);
94
- } else {
73
+ }
74
+ else {
95
75
  console.error('An unknown error occurred:', error);
96
76
  }
97
77
  }
98
78
  }
99
-
100
79
  await main();
80
+ //# sourceMappingURL=clientSse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientSse.js","sourceRoot":"","sources":["../../src/examples/clientSse.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,0CAA0C;AAC1C,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,C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AC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;IACL,CAAC;AACL,CAAC;AAED,MAAM,IAAI,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Connect to the MCP server using stdio transport and call a tool.
3
+ * This script uses a selected tool without LLM involvement.
4
+ * You need to provide the path to the MCP server and `APIFY_TOKEN` in the `.env` file.
5
+ * You can choose actors to run in the server, for example: `apify/rag-web-browser`.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=clientStdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientStdio.d.ts","sourceRoot":"","sources":["../../src/examples/clientStdio.ts"],"names":[],"mappings":"AACA;;;;;GAKG"}
@@ -5,81 +5,62 @@
5
5
  * You need to provide the path to the MCP server and `APIFY_TOKEN` in the `.env` file.
6
6
  * You can choose actors to run in the server, for example: `apify/rag-web-browser`.
7
7
  */
8
-
9
8
  import { execSync } from 'child_process';
10
9
  import path from 'path';
11
10
  import { fileURLToPath } from 'url';
12
-
13
11
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
14
12
  import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
15
13
  import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
16
14
  import dotenv from 'dotenv';
17
-
18
15
  // Resolve dirname equivalent in ES module
19
16
  const filename = fileURLToPath(import.meta.url);
20
17
  const dirname = path.dirname(filename);
21
-
22
18
  dotenv.config({ path: path.resolve(dirname, '../../.env') });
23
19
  const SERVER_PATH = path.resolve(dirname, '../../dist/index.js');
24
20
  const NODE_PATH = execSync(process.platform === 'win32' ? 'where node' : 'which node').toString().trim();
25
-
26
21
  const TOOLS = 'apify/rag-web-browser,lukaskrivka/google-maps-with-contact-details';
27
22
  const SELECTED_TOOL = 'apify_rag-web-browser'; // We need to change / to _ in the tool name
28
-
29
23
  if (!process.env.APIFY_TOKEN) {
30
24
  console.error('APIFY_TOKEN is required but not set in the environment variables.');
31
25
  process.exit(1);
32
26
  }
33
-
34
27
  // Create server parameters for stdio connection
35
28
  const transport = new StdioClientTransport({
36
29
  command: NODE_PATH,
37
30
  args: [SERVER_PATH, '--actors', TOOLS],
38
31
  env: { APIFY_TOKEN: process.env.APIFY_TOKEN || '' },
39
32
  });
40
-
41
33
  // Create a new client instance
42
- const client = new Client(
43
- { name: 'example-client', version: '0.1.0' },
44
- { capabilities: {} },
45
- );
46
-
34
+ const client = new Client({ name: 'example-client', version: '0.1.0' }, { capabilities: {} });
47
35
  // Main function to run the example client
48
36
  async function run() {
49
37
  try {
50
38
  // Connect to the MCP server
51
39
  await client.connect(transport);
52
-
53
40
  // List available tools
54
41
  const tools = await client.listTools();
55
42
  console.log('Available tools:', tools);
56
-
57
43
  if (tools.tools.length === 0) {
58
44
  console.log('No tools available');
59
45
  return;
60
46
  }
61
-
62
47
  // Example: Call the first available tool
63
48
  const selectedTool = tools.tools.find((tool) => tool.name === SELECTED_TOOL);
64
-
65
49
  if (!selectedTool) {
66
50
  console.error(`The specified tool: ${selectedTool} is not available. Exiting.`);
67
51
  return;
68
52
  }
69
-
70
53
  // Call a tool
71
54
  console.log('Calling actor ...');
72
- const result = await client.callTool(
73
- { name: SELECTED_TOOL, arguments: { query: 'web browser for Anthropic' } },
74
- CallToolResultSchema,
75
- );
55
+ const result = await client.callTool({ name: SELECTED_TOOL, arguments: { query: 'web browser for Anthropic' } }, CallToolResultSchema);
76
56
  console.log('Tool result:', JSON.stringify(result));
77
- } catch (error) {
57
+ }
58
+ catch (error) {
78
59
  console.error('Error:', error);
79
60
  }
80
61
  }
81
-
82
62
  run().catch((error) => {
83
63
  console.error('Unhandled error:', error);
84
64
  process.exit(1);
85
65
  });
66
+ //# sourceMappingURL=clientStdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientStdio.js","sourceRoot":"","sources":["../../src/examples/clientSt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oBAAoB,CACvB,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;AACL,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Create a simple chat client that connects to the Model Context Protocol server using the stdio transport.
3
+ * Based on the user input, the client sends a query to the MCP server, retrieves results and processes them.
4
+ *
5
+ * You can expect the following output:
6
+ *
7
+ * MCP Client Started!
8
+ * Type your queries or 'quit|q|exit' to exit.
9
+ * You: Find to articles about AI agent and return URLs
10
+ * [internal] Received response from Claude: [{"type":"text","text":"I'll search for information about AI agents
11
+ * and provide you with a summary."},{"type":"tool_use","id":"tool_01He9TkzQfh2979bbeuxWVqM","name":"search",
12
+ * "input":{"query":"what are AI agents definition capabilities applications","maxResults":2}}]
13
+ * [internal] Calling tool: {"name":"search","arguments":{"query":"what are AI agents definition ...
14
+ * I can help analyze the provided content about AI agents.
15
+ * This appears to be crawled content from AWS and IBM websites explaining what AI agents are.
16
+ * Let me summarize the key points:
17
+ */
18
+ export type Tool = {
19
+ name: string;
20
+ description: string | undefined;
21
+ input_schema: unknown;
22
+ };
23
+ //# sourceMappingURL=clientStdioChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientStdioChat.d.ts","sourceRoot":"","sources":["../../src/examples/clientStdioChat.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;GAgBG;AAgCH,MAAM,MAAM,IAAI,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;CACzB,CAAA"}