@apify/actors-mcp-server 0.1.1-beta.1 → 0.1.1-beta.3
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/dist/tsconfig.tsbuildinfo +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 +2 -3
- package/src/examples/client_sse.py +0 -48
- package/src/input.ts +0 -16
- package/src/main.ts +0 -115
package/src/input.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Input } from './types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Process input parameters, split actors string into an array
|
|
5
|
-
* @param originalInput
|
|
6
|
-
* @returns input
|
|
7
|
-
*/
|
|
8
|
-
export async function processInput(originalInput: Partial<Input>): Promise<Input> {
|
|
9
|
-
const input = originalInput as Input;
|
|
10
|
-
|
|
11
|
-
// actors can be a string or an array of strings
|
|
12
|
-
if (input.actors && typeof input.actors === 'string') {
|
|
13
|
-
input.actors = input.actors.split(',').map((format: string) => format.trim()) as string[];
|
|
14
|
-
}
|
|
15
|
-
return input;
|
|
16
|
-
}
|
package/src/main.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { ParsedUrlQuery } from 'querystring';
|
|
2
|
-
import { parse } from 'querystring';
|
|
3
|
-
|
|
4
|
-
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
5
|
-
import { Actor } from 'apify';
|
|
6
|
-
import type { Request, Response } from 'express';
|
|
7
|
-
import express from 'express';
|
|
8
|
-
|
|
9
|
-
import { Routes } from './const.js';
|
|
10
|
-
import { processInput } from './input.js';
|
|
11
|
-
import { log } from './logger.js';
|
|
12
|
-
import { ApifyMcpServer } from './server.js';
|
|
13
|
-
import type { Input } from './types.js';
|
|
14
|
-
|
|
15
|
-
await Actor.init();
|
|
16
|
-
|
|
17
|
-
const STANDBY_MODE = Actor.getEnv().metaOrigin === 'STANDBY';
|
|
18
|
-
const HOST = Actor.isAtHome() ? process.env.ACTOR_STANDBY_URL : 'http://localhost';
|
|
19
|
-
const PORT = Actor.isAtHome() ? process.env.ACTOR_STANDBY_PORT : 3001;
|
|
20
|
-
|
|
21
|
-
const app = express();
|
|
22
|
-
|
|
23
|
-
const mcpServer = new ApifyMcpServer();
|
|
24
|
-
let transport: SSEServerTransport;
|
|
25
|
-
|
|
26
|
-
const HELP_MESSAGE = `Connect to the server with GET request to ${HOST}/sse?token=YOUR-APIFY-TOKEN`
|
|
27
|
-
+ ` and then send POST requests to ${HOST}/message?token=YOUR-APIFY-TOKEN`;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Process input parameters and update tools
|
|
31
|
-
* If URL contains query parameter actors, add tools from actors, otherwise add tools from default actors
|
|
32
|
-
* @param url
|
|
33
|
-
*/
|
|
34
|
-
async function processParamsAndUpdateTools(url: string) {
|
|
35
|
-
const params = parse(url.split('?')[1] || '') as ParsedUrlQuery;
|
|
36
|
-
delete params.token;
|
|
37
|
-
log.debug(`Received input parameters: ${JSON.stringify(params)}`);
|
|
38
|
-
const input = await processInput(params as Input);
|
|
39
|
-
if (input.actors) {
|
|
40
|
-
await mcpServer.addToolsFromActors(input.actors as string[]);
|
|
41
|
-
} else {
|
|
42
|
-
log.debug(`Server is running in STANDBY mode with the following Actors (tools): ${mcpServer.getToolNames()}.
|
|
43
|
-
To use different Actors, provide them in query parameter "actors" or include them in the Actor Task input.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
app.route(Routes.ROOT)
|
|
48
|
-
.get(async (req: Request, res: Response) => {
|
|
49
|
-
try {
|
|
50
|
-
log.info(`Received GET message at: ${req.url}`);
|
|
51
|
-
await processParamsAndUpdateTools(req.url);
|
|
52
|
-
res.status(200).json({ message: `Actor is using Model Context Protocol. ${HELP_MESSAGE}` }).end();
|
|
53
|
-
} catch (error) {
|
|
54
|
-
log.error(`Error in GET ${Routes.ROOT} ${error}`);
|
|
55
|
-
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
.head((_req: Request, res: Response) => {
|
|
59
|
-
res.status(200).end();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
app.route(Routes.SSE)
|
|
63
|
-
.get(async (req: Request, res: Response) => {
|
|
64
|
-
try {
|
|
65
|
-
log.info(`Received GET message at: ${req.url}`);
|
|
66
|
-
await processParamsAndUpdateTools(req.url);
|
|
67
|
-
transport = new SSEServerTransport(Routes.MESSAGE, res);
|
|
68
|
-
await mcpServer.connect(transport);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
log.error(`Error in GET ${Routes.SSE}: ${error}`);
|
|
71
|
-
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
app.route(Routes.MESSAGE)
|
|
76
|
-
.post(async (req: Request, res: Response) => {
|
|
77
|
-
try {
|
|
78
|
-
log.info(`Received POST message at: ${req.url}`);
|
|
79
|
-
if (transport) {
|
|
80
|
-
await transport.handlePostMessage(req, res);
|
|
81
|
-
} else {
|
|
82
|
-
res.status(400).json({
|
|
83
|
-
message: 'Server is not connected to the client. '
|
|
84
|
-
+ 'Connect to the server with GET request to /sse endpoint',
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
} catch (error) {
|
|
88
|
-
log.error(`Error in POST ${Routes.MESSAGE}: ${error}`);
|
|
89
|
-
res.status(500).json({ message: 'Internal Server Error' }).end();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Catch-all for undefined routes
|
|
94
|
-
app.use((req: Request, res: Response) => {
|
|
95
|
-
res.status(404).json({ message: `There is nothing at route ${req.method} ${req.originalUrl}. ${HELP_MESSAGE}` }).end();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const input = await processInput((await Actor.getInput<Partial<Input>>()) ?? ({} as Input));
|
|
99
|
-
log.info(`Loaded input: ${JSON.stringify(input)} `);
|
|
100
|
-
|
|
101
|
-
if (STANDBY_MODE) {
|
|
102
|
-
log.info('Actor is running in the STANDBY mode.');
|
|
103
|
-
await mcpServer.addToolsFromDefaultActors();
|
|
104
|
-
app.listen(PORT, () => {
|
|
105
|
-
log.info(`The Actor web server is listening for user requests at ${HOST}`);
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
log.info('Actor is not designed to run in the NORMAL model (use this mode only for debugging purposes)');
|
|
109
|
-
|
|
110
|
-
if (input && !input.debugActor && !input.debugActorInput) {
|
|
111
|
-
await Actor.fail('If you need to debug a specific actor, please provide the debugActor and debugActorInput fields in the input');
|
|
112
|
-
}
|
|
113
|
-
await mcpServer.callActorGetDataset(input.debugActor!, input.debugActorInput!);
|
|
114
|
-
await Actor.exit();
|
|
115
|
-
}
|