@@ -8,8 +8,6 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
8
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' ;
9
9
import {
10
10
CallToolRequestSchema ,
11
- GetPromptRequestSchema ,
12
- ListPromptsRequestSchema ,
13
11
ListToolsRequestSchema ,
14
12
} from '@modelcontextprotocol/sdk/types.js' ;
15
13
import dotenv from 'dotenv' ;
@@ -32,28 +30,13 @@ const WebBrowserArgsSchema = z.object({
32
30
. describe (
33
31
'The maximum number of top organic Google Search results whose web pages will be extracted' ,
34
32
) ,
33
+ scrapingTool : z . enum ( [ 'browser-playwright' , 'raw-http' ] )
34
+ . describe ( 'Select a scraping tool for extracting the target web pages. '
35
+ + 'The Browser tool is more powerful and can handle JavaScript heavy websites, while the '
36
+ + 'Plain HTML tool can not handle JavaScript but is about two times faster.' )
37
+ . default ( 'raw-http' ) ,
35
38
} ) ;
36
39
37
- const PROMPTS = [
38
- {
39
- name : TOOL_SEARCH ,
40
- description : 'Search phrase or a URL at Google and return crawled web pages as text or Markdown' ,
41
- arguments : [
42
- {
43
- name : 'query' ,
44
- description : 'Google Search keywords or a URL of a specific web page' ,
45
- required : true ,
46
- } ,
47
- {
48
- name : 'maxResults' ,
49
- description : 'The maximum number of top organic Google Search results whose web pages'
50
- + ' will be extracted (default: 1)' ,
51
- required : false ,
52
- } ,
53
- ] ,
54
- } ,
55
- ] ;
56
-
57
40
/**
58
41
* Create an MCP server with a tool to call RAG Web Browser Actor
59
42
*/
@@ -74,11 +57,10 @@ export class RagWebBrowserServer {
74
57
} ,
75
58
) ;
76
59
this . setupErrorHandling ( ) ;
77
- this . setupPromptHandlers ( ) ;
78
60
this . setupToolHandlers ( ) ;
79
61
}
80
62
81
- private async callRagWebBrowser ( query : string , maxResults : number ) : Promise < string > {
63
+ private async callRagWebBrowser ( query : string , maxResults : number , scrapingTool : string ) : Promise < string > {
82
64
if ( ! APIFY_API_TOKEN ) {
83
65
throw new Error ( 'APIFY_API_TOKEN is required but not set. '
84
66
+ 'Please set it in your environment variables or pass it as a command-line argument.' ) ;
@@ -87,6 +69,7 @@ export class RagWebBrowserServer {
87
69
const queryParams = new URLSearchParams ( {
88
70
query,
89
71
maxResults : maxResults . toString ( ) ,
72
+ scrapingTool,
90
73
} ) ;
91
74
const url = `${ ACTOR_BASE_URL } ?${ queryParams . toString ( ) } ` ;
92
75
const response = await fetch ( url , {
@@ -114,43 +97,14 @@ export class RagWebBrowserServer {
114
97
} ) ;
115
98
}
116
99
117
- private setupPromptHandlers ( ) : void {
118
- this . server . setRequestHandler ( ListPromptsRequestSchema , async ( ) => {
119
- return {
120
- prompts : PROMPTS ,
121
- } ;
122
- } ) ;
123
-
124
- this . server . setRequestHandler ( GetPromptRequestSchema , async ( request ) => {
125
- const { name, arguments : args } = request . params ;
126
- switch ( name ) {
127
- case TOOL_SEARCH : {
128
- const parsed = WebBrowserArgsSchema . parse ( args ) ;
129
- const content = await this . callRagWebBrowser ( parsed . query , parsed . maxResults ) ;
130
- return {
131
- description : `Markdown content for search query: ${ parsed . query } ` ,
132
- messages : [
133
- {
134
- role : 'user' ,
135
- content : { type : 'text' , text : content } ,
136
- } ,
137
- ] ,
138
- } ;
139
- }
140
- default : {
141
- throw new Error ( `Unknown prompt: ${ name } ` ) ;
142
- }
143
- }
144
- } ) ;
145
- }
146
-
147
100
private setupToolHandlers ( ) : void {
148
101
this . server . setRequestHandler ( ListToolsRequestSchema , async ( ) => {
149
102
return {
150
103
tools : [
151
104
{
152
105
name : TOOL_SEARCH ,
153
- description : 'Search phrase or a URL at Google and return crawled web pages as text or Markdown' ,
106
+ description : 'Search phrase or a URL at Google and return crawled web pages as text or Markdown. '
107
+ + 'Prefer HTTP client for speed and browser-playwright for reability.' ,
154
108
inputSchema : zodToJsonSchema ( WebBrowserArgsSchema ) ,
155
109
} ,
156
110
] ,
@@ -161,7 +115,7 @@ export class RagWebBrowserServer {
161
115
switch ( name ) {
162
116
case TOOL_SEARCH : {
163
117
const parsed = WebBrowserArgsSchema . parse ( args ) ;
164
- const content = await this . callRagWebBrowser ( parsed . query , parsed . maxResults ) ;
118
+ const content = await this . callRagWebBrowser ( parsed . query , parsed . maxResults , parsed . scrapingTool ) ;
165
119
return {
166
120
content : [ { type : 'text' , text : content } ] ,
167
121
} ;
0 commit comments