search1api-mcp 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -61,6 +61,13 @@ More discussions, please join the official [discord](https://discord.com/invite/
61
61
  - Parameters:
62
62
  * `content` (required): The question or problem that needs deep thinking
63
63
 
64
+ ### 6. Trending Tool
65
+ - Name: `trending`
66
+ - Description: Get trending topics from popular platforms
67
+ - Parameters:
68
+ * `search_service` (required): Specify the platform to get trending topics from (github, hackernews)
69
+ * `max_results` (optional, default: 10): Maximum number of trending items to return
70
+
64
71
  ## Setup Guide
65
72
 
66
73
  ### 1. Get Search1API Key
@@ -85,6 +92,7 @@ More discussions, please join the official [discord](https://discord.com/invite/
85
92
 
86
93
  ## Version History
87
94
 
95
+ - v0.1.7: Added Trending tool for GitHub and Hacker News
88
96
  - v0.1.6: Added Wikipedia search service
89
97
  - v0.1.5: Added new search parameters (include_sites, exclude_sites, time_range) and new search services (arxiv, wechat, bilibili, imdb)
90
98
  - v0.1.4: Added reasoning tool with deepseek r1 and updated the Cursor and Windsurf configuration guide
package/build/api.js ADDED
@@ -0,0 +1,37 @@
1
+ import { API_KEY, API_CONFIG } from './config.js';
2
+ import { log } from './utils.js';
3
+ /**
4
+ * Unified API request function
5
+ * @param endpoint API endpoint
6
+ * @param data Request data
7
+ * @returns API response
8
+ */
9
+ export async function makeRequest(endpoint, data) {
10
+ const startTime = Date.now();
11
+ const baseUrl = API_CONFIG.BASE_URL.replace(/\/+$/, '');
12
+ const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
13
+ const url = `${baseUrl}${path}`;
14
+ try {
15
+ const response = await fetch(url, {
16
+ method: 'POST',
17
+ headers: {
18
+ 'Authorization': `Bearer ${API_KEY}`,
19
+ 'Content-Type': 'application/json',
20
+ },
21
+ body: JSON.stringify(data)
22
+ });
23
+ if (!response.ok) {
24
+ const errorData = await response.json().catch(() => ({}));
25
+ throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
26
+ }
27
+ const result = await response.json();
28
+ const duration = Date.now() - startTime;
29
+ log(`API request to ${endpoint} completed in ${duration}ms`);
30
+ return result;
31
+ }
32
+ catch (error) {
33
+ const duration = Date.now() - startTime;
34
+ log(`API request to ${endpoint} failed after ${duration}ms:`, error);
35
+ throw error;
36
+ }
37
+ }
@@ -0,0 +1,22 @@
1
+ import dotenv from "dotenv";
2
+ dotenv.config();
3
+ // Check API key
4
+ const API_KEY = process.env.SEARCH1API_KEY;
5
+ if (!API_KEY) {
6
+ throw new Error("SEARCH1API_KEY environment variable is required");
7
+ }
8
+ // API configuration
9
+ export const API_CONFIG = {
10
+ BASE_URL: 'https://api.search1api.com',
11
+ DEFAULT_QUERY: 'latest news in the world',
12
+ ENDPOINTS: {
13
+ SEARCH: '/search',
14
+ CRAWL: '/crawl',
15
+ SITEMAP: '/sitemap',
16
+ NEWS: '/news',
17
+ REASONING: '/v1/chat/completions',
18
+ TRENDING: '/trending'
19
+ }
20
+ };
21
+ // Export API key
22
+ export { API_KEY };
package/build/index.js CHANGED
@@ -1,438 +1,47 @@
1
1
  #!/usr/bin/env node
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
5
- import dotenv from "dotenv";
6
- import { isValidSearchArgs, isValidCrawlArgs, isValidSitemapArgs, isValidNewsArgs } from "./types.js";
7
- dotenv.config();
8
- const API_KEY = process.env.SEARCH1API_KEY;
9
- if (!API_KEY) {
10
- throw new Error("SEARCH1API_KEY environment variable is required");
11
- }
12
- const API_CONFIG = {
13
- BASE_URL: 'https://api.search1api.com',
14
- DEFAULT_QUERY: 'latest news in the world',
15
- ENDPOINTS: {
16
- SEARCH: '/search',
17
- CRAWL: '/crawl',
18
- SITEMAP: '/sitemap',
19
- NEWS: '/news',
20
- REASONING: '/v1/chat/completions'
21
- }
22
- };
23
- const SEARCH_TOOL = {
24
- name: "search",
25
- description: "Search the web for real-time results",
26
- inputSchema: {
27
- type: "object",
28
- properties: {
29
- query: {
30
- type: "string",
31
- description: "Search query in natural language. Be specific and concise for better results"
32
- },
33
- max_results: {
34
- type: "number",
35
- description: "Maximum number of results to return",
36
- default: 10
37
- },
38
- search_service: {
39
- type: "string",
40
- description: "Specify the search engine to use. Choose based on your specific needs",
41
- default: "google",
42
- enum: ["google", "bing", "duckduckgo", "yahoo", "github", "youtube", "arxiv", "wechat", "bilibili", "imdb", "wikipedia"]
43
- },
44
- crawl_results: {
45
- type: "number",
46
- description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
47
- default: 0
48
- },
49
- include_sites: {
50
- type: "array",
51
- items: {
52
- type: "string"
53
- },
54
- description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
55
- default: []
56
- },
57
- exclude_sites: {
58
- type: "array",
59
- items: {
60
- type: "string"
61
- },
62
- description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
63
- default: []
64
- },
65
- time_range: {
66
- type: "string",
67
- description: "Time range for search results, only use when specific time constraints are required",
68
- enum: ["day", "month", "year"]
69
- }
70
- },
71
- required: ["query"]
72
- }
73
- };
74
- const NEWS_TOOL = {
75
- name: "news",
76
- description: "Search for news articles",
77
- inputSchema: {
78
- type: "object",
79
- properties: {
80
- query: {
81
- type: "string",
82
- description: "Search query in natural language. Be specific and concise for better results"
83
- },
84
- max_results: {
85
- type: "number",
86
- description: "Maximum number of results to return",
87
- default: 10
88
- },
89
- search_service: {
90
- type: "string",
91
- description: "Specify the news engine to use. Choose based on your specific needs",
92
- default: "bing",
93
- enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"]
94
- },
95
- crawl_results: {
96
- type: "number",
97
- description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
98
- default: 0
99
- },
100
- include_sites: {
101
- type: "array",
102
- items: {
103
- type: "string"
104
- },
105
- description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
106
- default: []
107
- },
108
- exclude_sites: {
109
- type: "array",
110
- items: {
111
- type: "string"
112
- },
113
- description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
114
- default: []
115
- },
116
- time_range: {
117
- type: "string",
118
- description: "Time range for search results, only use when specific time constraints are required",
119
- enum: ["day", "month", "year"]
120
- }
121
- },
122
- required: ["query"]
123
- }
124
- };
125
- const CRAWL_TOOL = {
126
- name: "crawl",
127
- description: "Extract content from URL",
128
- inputSchema: {
129
- type: "object",
130
- properties: {
131
- url: {
132
- type: "string",
133
- description: "URL to crawl"
134
- }
135
- },
136
- required: ["url"]
137
- }
138
- };
139
- const SITEMAP_TOOL = {
140
- name: "sitemap",
141
- description: "Get all related links from a URL",
142
- inputSchema: {
143
- type: "object",
144
- properties: {
145
- url: {
146
- type: "string",
147
- description: "URL to get sitemap"
148
- }
149
- },
150
- required: ["url"]
151
- }
152
- };
153
- const REASONING_TOOL = {
154
- name: "reasoning",
155
- description: "Deep thinking and complex problem solving",
156
- inputSchema: {
157
- type: "object",
158
- properties: {
159
- content: {
160
- type: "string",
161
- description: "The question or problem that needs deep thinking"
162
- }
163
- },
164
- required: ["content"]
2
+ import { log } from "./utils.js";
3
+ import { createServer } from "./server.js";
4
+ import { API_KEY } from "./config.js";
5
+ /**
6
+ * Main function - Program entry point
7
+ */
8
+ async function main() {
9
+ // Ensure API key exists
10
+ if (!API_KEY) {
11
+ log("SEARCH1API_KEY environment variable is not set");
12
+ process.exit(1);
165
13
  }
166
- };
167
- // Server implementation
168
- const server = new Server({
169
- name: "search1api-mcp",
170
- version: "0.1.6",
171
- }, {
172
- capabilities: {
173
- resources: {
174
- supportedTypes: ["application/json", "text/plain"],
175
- },
176
- tools: {
177
- search: {
178
- description: "Search functionality"
179
- },
180
- news: {
181
- description: "News search functionality"
182
- },
183
- crawl: {
184
- description: "Web crawling functionality"
185
- },
186
- sitemap: {
187
- description: "Sitemap extraction functionality"
188
- },
189
- reasoning: {
190
- description: "Deep thinking and complex problem solving"
191
- }
192
- },
193
- },
194
- });
195
- // Add server event listeners
196
- server.onerror = (error) => {
197
- log('MCP Server Error:', error);
198
- };
199
- server.onclose = () => {
200
- log('MCP Server Connection Closed');
201
- };
202
- // Add asynchronous request function
203
- async function makeRequest(endpoint, data) {
204
- const startTime = Date.now();
205
- // Ensure BASE_URL has no trailing slash and endpoint starts with slash
206
- const baseUrl = API_CONFIG.BASE_URL.replace(/\/+$/, '');
207
- const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
208
- const url = `${baseUrl}${path}`;
209
14
  try {
210
- const response = await fetch(url, {
211
- method: 'POST',
212
- headers: {
213
- 'Authorization': `Bearer ${API_KEY}`,
214
- 'Content-Type': 'application/json',
215
- },
216
- body: JSON.stringify(data)
217
- });
218
- if (!response.ok) {
219
- const errorData = await response.json().catch(() => ({}));
220
- throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
221
- }
222
- const result = await response.json();
223
- const duration = Date.now() - startTime;
224
- log(`API request to ${endpoint} completed in ${duration}ms`);
225
- return result;
15
+ log("Starting Search1API MCP server");
16
+ const server = createServer();
17
+ // Start server
18
+ await server.start();
19
+ log("Server started successfully");
20
+ // Handle process exit signals
21
+ setupExitHandlers(server);
226
22
  }
227
23
  catch (error) {
228
- const duration = Date.now() - startTime;
229
- log(`API request to ${endpoint} failed after ${duration}ms:`, error);
230
- throw error;
231
- }
232
- }
233
- // Add error handling utility function
234
- function formatError(error) {
235
- if (error instanceof Error) {
236
- return error.message;
237
- }
238
- return String(error);
239
- }
240
- // Resource handlers
241
- server.setRequestHandler(ListResourcesRequestSchema, async () => ({
242
- resources: [{
243
- uri: `search://${encodeURIComponent(API_CONFIG.DEFAULT_QUERY)}`,
244
- name: `Search results for "${API_CONFIG.DEFAULT_QUERY}"`,
245
- mimeType: "application/json",
246
- description: "Search results including title, link, and snippet"
247
- }]
248
- }));
249
- server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
250
- const defaultQuery = API_CONFIG.DEFAULT_QUERY;
251
- if (request.params.uri !== `search://${encodeURIComponent(defaultQuery)}`) {
252
- throw new McpError(ErrorCode.InvalidRequest, `Unknown resource: ${request.params.uri}`);
24
+ log("Failed to start server:", error);
25
+ process.exit(1);
253
26
  }
254
- try {
255
- const response = await makeRequest(API_CONFIG.ENDPOINTS.SEARCH, {
256
- query: defaultQuery,
257
- search_service: "google",
258
- max_results: 10
259
- });
260
- return {
261
- contents: [{
262
- uri: request.params.uri,
263
- mimeType: "application/json",
264
- text: JSON.stringify(response.results, null, 2)
265
- }]
266
- };
267
- }
268
- catch (error) {
269
- log("Search error:", error);
270
- return {
271
- contents: [{
272
- uri: request.params.uri,
273
- mimeType: "text/plain",
274
- text: `Search API error: ${formatError(error)}`
275
- }],
276
- isError: true
277
- };
278
- }
279
- });
280
- // Tool handlers
281
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
282
- tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL],
283
- }));
284
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
285
- try {
286
- const { name, arguments: args } = request.params;
287
- if (!args) {
288
- throw new Error("No arguments provided");
289
- }
290
- switch (name) {
291
- case "search": {
292
- if (!isValidSearchArgs(args)) {
293
- throw new McpError(ErrorCode.InvalidParams, "Invalid search arguments");
294
- }
295
- const response = await makeRequest(API_CONFIG.ENDPOINTS.SEARCH, args);
296
- return {
297
- content: [{
298
- type: "text",
299
- mimeType: "application/json",
300
- text: JSON.stringify(response.results, null, 2)
301
- }]
302
- };
303
- }
304
- case "news": {
305
- if (!isValidNewsArgs(args)) {
306
- throw new McpError(ErrorCode.InvalidParams, "Invalid news arguments");
307
- }
308
- const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, args);
309
- return {
310
- content: [{
311
- type: "text",
312
- mimeType: "application/json",
313
- text: JSON.stringify(response.results, null, 2)
314
- }]
315
- };
316
- }
317
- case "crawl": {
318
- if (!isValidCrawlArgs(args)) {
319
- throw new McpError(ErrorCode.InvalidParams, "Invalid crawl arguments");
320
- }
321
- const { url } = args;
322
- log("Starting crawl for:", url);
323
- try {
324
- const startTime = Date.now();
325
- const response = await makeRequest(API_CONFIG.ENDPOINTS.CRAWL, { url });
326
- const endTime = Date.now();
327
- log(`Crawl completed successfully in ${endTime - startTime}ms`);
328
- return {
329
- content: [{
330
- type: "text",
331
- mimeType: "application/json",
332
- text: JSON.stringify(response.results, null, 2)
333
- }]
334
- };
335
- }
336
- catch (error) {
337
- log("Crawl error:", error);
338
- return {
339
- content: [{
340
- type: "text",
341
- mimeType: "text/plain",
342
- text: `Crawl API error: ${formatError(error)}`
343
- }],
344
- isError: true
345
- };
346
- }
347
- }
348
- case "sitemap": {
349
- if (!isValidSitemapArgs(args)) {
350
- throw new McpError(ErrorCode.InvalidParams, "Invalid sitemap arguments");
351
- }
352
- try {
353
- const response = await makeRequest(API_CONFIG.ENDPOINTS.SITEMAP, args);
354
- return {
355
- content: [{
356
- type: "text",
357
- mimeType: "application/json",
358
- text: JSON.stringify(response.links, null, 2)
359
- }]
360
- };
361
- }
362
- catch (error) {
363
- throw formatError(error);
364
- }
365
- }
366
- case "reasoning": {
367
- if (!args) {
368
- throw new Error("No arguments provided");
369
- }
370
- const { content } = args;
371
- const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.REASONING}`, {
372
- method: 'POST',
373
- headers: {
374
- 'Authorization': `Bearer ${API_KEY}`,
375
- 'Content-Type': 'application/json',
376
- },
377
- body: JSON.stringify({
378
- model: "deepseek-r1-70b-fast-online",
379
- messages: [
380
- {
381
- role: "user",
382
- content: content
383
- }
384
- ],
385
- stream: false
386
- })
387
- });
388
- if (!response.ok) {
389
- const errorData = await response.json().catch(() => ({}));
390
- throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
391
- }
392
- const result = await response.json();
393
- return {
394
- content: [{
395
- type: "text",
396
- mimeType: "application/json",
397
- text: JSON.stringify(result.choices[0].message)
398
- }]
399
- };
400
- }
401
- default:
402
- throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
403
- }
404
- }
405
- catch (error) {
406
- log("Tool error:", error);
407
- return {
408
- content: [{
409
- type: "text",
410
- mimeType: "text/plain",
411
- text: `API error: ${formatError(error)}`
412
- }],
413
- isError: true
414
- };
415
- }
416
- });
417
- // Add logging utility function
418
- function log(message, ...args) {
419
- const timestamp = new Date().toISOString();
420
- console.error(`[${timestamp}] ${message}`, ...args);
421
27
  }
422
- async function runServer() {
423
- const transport = new StdioServerTransport();
424
- log("Starting Search1API MCP Server...");
425
- // Add global error handling
426
- process.on('uncaughtException', (error) => {
427
- log('Uncaught Exception:', error);
428
- });
429
- process.on('unhandledRejection', (reason, promise) => {
430
- log('Unhandled Rejection at:', promise, 'reason:', reason);
431
- });
432
- await server.connect(transport);
433
- log("Search1API MCP Server running on stdio");
28
+ /**
29
+ * Set up process exit signal handlers
30
+ */
31
+ function setupExitHandlers(server) {
32
+ const exitHandler = async () => {
33
+ log("Shutting down server...");
34
+ await server.stop();
35
+ process.exit(0);
36
+ };
37
+ // Handle various exit signals
38
+ process.on("SIGINT", exitHandler);
39
+ process.on("SIGTERM", exitHandler);
40
+ process.on("SIGUSR1", exitHandler);
41
+ process.on("SIGUSR2", exitHandler);
434
42
  }
435
- runServer().catch((error) => {
436
- log('Fatal error running server:', error);
43
+ // Start program
44
+ main().catch((error) => {
45
+ log("Fatal error:", error);
437
46
  process.exit(1);
438
47
  });
@@ -0,0 +1,34 @@
1
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
+ import { log } from './utils.js';
3
+ /**
4
+ * Define the default search query result resource
5
+ */
6
+ export const DEFAULT_SEARCH_RESOURCE = {
7
+ uri: "search1api://info",
8
+ name: "Search1API Information",
9
+ description: "Basic information about Search1API capabilities",
10
+ mimeType: "application/json"
11
+ };
12
+ /**
13
+ * List of all available resources
14
+ */
15
+ export const RESOURCES = [DEFAULT_SEARCH_RESOURCE];
16
+ /**
17
+ * Handle list resources request
18
+ */
19
+ export function handleListResources() {
20
+ log("Handling list resources request");
21
+ return RESOURCES;
22
+ }
23
+ /**
24
+ * Handle read resource request
25
+ * @param resourceUri The resource URI to read
26
+ */
27
+ export function handleReadResource(resourceUri) {
28
+ log(`Handling read resource request for ${resourceUri}`);
29
+ const resource = RESOURCES.find((r) => r.uri === resourceUri);
30
+ if (!resource) {
31
+ throw new McpError(ErrorCode.InvalidRequest, `Resource not found: ${resourceUri}`);
32
+ }
33
+ return resource;
34
+ }
@@ -0,0 +1,112 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { McpError, ErrorCode, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
4
+ import { handleToolCall } from "./tools/handlers.js";
5
+ import { log, formatError } from "./utils.js";
6
+ import { handleListResources, handleReadResource } from "./resources.js";
7
+ import { ALL_TOOLS } from "./tools/index.js";
8
+ /**
9
+ * Create and configure MCP server
10
+ */
11
+ export function createServer() {
12
+ log("Creating Search1API MCP server");
13
+ // Create server instance
14
+ const server = new Server({
15
+ name: "search1api-server",
16
+ version: "1.0.0"
17
+ }, {
18
+ capabilities: {
19
+ resources: {},
20
+ tools: {}
21
+ }
22
+ });
23
+ // Set up request handlers
24
+ setupRequestHandlers(server);
25
+ // Create STDIO transport
26
+ const transport = new StdioServerTransport();
27
+ return {
28
+ start: async () => {
29
+ try {
30
+ await server.connect(transport);
31
+ log("Server started successfully");
32
+ }
33
+ catch (error) {
34
+ log("Failed to start server:", error);
35
+ throw error;
36
+ }
37
+ },
38
+ stop: async () => {
39
+ try {
40
+ await server.close();
41
+ log("Server stopped");
42
+ }
43
+ catch (error) {
44
+ log("Error stopping server:", error);
45
+ }
46
+ }
47
+ };
48
+ }
49
+ /**
50
+ * Helper function to handle errors uniformly
51
+ */
52
+ function handleError(context, error) {
53
+ log(`Error ${context}:`, error);
54
+ if (error instanceof McpError) {
55
+ throw error;
56
+ }
57
+ throw new McpError(ErrorCode.InternalError, `${context}: ${formatError(error)}`);
58
+ }
59
+ /**
60
+ * Set up server request handlers
61
+ */
62
+ function setupRequestHandlers(server) {
63
+ // Handle tool calls
64
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
65
+ try {
66
+ const toolName = request.params.name;
67
+ const toolArgs = request.params.arguments;
68
+ log(`Tool call received: ${toolName}`);
69
+ return await handleToolCall(toolName, toolArgs);
70
+ }
71
+ catch (error) {
72
+ handleError("handling tool call", error);
73
+ }
74
+ });
75
+ // Handle resource listing
76
+ server.setRequestHandler(ListResourcesRequestSchema, async () => {
77
+ try {
78
+ return { resources: handleListResources() };
79
+ }
80
+ catch (error) {
81
+ handleError("listing resources", error);
82
+ }
83
+ });
84
+ // Handle resource reading
85
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
86
+ try {
87
+ const resourceUri = request.params.uri;
88
+ const resource = handleReadResource(resourceUri);
89
+ return {
90
+ contents: [{
91
+ uri: resourceUri,
92
+ mimeType: resource.mimeType || "application/json",
93
+ text: JSON.stringify(resource)
94
+ }]
95
+ };
96
+ }
97
+ catch (error) {
98
+ handleError("reading resource", error);
99
+ }
100
+ });
101
+ // Handle tool listing
102
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
103
+ return { tools: ALL_TOOLS };
104
+ });
105
+ // Handle global errors
106
+ process.on("uncaughtException", (error) => {
107
+ log("Uncaught exception:", error);
108
+ });
109
+ process.on("unhandledRejection", (reason) => {
110
+ log("Unhandled rejection:", reason);
111
+ });
112
+ }
@@ -0,0 +1,39 @@
1
+ import { isValidCrawlArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError, log } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the crawl tool
8
+ */
9
+ export async function handleCrawl(args) {
10
+ if (!isValidCrawlArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid crawl arguments");
12
+ }
13
+ const { url } = args;
14
+ log("Starting crawl for:", url);
15
+ try {
16
+ const startTime = Date.now();
17
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.CRAWL, { url });
18
+ const endTime = Date.now();
19
+ log(`Crawl completed successfully in ${endTime - startTime}ms`);
20
+ return {
21
+ content: [{
22
+ type: "text",
23
+ mimeType: "application/json",
24
+ text: JSON.stringify(response.results, null, 2)
25
+ }]
26
+ };
27
+ }
28
+ catch (error) {
29
+ log("Crawl error:", error);
30
+ return {
31
+ content: [{
32
+ type: "text",
33
+ mimeType: "text/plain",
34
+ text: `Crawl API error: ${formatError(error)}`
35
+ }],
36
+ isError: true
37
+ };
38
+ }
39
+ }
@@ -0,0 +1,35 @@
1
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
+ import { log } from '../utils.js';
3
+ import { handleSearch } from './search.js';
4
+ import { handleCrawl } from './crawl.js';
5
+ import { handleSitemap } from './sitemap.js';
6
+ import { handleNews } from './news.js';
7
+ import { handleReasoning } from './reasoning.js';
8
+ import { handleTrending } from './trending.js';
9
+ import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL, TRENDING_TOOL } from './index.js';
10
+ /**
11
+ * Dispatch request based on tool name
12
+ * @param toolName Name of the tool
13
+ * @param args Tool parameters
14
+ * @returns Tool processing result
15
+ */
16
+ export async function handleToolCall(toolName, args) {
17
+ log(`Handling tool call: ${toolName}`);
18
+ switch (toolName) {
19
+ case SEARCH_TOOL.name:
20
+ return await handleSearch(args);
21
+ case CRAWL_TOOL.name:
22
+ return await handleCrawl(args);
23
+ case SITEMAP_TOOL.name:
24
+ return await handleSitemap(args);
25
+ case NEWS_TOOL.name:
26
+ return await handleNews(args);
27
+ case REASONING_TOOL.name:
28
+ return await handleReasoning(args);
29
+ case TRENDING_TOOL.name:
30
+ return await handleTrending(args);
31
+ default:
32
+ log(`Unknown tool: ${toolName}`);
33
+ throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${toolName}`);
34
+ }
35
+ }
@@ -0,0 +1,180 @@
1
+ // Search tool definition
2
+ export const SEARCH_TOOL = {
3
+ name: "search",
4
+ description: "Web search tool",
5
+ inputSchema: {
6
+ type: "object",
7
+ properties: {
8
+ query: {
9
+ type: "string",
10
+ description: "Search query, be simple and concise"
11
+ },
12
+ max_results: {
13
+ type: "number",
14
+ description: "Maximum number of results to return",
15
+ default: 10
16
+ },
17
+ search_service: {
18
+ type: "string",
19
+ description: "Specify the search engine to use. Choose based on your specific needs",
20
+ default: "google",
21
+ enum: ["google", "bing", "duckduckgo", "yahoo", "github", "youtube", "arxiv", "wechat", "bilibili", "imdb", "wikipedia"]
22
+ },
23
+ crawl_results: {
24
+ type: "number",
25
+ description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
26
+ default: 0
27
+ },
28
+ include_sites: {
29
+ type: "array",
30
+ items: {
31
+ type: "string"
32
+ },
33
+ description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
34
+ default: []
35
+ },
36
+ exclude_sites: {
37
+ type: "array",
38
+ items: {
39
+ type: "string"
40
+ },
41
+ description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
42
+ default: []
43
+ },
44
+ time_range: {
45
+ type: "string",
46
+ description: "Time range for search results, only use when specific time constraints are required",
47
+ enum: ["day", "month", "year"]
48
+ }
49
+ },
50
+ required: ["query"]
51
+ }
52
+ };
53
+ // News tool definition
54
+ export const NEWS_TOOL = {
55
+ name: "news",
56
+ description: "News search tool",
57
+ inputSchema: {
58
+ type: "object",
59
+ properties: {
60
+ query: {
61
+ type: "string",
62
+ description: "Search query, be simple and concise"
63
+ },
64
+ max_results: {
65
+ type: "number",
66
+ description: "Maximum number of results to return",
67
+ default: 10
68
+ },
69
+ search_service: {
70
+ type: "string",
71
+ description: "Specify the news engine to use. Choose based on your specific needs",
72
+ default: "bing",
73
+ enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"]
74
+ },
75
+ crawl_results: {
76
+ type: "number",
77
+ description: "Number of results to crawl for full webpage content, useful when search result summaries are insufficient for complex queries",
78
+ default: 0
79
+ },
80
+ include_sites: {
81
+ type: "array",
82
+ items: {
83
+ type: "string"
84
+ },
85
+ description: "List of sites to include in search. Only use when you need special results from sites not available in search_service",
86
+ default: []
87
+ },
88
+ exclude_sites: {
89
+ type: "array",
90
+ items: {
91
+ type: "string"
92
+ },
93
+ description: "List of sites to exclude from search. Only use when you need to explicitly filter out specific domains from results",
94
+ default: []
95
+ },
96
+ time_range: {
97
+ type: "string",
98
+ description: "Time range for search results, only use when specific time constraints are required",
99
+ enum: ["day", "month", "year"]
100
+ }
101
+ },
102
+ required: ["query"]
103
+ }
104
+ };
105
+ // Crawl tool definition
106
+ export const CRAWL_TOOL = {
107
+ name: "crawl",
108
+ description: "Extract content from URL",
109
+ inputSchema: {
110
+ type: "object",
111
+ properties: {
112
+ url: {
113
+ type: "string",
114
+ description: "URL to crawl"
115
+ }
116
+ },
117
+ required: ["url"]
118
+ }
119
+ };
120
+ // Sitemap tool definition
121
+ export const SITEMAP_TOOL = {
122
+ name: "sitemap",
123
+ description: "Get all related links from a URL",
124
+ inputSchema: {
125
+ type: "object",
126
+ properties: {
127
+ url: {
128
+ type: "string",
129
+ description: "URL to get sitemap"
130
+ }
131
+ },
132
+ required: ["url"]
133
+ }
134
+ };
135
+ // Reasoning tool definition
136
+ export const REASONING_TOOL = {
137
+ name: "reasoning",
138
+ description: "Deep thinking and complex problem solving",
139
+ inputSchema: {
140
+ type: "object",
141
+ properties: {
142
+ content: {
143
+ type: "string",
144
+ description: "The question or problem that needs deep thinking"
145
+ }
146
+ },
147
+ required: ["content"]
148
+ }
149
+ };
150
+ // Trending tool definition
151
+ export const TRENDING_TOOL = {
152
+ name: "trending",
153
+ description: "Get trending topics from popular platforms",
154
+ inputSchema: {
155
+ type: "object",
156
+ properties: {
157
+ search_service: {
158
+ type: "string",
159
+ description: "Specify the platform to get trending topics from",
160
+ enum: ["github", "hackernews"],
161
+ default: "github"
162
+ },
163
+ max_results: {
164
+ type: "number",
165
+ description: "Maximum number of trending items to return",
166
+ default: 10
167
+ }
168
+ },
169
+ required: ["search_service"]
170
+ }
171
+ };
172
+ // Export all tools
173
+ export const ALL_TOOLS = [
174
+ SEARCH_TOOL,
175
+ NEWS_TOOL,
176
+ CRAWL_TOOL,
177
+ SITEMAP_TOOL,
178
+ REASONING_TOOL,
179
+ TRENDING_TOOL
180
+ ];
@@ -0,0 +1,35 @@
1
+ import { isValidNewsArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError, log } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the news search tool
8
+ */
9
+ export async function handleNews(args) {
10
+ if (!isValidNewsArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid news search arguments");
12
+ }
13
+ log("Processing news search with query:", args.query);
14
+ try {
15
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, args);
16
+ return {
17
+ content: [{
18
+ type: "text",
19
+ mimeType: "application/json",
20
+ text: JSON.stringify(response.results, null, 2)
21
+ }]
22
+ };
23
+ }
24
+ catch (error) {
25
+ log("News search error:", error);
26
+ return {
27
+ content: [{
28
+ type: "text",
29
+ mimeType: "text/plain",
30
+ text: `News API error: ${formatError(error)}`
31
+ }],
32
+ isError: true
33
+ };
34
+ }
35
+ }
@@ -0,0 +1,56 @@
1
+ import { isValidReasoningArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError, log } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the deep thinking and complex reasoning tool
8
+ */
9
+ export async function handleReasoning(args) {
10
+ if (!isValidReasoningArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid reasoning arguments");
12
+ }
13
+ const { content } = args;
14
+ log("Processing reasoning request");
15
+ try {
16
+ /**
17
+ * Implementation of the deep thinking and complex reasoning tool
18
+ */
19
+ // Convert to API required format
20
+ const apiRequestData = {
21
+ model: "deepseek-r1-70b-fast-online",
22
+ messages: [
23
+ {
24
+ role: "user",
25
+ content: content
26
+ }
27
+ ],
28
+ stream: false
29
+ };
30
+ // Use the correct structure of ReasoningResponse
31
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.REASONING, apiRequestData // Using converted format instead of raw args
32
+ );
33
+ // Directly use the correct structure of ReasoningResponse
34
+ const resultText = response.choices && response.choices.length > 0
35
+ ? response.choices[0].message.content
36
+ : JSON.stringify(response);
37
+ return {
38
+ content: [{
39
+ type: "text",
40
+ mimeType: "text/plain",
41
+ text: resultText
42
+ }]
43
+ };
44
+ }
45
+ catch (error) {
46
+ log("Reasoning API error:", error);
47
+ return {
48
+ content: [{
49
+ type: "text",
50
+ mimeType: "text/plain",
51
+ text: `Reasoning API error: ${formatError(error)}`
52
+ }],
53
+ isError: true
54
+ };
55
+ }
56
+ }
@@ -0,0 +1,33 @@
1
+ import { isValidSearchArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the search tool
8
+ */
9
+ export async function handleSearch(args) {
10
+ if (!isValidSearchArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid search arguments");
12
+ }
13
+ try {
14
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.SEARCH, args);
15
+ return {
16
+ content: [{
17
+ type: "text",
18
+ mimeType: "application/json",
19
+ text: JSON.stringify(response.results, null, 2)
20
+ }]
21
+ };
22
+ }
23
+ catch (error) {
24
+ return {
25
+ content: [{
26
+ type: "text",
27
+ mimeType: "text/plain",
28
+ text: `Search API error: ${formatError(error)}`
29
+ }],
30
+ isError: true
31
+ };
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { isValidSitemapArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the sitemap tool
8
+ */
9
+ export async function handleSitemap(args) {
10
+ if (!isValidSitemapArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid sitemap arguments");
12
+ }
13
+ try {
14
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.SITEMAP, args);
15
+ return {
16
+ content: [{
17
+ type: "text",
18
+ mimeType: "application/json",
19
+ text: JSON.stringify(response.links, null, 2)
20
+ }]
21
+ };
22
+ }
23
+ catch (error) {
24
+ return {
25
+ content: [{
26
+ type: "text",
27
+ mimeType: "text/plain",
28
+ text: `Sitemap API error: ${formatError(error)}`
29
+ }],
30
+ isError: true
31
+ };
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { isValidTrendingArgs } from '../types.js';
2
+ import { makeRequest } from '../api.js';
3
+ import { formatError } from '../utils.js';
4
+ import { API_CONFIG } from '../config.js';
5
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
6
+ /**
7
+ * Implementation of the trending tool
8
+ */
9
+ export async function handleTrending(args) {
10
+ if (!isValidTrendingArgs(args)) {
11
+ throw new McpError(ErrorCode.InvalidParams, "Invalid trending arguments");
12
+ }
13
+ try {
14
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.TRENDING, args);
15
+ return {
16
+ content: [{
17
+ type: "text",
18
+ mimeType: "application/json",
19
+ text: JSON.stringify(response.results, null, 2)
20
+ }]
21
+ };
22
+ }
23
+ catch (error) {
24
+ return {
25
+ content: [{
26
+ type: "text",
27
+ mimeType: "text/plain",
28
+ text: `Trending API error: ${formatError(error)}`
29
+ }],
30
+ isError: true
31
+ };
32
+ }
33
+ }
package/build/types.js CHANGED
@@ -124,3 +124,25 @@ export function isValidReasoningArgs(args) {
124
124
  }
125
125
  return true;
126
126
  }
127
+ export var TrendingService;
128
+ (function (TrendingService) {
129
+ TrendingService["GITHUB"] = "github";
130
+ TrendingService["HACKERNEWS"] = "hackernews";
131
+ })(TrendingService || (TrendingService = {}));
132
+ export function isValidTrendingArgs(args) {
133
+ if (typeof args !== 'object' || args === null) {
134
+ return false;
135
+ }
136
+ const { search_service, max_results } = args;
137
+ if (search_service === undefined) {
138
+ return false;
139
+ }
140
+ const validServices = Object.values(TrendingService);
141
+ if (!validServices.includes(search_service)) {
142
+ return false;
143
+ }
144
+ if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) {
145
+ return false;
146
+ }
147
+ return true;
148
+ }
package/build/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Logging utility function
3
+ */
4
+ export function log(message, ...args) {
5
+ const timestamp = new Date().toISOString();
6
+ console.error(`[${timestamp}] ${message}`, ...args);
7
+ }
8
+ /**
9
+ * Error formatting utility function
10
+ */
11
+ export function formatError(error) {
12
+ if (error instanceof Error) {
13
+ return error.message;
14
+ }
15
+ return String(error);
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A Model Context Protocol (MCP) server that provides search and crawl functionality using Search1API",
5
5
  "private": false,
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "inspector": "npx @modelcontextprotocol/inspector build/index.js"
18
18
  },
19
19
  "dependencies": {
20
- "@modelcontextprotocol/sdk": "0.6.0",
20
+ "@modelcontextprotocol/sdk": "^1.7.0",
21
21
  "axios": "^1.7.8",
22
22
  "dotenv": "^16.4.5"
23
23
  },