-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathindex.ts
More file actions
67 lines (56 loc) · 1.82 KB
/
index.ts
File metadata and controls
67 lines (56 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { program } from "commander";
import { appConfig } from "@repo/config/app.config";
import type { Resource } from "@/resources/resource";
import { createServerWithTools } from "@/server";
import * as common from "@/tools/common";
import * as custom from "@/tools/custom";
import * as snapshot from "@/tools/snapshot";
import type { Tool } from "@/tools/tool";
import packageJSON from "../package.json";
function setupExitWatchdog(server: Server) {
process.stdin.on("close", async () => {
setTimeout(() => process.exit(0), 15000);
await server.close();
process.exit(0);
});
}
const commonTools: Tool[] = [common.pressKey, common.wait];
const customTools: Tool[] = [custom.getConsoleLogs, custom.getNetworkLogs, custom.screenshot];
const snapshotTools: Tool[] = [
common.navigate(true),
common.newPage(true),
common.goBack(true),
common.goForward(true),
snapshot.snapshot,
snapshot.click,
snapshot.hover,
snapshot.type,
snapshot.selectOption,
...commonTools,
...customTools,
];
const resources: Resource[] = [];
async function createServer(): Promise<Server> {
return createServerWithTools({
name: appConfig.name,
version: packageJSON.version,
tools: snapshotTools,
resources,
});
}
/**
* Note: Tools must be defined *before* calling `createServer` because only declarations are hoisted, not the initializations
*/
program
.version("Version " + packageJSON.version)
.name(packageJSON.name)
.action(async () => {
const server = await createServer();
setupExitWatchdog(server);
const transport = new StdioServerTransport();
await server.connect(transport);
});
program.parse(process.argv);