1
1
#!/usr/bin/env node
2
2
3
3
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js' ;
4
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js' ;
4
5
import { z } from 'zod' ;
5
6
import axios from 'axios' ;
6
7
import dotenv from 'dotenv' ;
@@ -123,7 +124,7 @@ const client = new WebScrapingAIClient();
123
124
// Create MCP server
124
125
const server = new McpServer ( {
125
126
name : 'WebScraping.AI MCP Server' ,
126
- version : '1.0.0 '
127
+ version : '1.0.1 '
127
128
} ) ;
128
129
129
130
// Common options schema for all tools
@@ -151,7 +152,7 @@ server.tool(
151
152
} ,
152
153
async ( { url, question, ...options } ) => {
153
154
try {
154
- const result = await client . question ( url , question , extractOptions ( options ) ) ;
155
+ const result = await client . question ( url , question , options ) ;
155
156
return {
156
157
content : [ { type : 'text' , text : result } ]
157
158
} ;
@@ -173,7 +174,7 @@ server.tool(
173
174
} ,
174
175
async ( { url, fields, ...options } ) => {
175
176
try {
176
- const result = await client . fields ( url , fields , extractOptions ( options ) ) ;
177
+ const result = await client . fields ( url , fields , options ) ;
177
178
return {
178
179
content : [ { type : 'text' , text : JSON . stringify ( result , null , 2 ) } ]
179
180
} ;
@@ -196,7 +197,7 @@ server.tool(
196
197
} ,
197
198
async ( { url, return_script_result, format, ...options } ) => {
198
199
try {
199
- const result = await client . html ( url , { ...extractOptions ( options ) , return_script_result } ) ;
200
+ const result = await client . html ( url , { ...options , return_script_result } ) ;
200
201
if ( format === 'json' ) {
201
202
return {
202
203
content : [ { type : 'text' , text : JSON . stringify ( { html : result } ) } ]
@@ -226,7 +227,7 @@ server.tool(
226
227
async ( { url, text_format, return_links, ...options } ) => {
227
228
try {
228
229
const result = await client . text ( url , {
229
- ...extractOptions ( options ) ,
230
+ ...options ,
230
231
text_format,
231
232
return_links
232
233
} ) ;
@@ -253,7 +254,7 @@ server.tool(
253
254
} ,
254
255
async ( { url, selector, format, ...options } ) => {
255
256
try {
256
- const result = await client . selected ( url , selector , extractOptions ( options ) ) ;
257
+ const result = await client . selected ( url , selector , options ) ;
257
258
if ( format === 'json' ) {
258
259
return {
259
260
content : [ { type : 'text' , text : JSON . stringify ( { html : result } ) } ]
@@ -281,7 +282,7 @@ server.tool(
281
282
} ,
282
283
async ( { url, selectors, ...options } ) => {
283
284
try {
284
- const result = await client . selectedMultiple ( url , selectors , extractOptions ( options ) ) ;
285
+ const result = await client . selectedMultiple ( url , selectors , options ) ;
285
286
return {
286
287
content : [ { type : 'text' , text : JSON . stringify ( result , null , 2 ) } ]
287
288
} ;
@@ -312,24 +313,9 @@ server.tool(
312
313
}
313
314
) ;
314
315
315
- // Helper function to extract and normalize options
316
- function extractOptions ( options ) {
317
- const normalizedOptions = { ...options } ;
318
-
319
- // Convert js_timeout to jsTimeout for API compatibility
320
- if ( normalizedOptions . js_timeout ) {
321
- normalizedOptions . jsTimeout = normalizedOptions . js_timeout ;
322
- delete normalizedOptions . js_timeout ;
323
- }
324
-
325
- return normalizedOptions ;
326
- }
327
-
328
- import ( '@modelcontextprotocol/sdk/server/stdio.js' ) . then ( ( { StdioServerTransport } ) => {
329
- const transport = new StdioServerTransport ( ) ;
330
- server . connect ( transport ) . then ( ( ) => {
331
- } ) . catch ( err => {
332
- console . error ( 'Failed to connect to transport:' , err ) ;
333
- process . exit ( 1 ) ;
334
- } ) ;
316
+ const transport = new StdioServerTransport ( ) ;
317
+ server . connect ( transport ) . then ( ( ) => {
318
+ } ) . catch ( err => {
319
+ console . error ( 'Failed to connect to transport:' , err ) ;
320
+ process . exit ( 1 ) ;
335
321
} ) ;
0 commit comments