-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsapi-base-server.ts
More file actions
121 lines (108 loc) · 3.1 KB
/
sapi-base-server.ts
File metadata and controls
121 lines (108 loc) · 3.1 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { ScraperApiClient } from '../clients/scraper-api-client';
import {
AmazonSearchTool,
AmazonProductTool,
AmazonPricingTool,
AmazonSellersTool,
AmazonBestsellersTool,
BingSearchTool,
ChatGPTTool,
GoogleSearchTool,
GoogleAdsTool,
GoogleLensTool,
GoogleAiModeTool,
GoogleTravelHotelsTool,
PerplexityTool,
RedditPostTool,
RedditSubredditTool,
RedditUserTool,
TargetSearchTool,
TargetProductTool,
TiktokPostTool,
TiktokShopSearchTool,
TiktokShopProductTool,
TiktokShopUrlTool,
WalmartSearchTool,
WalmartProductTool,
YoutubeMetadataTool,
YoutubeChannelTool,
YoutubeSubtitlesTool,
YoutubeSearchTool,
ScrapeAsMarkdownTool,
ScreenshotTool,
} from '../tools';
import { Tool } from '../tools/tool';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { TOOLSET } from '../constants';
export class ScraperAPIBaseServer {
server: McpServer;
sapiClient: ScraperApiClient;
auth: string = '';
constructor({ auth, toolsets = [] }: { auth: string; toolsets: TOOLSET[] }) {
this.server = new McpServer({
name: 'decodo',
version: '1.2.1',
});
this.sapiClient = new ScraperApiClient();
this.auth = auth;
this.registerTools({ toolsets });
this.registerResources();
}
connect(transport: StdioServerTransport | StreamableHTTPServerTransport) {
this.server.connect(transport);
}
static allTools: Tool[] = [
new ScrapeAsMarkdownTool(),
new ScreenshotTool(),
new GoogleSearchTool(),
new GoogleAdsTool(),
new GoogleLensTool(),
new GoogleAiModeTool(),
new GoogleTravelHotelsTool(),
new AmazonSearchTool(),
new AmazonProductTool(),
new AmazonPricingTool(),
new AmazonSellersTool(),
new AmazonBestsellersTool(),
new WalmartSearchTool(),
new WalmartProductTool(),
new TargetSearchTool(),
new TargetProductTool(),
new TiktokPostTool(),
new TiktokShopSearchTool(),
new TiktokShopProductTool(),
new TiktokShopUrlTool(),
new YoutubeMetadataTool(),
new YoutubeChannelTool(),
new YoutubeSubtitlesTool(),
new YoutubeSearchTool(),
new RedditPostTool(),
new RedditSubredditTool(),
new RedditUserTool(),
new BingSearchTool(),
new ChatGPTTool(),
new PerplexityTool(),
];
registerTools({ toolsets }: { toolsets: TOOLSET[] }) {
if (toolsets.length === 0) {
this.registerAllTools();
return;
}
for (const toolset of toolsets) {
const tools = ScraperAPIBaseServer.allTools.filter(tool => tool.toolset === toolset);
for (const tool of tools) {
tool.register({ server: this.server, sapiClient: this.sapiClient, auth: this.auth });
}
}
}
registerAllTools() {
for (const tool of ScraperAPIBaseServer.allTools) {
tool.register({ server: this.server, sapiClient: this.sapiClient, auth: this.auth });
}
}
registerResources() {
// todo: expose info about all targets available
}
}