@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.
- package/dist/actorDefinition.d.ts +14 -0
- package/dist/actorDefinition.d.ts.map +1 -0
- package/{src/actorDefinition.ts → dist/actorDefinition.js} +8 -12
- package/dist/actorDefinition.js.map +1 -0
- package/dist/const.d.ts +13 -0
- package/dist/const.d.ts.map +1 -0
- package/{src/const.ts → dist/const.js} +7 -8
- package/dist/const.js.map +1 -0
- package/dist/examples/clientSse.d.ts +8 -0
- package/dist/examples/clientSse.d.ts.map +1 -0
- package/{src/examples/clientSse.ts → dist/examples/clientSse.js} +25 -45
- package/dist/examples/clientSse.js.map +1 -0
- package/dist/examples/clientStdio.d.ts +8 -0
- package/dist/examples/clientStdio.d.ts.map +1 -0
- package/{src/examples/clientStdio.ts → dist/examples/clientStdio.js} +5 -24
- package/dist/examples/clientStdio.js.map +1 -0
- package/dist/examples/clientStdioChat.d.ts +23 -0
- package/dist/examples/clientStdioChat.d.ts.map +1 -0
- package/{src/examples/clientStdioChat.ts → dist/examples/clientStdioChat.js} +37 -63
- package/dist/examples/clientStdioChat.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +2 -6
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +8 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +14 -0
- package/dist/input.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/{src/logger.ts → dist/logger.js} +1 -2
- package/dist/logger.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +104 -0
- package/dist/main.js.map +1 -0
- package/dist/server.d.ts +31 -0
- package/dist/server.d.ts.map +1 -0
- package/{src/server.ts → dist/server.js} +23 -47
- package/dist/server.js.map +1 -0
- package/{src/types.ts → dist/types.d.ts} +1 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -3
- package/src/examples/client_sse.py +0 -48
- package/src/input.ts +0 -16
- package/src/main.ts +0 -115
|
@@ -16,75 +16,51 @@
|
|
|
16
16
|
* This appears to be crawled content from AWS and IBM websites explaining what AI agents are.
|
|
17
17
|
* Let me summarize the key points:
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
19
|
import { execSync } from 'child_process';
|
|
21
20
|
import path from 'path';
|
|
22
21
|
import * as readline from 'readline';
|
|
23
22
|
import { fileURLToPath } from 'url';
|
|
24
|
-
|
|
25
23
|
import { Anthropic } from '@anthropic-ai/sdk';
|
|
26
|
-
import type { Message, ToolUseBlock, MessageParam } from '@anthropic-ai/sdk/resources/messages';
|
|
27
24
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
28
25
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
29
26
|
import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
30
27
|
import dotenv from 'dotenv';
|
|
31
|
-
|
|
32
28
|
const filename = fileURLToPath(import.meta.url);
|
|
33
29
|
const dirname = path.dirname(filename);
|
|
34
|
-
|
|
35
30
|
dotenv.config({ path: path.resolve(dirname, '../../.env') });
|
|
36
|
-
|
|
37
31
|
const REQUEST_TIMEOUT = 120_000; // 2 minutes
|
|
38
32
|
const MAX_TOKENS = 2048; // Maximum tokens for Claude response
|
|
39
|
-
|
|
40
33
|
// const CLAUDE_MODEL = 'claude-3-5-sonnet-20241022'; // the most intelligent model
|
|
41
34
|
// const CLAUDE_MODEL = 'claude-3-5-haiku-20241022'; // a fastest model
|
|
42
35
|
const CLAUDE_MODEL = 'claude-3-haiku-20240307'; // a fastest and most compact model for near-instant responsiveness
|
|
43
36
|
const DEBUG = true;
|
|
44
37
|
const DEBUG_SERVER_PATH = path.resolve(dirname, '../../dist/index.js');
|
|
45
|
-
|
|
46
38
|
const NODE_PATH = execSync('which node').toString().trim();
|
|
47
|
-
|
|
48
39
|
dotenv.config(); // Load environment variables from .env
|
|
49
|
-
|
|
50
|
-
export type Tool = {
|
|
51
|
-
name: string;
|
|
52
|
-
description: string | undefined;
|
|
53
|
-
input_schema: unknown;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
40
|
class MCPClient {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
private tools: Tool[] = [];
|
|
69
|
-
|
|
41
|
+
anthropic;
|
|
42
|
+
client = new Client({
|
|
43
|
+
name: 'example-client',
|
|
44
|
+
version: '0.1.0',
|
|
45
|
+
}, {
|
|
46
|
+
capabilities: {}, // Optional capabilities
|
|
47
|
+
});
|
|
48
|
+
tools = [];
|
|
70
49
|
constructor() {
|
|
71
50
|
this.anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
72
51
|
}
|
|
73
|
-
|
|
74
52
|
/**
|
|
75
53
|
* Start the server using node and provided server script path.
|
|
76
54
|
* Connect to the server using stdio transport and list available tools.
|
|
77
55
|
*/
|
|
78
|
-
async connectToServer(serverArgs
|
|
56
|
+
async connectToServer(serverArgs) {
|
|
79
57
|
const transport = new StdioClientTransport({
|
|
80
58
|
command: NODE_PATH,
|
|
81
59
|
args: serverArgs,
|
|
82
60
|
env: { APIFY_TOKEN: process.env.APIFY_TOKEN || '' },
|
|
83
61
|
});
|
|
84
|
-
|
|
85
62
|
await this.client.connect(transport);
|
|
86
63
|
const response = await this.client.listTools();
|
|
87
|
-
|
|
88
64
|
this.tools = response.tools.map((x) => ({
|
|
89
65
|
name: x.name,
|
|
90
66
|
description: x.description,
|
|
@@ -92,29 +68,28 @@ class MCPClient {
|
|
|
92
68
|
}));
|
|
93
69
|
console.log('Connected to server with tools:', this.tools.map((x) => x.name));
|
|
94
70
|
}
|
|
95
|
-
|
|
96
71
|
/**
|
|
97
72
|
* Process LLM response and check whether it contains any tool calls.
|
|
98
73
|
* If a tool call is found, call the tool and return the response and save the results to messages with type: user.
|
|
99
74
|
* If the tools response is too large, truncate it to the limit.
|
|
100
75
|
*/
|
|
101
|
-
async processMsg(response
|
|
76
|
+
async processMsg(response, messages) {
|
|
102
77
|
for (const content of response.content) {
|
|
103
78
|
if (content.type === 'text') {
|
|
104
79
|
messages.push({ role: 'assistant', content: content.text });
|
|
105
|
-
}
|
|
80
|
+
}
|
|
81
|
+
else if (content.type === 'tool_use') {
|
|
106
82
|
await this.handleToolCall(content, messages);
|
|
107
83
|
}
|
|
108
84
|
}
|
|
109
85
|
return messages;
|
|
110
86
|
}
|
|
111
|
-
|
|
112
87
|
/**
|
|
113
88
|
* Call the tool and return the response.
|
|
114
89
|
*/
|
|
115
|
-
|
|
90
|
+
async handleToolCall(content, messages, toolCallCount = 0) {
|
|
116
91
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
-
const params = { name: content.name, arguments: content.input
|
|
92
|
+
const params = { name: content.name, arguments: content.input };
|
|
118
93
|
console.log(`[internal] Calling tool (count: ${toolCallCount}): ${JSON.stringify(params)}`);
|
|
119
94
|
let results;
|
|
120
95
|
try {
|
|
@@ -122,47 +97,46 @@ class MCPClient {
|
|
|
122
97
|
if (results.content instanceof Array && results.content.length !== 0) {
|
|
123
98
|
const text = results.content.map((x) => x.text);
|
|
124
99
|
messages.push({ role: 'user', content: `Tool result: ${text.join('\n\n')}` });
|
|
125
|
-
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
126
102
|
messages.push({ role: 'user', content: `No results retrieved from ${params.name}` });
|
|
127
103
|
}
|
|
128
|
-
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
129
106
|
messages.push({ role: 'user', content: `Error calling tool: ${params.name}, error: ${error}` });
|
|
130
107
|
}
|
|
131
108
|
// Get next response from Claude
|
|
132
|
-
const nextResponse
|
|
109
|
+
const nextResponse = await this.anthropic.messages.create({
|
|
133
110
|
model: CLAUDE_MODEL,
|
|
134
111
|
max_tokens: MAX_TOKENS,
|
|
135
112
|
messages,
|
|
136
|
-
tools: this.tools
|
|
113
|
+
tools: this.tools, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
137
114
|
});
|
|
138
|
-
|
|
139
115
|
for (const c of nextResponse.content) {
|
|
140
116
|
if (c.type === 'text') {
|
|
141
117
|
messages.push({ role: 'assistant', content: c.text });
|
|
142
|
-
}
|
|
118
|
+
}
|
|
119
|
+
else if (c.type === 'tool_use' && toolCallCount < 3) {
|
|
143
120
|
return await this.handleToolCall(c, messages, toolCallCount + 1);
|
|
144
121
|
}
|
|
145
122
|
}
|
|
146
|
-
|
|
147
123
|
return messages;
|
|
148
124
|
}
|
|
149
|
-
|
|
150
125
|
/**
|
|
151
126
|
* Process user query by sending it to the server and returning the response.
|
|
152
127
|
* Also, process any tool calls.
|
|
153
128
|
*/
|
|
154
|
-
async processQuery(query
|
|
129
|
+
async processQuery(query, messages) {
|
|
155
130
|
messages.push({ role: 'user', content: query });
|
|
156
|
-
const response
|
|
131
|
+
const response = await this.anthropic.messages.create({
|
|
157
132
|
model: CLAUDE_MODEL,
|
|
158
133
|
max_tokens: MAX_TOKENS,
|
|
159
134
|
messages,
|
|
160
|
-
tools: this.tools
|
|
135
|
+
tools: this.tools, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
161
136
|
});
|
|
162
137
|
console.log('[internal] Received response from Claude:', JSON.stringify(response.content));
|
|
163
138
|
return await this.processMsg(response, messages);
|
|
164
139
|
}
|
|
165
|
-
|
|
166
140
|
/**
|
|
167
141
|
* Create a chat loop that reads user input from the console and sends it to the server for processing.
|
|
168
142
|
*/
|
|
@@ -172,12 +146,10 @@ class MCPClient {
|
|
|
172
146
|
output: process.stdout,
|
|
173
147
|
prompt: 'You: ',
|
|
174
148
|
});
|
|
175
|
-
|
|
176
149
|
console.log("MCP Client Started!\nType your queries or 'quit|q|exit' to exit.");
|
|
177
150
|
rl.prompt();
|
|
178
|
-
|
|
179
151
|
let lastPrintMessage = 0;
|
|
180
|
-
const messages
|
|
152
|
+
const messages = [];
|
|
181
153
|
rl.on('line', async (input) => {
|
|
182
154
|
const v = input.trim().toLowerCase();
|
|
183
155
|
if (v === 'quit' || v === 'q' || v === 'exit') {
|
|
@@ -189,39 +161,41 @@ class MCPClient {
|
|
|
189
161
|
for (let i = lastPrintMessage + 1; i < messages.length; i++) {
|
|
190
162
|
if (messages[i].role === 'assistant') {
|
|
191
163
|
console.log('CLAUDE:', messages[i].content);
|
|
192
|
-
}
|
|
164
|
+
}
|
|
165
|
+
else if (messages[i].role === 'user') {
|
|
193
166
|
console.log('USER:', messages[i].content.slice(0, 500), '...');
|
|
194
|
-
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
195
169
|
console.log('CLAUDE[thinking]:', messages[i].content);
|
|
196
170
|
}
|
|
197
171
|
}
|
|
198
172
|
lastPrintMessage += messages.length;
|
|
199
|
-
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
200
175
|
console.error('Error processing query:', error);
|
|
201
176
|
}
|
|
202
177
|
rl.prompt();
|
|
203
178
|
});
|
|
204
179
|
}
|
|
205
180
|
}
|
|
206
|
-
|
|
207
181
|
async function main() {
|
|
208
182
|
const client = new MCPClient();
|
|
209
|
-
|
|
210
183
|
if (process.argv.length < 3) {
|
|
211
184
|
if (DEBUG) {
|
|
212
185
|
process.argv.push(DEBUG_SERVER_PATH);
|
|
213
|
-
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
214
188
|
console.error('Usage: node <path_to_server_script>');
|
|
215
189
|
process.exit(1);
|
|
216
190
|
}
|
|
217
191
|
}
|
|
218
|
-
|
|
219
192
|
try {
|
|
220
193
|
await client.connectToServer(process.argv.slice(2));
|
|
221
194
|
await client.chatLoop();
|
|
222
|
-
}
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
223
197
|
console.error('Error:', error);
|
|
224
198
|
}
|
|
225
199
|
}
|
|
226
|
-
|
|
227
200
|
main().catch(console.error);
|
|
201
|
+
//# sourceMappingURL=clientStdioChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientStdioChat.js","sourceRoot":"","sources":["../../src/examples/clientStdioChat.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;AAE7D,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,YAAY;AAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,qCAAqC;AAE9D,mFAAmF;AACnF,uEAAuE;AACvE,MAAM,YAAY,GAAG,yBAAyB,CAAC,CAAC,mEAAmE;AACnH,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,iBAAiB,GAAG,IA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AC,CAAC;QACzC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This script initializes and starts the Apify MCP server using the Stdio transport.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* node <script_name> --actors=<actor1,actor2,...>
|
|
6
|
+
*
|
|
7
|
+
* Command-line arguments:
|
|
8
|
+
* --actors - A comma-separated list of actor full names to add to the server.
|
|
9
|
+
*
|
|
10
|
+
* Example:
|
|
11
|
+
* node index.js --actors=apify/google-search-scraper,apify/instagram-scraper
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -10,15 +10,11 @@
|
|
|
10
10
|
* Example:
|
|
11
11
|
* node index.js --actors=apify/google-search-scraper,apify/instagram-scraper
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
15
14
|
import minimist from 'minimist';
|
|
16
|
-
|
|
17
15
|
import { ApifyMcpServer } from './server.js';
|
|
18
|
-
|
|
19
16
|
const argv = minimist(process.argv.slice(2));
|
|
20
|
-
const argActors = argv.actors?.split(',').map((actor
|
|
21
|
-
|
|
17
|
+
const argActors = argv.actors?.split(',').map((actor) => actor.trim()) || [];
|
|
22
18
|
async function main() {
|
|
23
19
|
const server = new ApifyMcpServer();
|
|
24
20
|
await (argActors.length !== 0
|
|
@@ -27,8 +23,8 @@ async function main() {
|
|
|
27
23
|
const transport = new StdioServerTransport();
|
|
28
24
|
await server.connect(transport);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
main().catch((error) => {
|
|
32
27
|
console.error('Server error:', error); // eslint-disable-line no-console
|
|
33
28
|
process.exit(1);
|
|
34
29
|
});
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AAErF,KAAK,UAAU,IAAI;IACf,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IACpC,MAAM,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;QACzB,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC;QACtC,CAAC,CAAC,MAAM,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,iCAAiC;IACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Input } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Process input parameters, split actors string into an array
|
|
4
|
+
* @param originalInput
|
|
5
|
+
* @returns input
|
|
6
|
+
*/
|
|
7
|
+
export declare function processInput(originalInput: Partial<Input>): Promise<Input>;
|
|
8
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAQhF"}
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process input parameters, split actors string into an array
|
|
3
|
+
* @param originalInput
|
|
4
|
+
* @returns input
|
|
5
|
+
*/
|
|
6
|
+
export async function processInput(originalInput) {
|
|
7
|
+
const input = originalInput;
|
|
8
|
+
// actors can be a string or an array of strings
|
|
9
|
+
if (input.actors && typeof input.actors === 'string') {
|
|
10
|
+
input.actors = input.actors.split(',').map((format) => format.trim());
|
|
11
|
+
}
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,aAA6B;IAC5D,MAAM,KAAK,GAAG,aAAsB,CAAC;IAErC,gDAAgD;IAChD,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACnD,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAa,CAAC;IAC9F,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAI5B,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE/B,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { parse } from 'querystring';
|
|
2
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
3
|
+
import { Actor } from 'apify';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import { Routes } from './const.js';
|
|
6
|
+
import { processInput } from './input.js';
|
|
7
|
+
import { log } from './logger.js';
|
|
8
|
+
import { ApifyMcpServer } from './server.js';
|
|
9
|
+
await Actor.init();
|
|
10
|
+
const STANDBY_MODE = Actor.getEnv().metaOrigin === 'STANDBY';
|
|
11
|
+
const HOST = Actor.isAtHome() ? process.env.ACTOR_STANDBY_URL : 'http://localhost';
|
|
12
|
+
const PORT = Actor.isAtHome() ? process.env.ACTOR_STANDBY_PORT : 3001;
|
|
13
|
+
const app = express();
|
|
14
|
+
const mcpServer = new ApifyMcpServer();
|
|
15
|
+
let transport;
|
|
16
|
+
const HELP_MESSAGE = `Connect to the server with GET request to ${HOST}/sse?token=YOUR-APIFY-TOKEN`
|
|
17
|
+
+ ` and then send POST requests to ${HOST}/message?token=YOUR-APIFY-TOKEN`;
|
|
18
|
+
/**
|
|
19
|
+
* Process input parameters and update tools
|
|
20
|
+
* If URL contains query parameter actors, add tools from actors, otherwise add tools from default actors
|
|
21
|
+
* @param url
|
|
22
|
+
*/
|
|
23
|
+
async function processParamsAndUpdateTools(url) {
|
|
24
|
+
const params = parse(url.split('?')[1] || '');
|
|
25
|
+
delete params.token;
|
|
26
|
+
log.debug(`Received input parameters: ${JSON.stringify(params)}`);
|
|
27
|
+
const input = await processInput(params);
|
|
28
|
+
if (input.actors) {
|
|
29
|
+
await mcpServer.addToolsFromActors(input.actors);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
log.debug(`Server is running in STANDBY mode with the following Actors (tools): ${mcpServer.getToolNames()}.
|
|
33
|
+
To use different Actors, provide them in query parameter "actors" or include them in the Actor Task input.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
app.route(Routes.ROOT)
|
|
37
|
+
.get(async (req, res) => {
|
|
38
|
+
try {
|
|
39
|
+
log.info(`Received GET message at: ${req.url}`);
|
|
40
|
+
await processParamsAndUpdateTools(req.url);
|
|
41
|
+
res.status(200).json({ message: `Actor is using Model Context Protocol. ${HELP_MESSAGE}` }).end();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
log.error(`Error in GET ${Routes.ROOT} ${error}`);
|
|
45
|
+
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.head((_req, res) => {
|
|
49
|
+
res.status(200).end();
|
|
50
|
+
});
|
|
51
|
+
app.route(Routes.SSE)
|
|
52
|
+
.get(async (req, res) => {
|
|
53
|
+
try {
|
|
54
|
+
log.info(`Received GET message at: ${req.url}`);
|
|
55
|
+
await processParamsAndUpdateTools(req.url);
|
|
56
|
+
transport = new SSEServerTransport(Routes.MESSAGE, res);
|
|
57
|
+
await mcpServer.connect(transport);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
log.error(`Error in GET ${Routes.SSE}: ${error}`);
|
|
61
|
+
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
app.route(Routes.MESSAGE)
|
|
65
|
+
.post(async (req, res) => {
|
|
66
|
+
try {
|
|
67
|
+
log.info(`Received POST message at: ${req.url}`);
|
|
68
|
+
if (transport) {
|
|
69
|
+
await transport.handlePostMessage(req, res);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
res.status(400).json({
|
|
73
|
+
message: 'Server is not connected to the client. '
|
|
74
|
+
+ 'Connect to the server with GET request to /sse endpoint',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
log.error(`Error in POST ${Routes.MESSAGE}: ${error}`);
|
|
80
|
+
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// Catch-all for undefined routes
|
|
84
|
+
app.use((req, res) => {
|
|
85
|
+
res.status(404).json({ message: `There is nothing at route ${req.method} ${req.originalUrl}. ${HELP_MESSAGE}` }).end();
|
|
86
|
+
});
|
|
87
|
+
const input = await processInput((await Actor.getInput()) ?? {});
|
|
88
|
+
log.info(`Loaded input: ${JSON.stringify(input)} `);
|
|
89
|
+
if (STANDBY_MODE) {
|
|
90
|
+
log.info('Actor is running in the STANDBY mode.');
|
|
91
|
+
await mcpServer.addToolsFromDefaultActors();
|
|
92
|
+
app.listen(PORT, () => {
|
|
93
|
+
log.info(`The Actor web server is listening for user requests at ${HOST}`);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
log.info('Actor is not designed to run in the NORMAL model (use this mode only for debugging purposes)');
|
|
98
|
+
if (input && !input.debugActor && !input.debugActorInput) {
|
|
99
|
+
await Actor.fail('If you need to debug a specific actor, please provide the debugActor and debugActorInput fields in the input');
|
|
100
|
+
}
|
|
101
|
+
await mcpServer.callActorGetDataset(input.debugActor, input.debugActorInput);
|
|
102
|
+
await Actor.exit();
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,KAAK,CAAC,IA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AEH,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,QAAQ,EAAkB,CAAC,IAAK,EAAY,CAAC,CAAC;AAC5F,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAEpD,IAAI,YAAY,EAAE,CAAC;IACf,GAAG,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IAClD,MAAM,SAAS,CAAC,yBAAyB,EAAE,CAAC;IAC5C,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QAClB,GAAG,CAAC,IAAI,CAAC,0DAA0D,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACP,CAAC;KAAM,CAAC;IACJ,GAAG,CAAC,IAAI,CAAC,8FAA8F,CAAC,CAAC;IAEzG,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;QACvD,MAAM,KAAK,CAAC,IAAI,CAAC,8GAA8G,CAAC,CAAC;IACrI,CAAC;IACD,MAAM,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC,UAAW,EAAE,KAAK,CAAC,eAAgB,CAAC,CAAC;IAC/E,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
3
|
+
import type { Tool } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Create Apify MCP server
|
|
6
|
+
*/
|
|
7
|
+
export declare class ApifyMcpServer {
|
|
8
|
+
private server;
|
|
9
|
+
private tools;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Calls an Apify actor and retrieves the dataset items.
|
|
13
|
+
*
|
|
14
|
+
* It requires the `APIFY_TOKEN` environment variable to be set.
|
|
15
|
+
* If the `APIFY_IS_AT_HOME` the dataset items are pushed to the Apify dataset.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} actorName - The name of the actor to call.
|
|
18
|
+
* @param {unknown} input - The input to pass to the actor.
|
|
19
|
+
* @returns {Promise<object[]>} - A promise that resolves to an array of dataset items.
|
|
20
|
+
* @throws {Error} - Throws an error if the `APIFY_TOKEN` is not set
|
|
21
|
+
*/
|
|
22
|
+
callActorGetDataset(actorName: string, input: unknown): Promise<object[]>;
|
|
23
|
+
addToolsFromActors(actors: string[]): Promise<void>;
|
|
24
|
+
addToolsFromDefaultActors(): Promise<void>;
|
|
25
|
+
updateTools(tools: Tool[]): void;
|
|
26
|
+
getToolNames(): string[];
|
|
27
|
+
private setupErrorHandling;
|
|
28
|
+
private setupToolHandlers;
|
|
29
|
+
connect(transport: Transport): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAc/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAoB;;IAmBjC;;;;;;;;;;OAUG;IACU,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAwBzE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE;IAKnC,yBAAyB;IAI/B,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI;IAOhC,YAAY,IAAI,MAAM,EAAE;IAI/B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;IAuCnB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
|