Skip to content

Commit 1740678

Browse files
Bugfixes, 1.0.1 version
1 parent b5571c9 commit 1740678

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webscraping-ai-mcp",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Model Context Protocol server for WebScraping.AI API. Provides LLM-powered web scraping tools with Chromium JavaScript rendering, rotating proxies, and HTML parsing.",
55
"type": "module",
66
"bin": {

src/index.js

100644100755
Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
45
import { z } from 'zod';
56
import axios from 'axios';
67
import dotenv from 'dotenv';
@@ -123,7 +124,7 @@ const client = new WebScrapingAIClient();
123124
// Create MCP server
124125
const server = new McpServer({
125126
name: 'WebScraping.AI MCP Server',
126-
version: '1.0.0'
127+
version: '1.0.1'
127128
});
128129

129130
// Common options schema for all tools
@@ -151,7 +152,7 @@ server.tool(
151152
},
152153
async ({ url, question, ...options }) => {
153154
try {
154-
const result = await client.question(url, question, extractOptions(options));
155+
const result = await client.question(url, question, options);
155156
return {
156157
content: [{ type: 'text', text: result }]
157158
};
@@ -173,7 +174,7 @@ server.tool(
173174
},
174175
async ({ url, fields, ...options }) => {
175176
try {
176-
const result = await client.fields(url, fields, extractOptions(options));
177+
const result = await client.fields(url, fields, options);
177178
return {
178179
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
179180
};
@@ -196,7 +197,7 @@ server.tool(
196197
},
197198
async ({ url, return_script_result, format, ...options }) => {
198199
try {
199-
const result = await client.html(url, { ...extractOptions(options), return_script_result });
200+
const result = await client.html(url, { ...options, return_script_result });
200201
if (format === 'json') {
201202
return {
202203
content: [{ type: 'text', text: JSON.stringify({ html: result }) }]
@@ -226,7 +227,7 @@ server.tool(
226227
async ({ url, text_format, return_links, ...options }) => {
227228
try {
228229
const result = await client.text(url, {
229-
...extractOptions(options),
230+
...options,
230231
text_format,
231232
return_links
232233
});
@@ -253,7 +254,7 @@ server.tool(
253254
},
254255
async ({ url, selector, format, ...options }) => {
255256
try {
256-
const result = await client.selected(url, selector, extractOptions(options));
257+
const result = await client.selected(url, selector, options);
257258
if (format === 'json') {
258259
return {
259260
content: [{ type: 'text', text: JSON.stringify({ html: result }) }]
@@ -281,7 +282,7 @@ server.tool(
281282
},
282283
async ({ url, selectors, ...options }) => {
283284
try {
284-
const result = await client.selectedMultiple(url, selectors, extractOptions(options));
285+
const result = await client.selectedMultiple(url, selectors, options);
285286
return {
286287
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
287288
};
@@ -312,24 +313,9 @@ server.tool(
312313
}
313314
);
314315

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);
335321
});

src/index.test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
beforeEach,
77
afterEach,
88
} from '@jest/globals';
9+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
10+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
911

1012
// Create mock WebScrapingAIClient
1113
class MockWebScrapingAIClient {
@@ -184,6 +186,55 @@ describe('WebScraping.AI MCP Server Tests', () => {
184186
expect(response.isError).toBe(true);
185187
expect(response.content[0].text).toContain('Unknown tool');
186188
});
189+
190+
// Test MCP Client Connection
191+
test('should connect to MCP server and list tools', async () => {
192+
const transport = new StdioClientTransport({
193+
command: "node",
194+
args: ["src/index.js"]
195+
});
196+
197+
const client = new Client({
198+
name: "webscraping-ai-test-client",
199+
version: "1.0.0"
200+
});
201+
202+
await client.connect(transport);
203+
const response = await client.listTools();
204+
205+
expect(response.tools).toEqual(expect.arrayContaining([
206+
expect.objectContaining({
207+
name: 'webscraping_ai_question',
208+
inputSchema: expect.any(Object)
209+
}),
210+
expect.objectContaining({
211+
name: 'webscraping_ai_fields',
212+
inputSchema: expect.any(Object)
213+
}),
214+
expect.objectContaining({
215+
name: 'webscraping_ai_html',
216+
inputSchema: expect.any(Object)
217+
}),
218+
expect.objectContaining({
219+
name: 'webscraping_ai_text',
220+
inputSchema: expect.any(Object)
221+
}),
222+
expect.objectContaining({
223+
name: 'webscraping_ai_selected',
224+
inputSchema: expect.any(Object)
225+
}),
226+
expect.objectContaining({
227+
name: 'webscraping_ai_selected_multiple',
228+
inputSchema: expect.any(Object)
229+
}),
230+
expect.objectContaining({
231+
name: 'webscraping_ai_account',
232+
inputSchema: expect.any(Object)
233+
})
234+
]));
235+
236+
await client.close();
237+
});
187238
});
188239

189240
// Helper function to simulate request handling
@@ -288,4 +339,4 @@ async function handleRequest(name, args, client) {
288339
isError: true
289340
};
290341
}
291-
}
342+
}

0 commit comments

Comments
 (0)