search1api-mcp 0.1.2 → 0.1.4

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
@@ -2,12 +2,17 @@
2
2
 
3
3
  A Model Context Protocol (MCP) server that provides search and crawl functionality using Search1API.
4
4
 
5
+ https://github.com/user-attachments/assets/58bc98ae-3b6b-442c-a7fc-010508b5f028
6
+
7
+
5
8
  ## Features
6
9
 
7
- - Web search functionality through Search1API
10
+ - Web search functionality
11
+ - News search functionality
8
12
  - Web page content extraction
9
13
  - Website sitemap extraction
10
- - Seamless integration with Claude Desktop
14
+ - Deep thinking and complex problem solving with DeepSeek R1
15
+ - Seamless integration with Claude Desktop, Cursor and Windsurf
11
16
 
12
17
  ## Tools
13
18
 
@@ -19,26 +24,40 @@ A Model Context Protocol (MCP) server that provides search and crawl functionali
19
24
  * `max_results` (optional, default: 10): Number of results to return
20
25
  * `search_service` (optional, default: "google"): Search service to use
21
26
 
22
- ### 2. Crawl Tool
27
+ ### 2. News Tool
28
+ - Name: `news`
29
+ - Description: Search for news articles using Search1API
30
+ - Parameters:
31
+ * `query` (required): Search query
32
+ * `max_results` (optional, default: 10): Number of results to return
33
+ * `search_service` (optional, default: "google"): Search service to use
34
+
35
+ ### 3. Crawl Tool
23
36
  - Name: `crawl`
24
37
  - Description: Extract content from a URL using Search1API
25
38
  - Parameters:
26
39
  * `url` (required): URL to crawl
27
40
 
28
- ### 3. Sitemap Tool
41
+ ### 4. Sitemap Tool
29
42
  - Name: `sitemap`
30
43
  - Description: Get all related links from a URL
31
44
  - Parameters:
32
45
  * `url` (required): URL to get sitemap
33
46
 
47
+ ### 5. Reasoning Tool
48
+ - Name: `reasoning`
49
+ - Description: A tool for deep thinking and complex problem solving with fast deepseek r1 model and web search ability(You can change to any other model in search1api website but the speed is not guaranteed)
50
+ - Parameters:
51
+ * `content` (required): The question or problem that needs deep thinking
52
+
34
53
  ## Setup Guide
35
54
 
36
55
  ### 1. Get Search1API Key
37
- 1. Register at [Search1API](https://www.search1api.com/)
38
- 2. Choose a pricing plan (starts from $0.99)
39
- 3. After payment, copy your API key from the confirmation email
56
+ 1. Register at [Search1API](https://www.search1api.com/?utm_source=mcp)
57
+ 2. Get your api key and 100 free credits
40
58
 
41
- ### 2. Configure Claude Desktop
59
+ ### 2. Configure
60
+ #### 2.1 Claude Desktop
42
61
  Update your Claude configuration file (`claude_desktop_config.json`) with the following content:
43
62
 
44
63
  ```json
@@ -59,8 +78,37 @@ Configuration file location:
59
78
  - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
60
79
  - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
61
80
 
81
+ #### 2.2 Cursor
82
+ 1. Copy the run.template.sh to your file path and rename it to run.sh
83
+ 2. Add your own Search1API key to the run.sh file
84
+ 3. Open Cursor Settings to add new MCP server `search1api` with the command `sh ./your_file_path/run.sh`
85
+
86
+ Read the Cursor MCP Server [Official Documentation](https://docs.cursor.com/context/model-context-protocol#adding-an-mcp-server-to-cursor) to get more information.
87
+
88
+ #### 2.3 Windsurf
89
+ Update your Windsurf configuration file (`mcp_config.json`) with the following content:
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "search1api": {
95
+ "command": "npx",
96
+ "args": ["-y", "search1api-mcp"],
97
+ "env": {
98
+ "SEARCH1API_KEY": "YOUR_SEARCH1API_KEY"
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ```
104
+ Read the Windsurf MCP Server [Official Documentation](https://docs.codeium.com/windsurf/mcp) to get more information.
105
+
106
+ **Notice: After the configuration is done, you can close Windsurf offcial web tools to save your credits**
107
+
62
108
  ## Version History
63
109
 
110
+ - v0.1.4: Added reasoning tool with deepseek r1 and updated the Cursor and Windsurf configuration guide
111
+ - v0.1.3: Added news search functionality
64
112
  - v0.1.2: Added sitemap functionality
65
113
  - v0.1.1: Added web crawling functionality
66
114
  - v0.1.0: Initial release with search functionality
package/build/index.js CHANGED
@@ -3,7 +3,7 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
5
5
  import dotenv from "dotenv";
6
- import { isValidSearchArgs, isValidCrawlArgs, isValidSitemapArgs } from "./types.js";
6
+ import { isValidSearchArgs, isValidCrawlArgs, isValidSitemapArgs, isValidNewsArgs } from "./types.js";
7
7
  dotenv.config();
8
8
  const API_KEY = process.env.SEARCH1API_KEY;
9
9
  if (!API_KEY) {
@@ -15,12 +15,14 @@ const API_CONFIG = {
15
15
  ENDPOINTS: {
16
16
  SEARCH: '/search',
17
17
  CRAWL: '/crawl',
18
- SITEMAP: '/sitemap'
18
+ SITEMAP: '/sitemap',
19
+ NEWS: '/news',
20
+ REASONING: '/v1/chat/completions'
19
21
  }
20
22
  };
21
23
  const SEARCH_TOOL = {
22
24
  name: "search",
23
- description: "A fast way to search the world",
25
+ description: "Search the web for real-time results",
24
26
  inputSchema: {
25
27
  type: "object",
26
28
  properties: {
@@ -42,6 +44,30 @@ const SEARCH_TOOL = {
42
44
  required: ["query"]
43
45
  }
44
46
  };
47
+ const NEWS_TOOL = {
48
+ name: "news",
49
+ description: "Search for news articles",
50
+ inputSchema: {
51
+ type: "object",
52
+ properties: {
53
+ query: {
54
+ type: "string",
55
+ description: "News search query"
56
+ },
57
+ max_results: {
58
+ type: "number",
59
+ description: "Maximum number of results to return (default: 10)",
60
+ default: 10
61
+ },
62
+ search_service: {
63
+ type: "string",
64
+ description: "Search service to use (default: google)",
65
+ default: "google"
66
+ }
67
+ },
68
+ required: ["query"]
69
+ }
70
+ };
45
71
  const CRAWL_TOOL = {
46
72
  name: "crawl",
47
73
  description: "Extract content from URL",
@@ -70,70 +96,87 @@ const SITEMAP_TOOL = {
70
96
  required: ["url"]
71
97
  }
72
98
  };
99
+ const REASONING_TOOL = {
100
+ name: "reasoning",
101
+ description: "Deep thinking and complex problem solving",
102
+ inputSchema: {
103
+ type: "object",
104
+ properties: {
105
+ content: {
106
+ type: "string",
107
+ description: "The question or problem that needs deep thinking"
108
+ }
109
+ },
110
+ required: ["content"]
111
+ }
112
+ };
73
113
  // Server implementation
74
114
  const server = new Server({
75
115
  name: "search1api-mcp",
76
- version: "0.1.0",
116
+ version: "0.1.3",
77
117
  }, {
78
118
  capabilities: {
79
- resources: {},
80
- tools: {},
119
+ resources: {
120
+ supportedTypes: ["application/json", "text/plain"],
121
+ },
122
+ tools: {
123
+ search: {
124
+ description: "Search functionality"
125
+ },
126
+ news: {
127
+ description: "News search functionality"
128
+ },
129
+ crawl: {
130
+ description: "Web crawling functionality"
131
+ },
132
+ sitemap: {
133
+ description: "Sitemap extraction functionality"
134
+ },
135
+ reasoning: {
136
+ description: "Deep thinking and complex problem solving"
137
+ }
138
+ },
81
139
  },
82
140
  });
83
- // 添加服务器事件监听
141
+ // Add server event listeners
84
142
  server.onerror = (error) => {
85
143
  log('MCP Server Error:', error);
86
144
  };
87
145
  server.onclose = () => {
88
146
  log('MCP Server Connection Closed');
89
147
  };
90
- // 添加异步请求函数
148
+ // Add asynchronous request function
91
149
  async function makeRequest(endpoint, data) {
92
150
  const startTime = Date.now();
93
- // 确保 BASE_URL 末尾没有斜杠,endpoint 开头有斜杠
151
+ // Ensure BASE_URL has no trailing slash and endpoint starts with slash
94
152
  const baseUrl = API_CONFIG.BASE_URL.replace(/\/+$/, '');
95
153
  const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
96
154
  const url = `${baseUrl}${path}`;
97
- log(`Starting request to ${url}`);
98
155
  try {
99
- const controller = new AbortController();
100
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 seconds timeout
101
156
  const response = await fetch(url, {
102
157
  method: 'POST',
103
158
  headers: {
104
159
  'Authorization': `Bearer ${API_KEY}`,
105
160
  'Content-Type': 'application/json',
106
161
  },
107
- body: JSON.stringify(data),
108
- signal: controller.signal
162
+ body: JSON.stringify(data)
109
163
  });
110
- clearTimeout(timeoutId);
111
164
  if (!response.ok) {
112
165
  const errorData = await response.json().catch(() => ({}));
113
166
  throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
114
167
  }
115
168
  const result = await response.json();
116
- const endTime = Date.now();
117
- log(`Request completed in ${endTime - startTime}ms`);
169
+ const duration = Date.now() - startTime;
170
+ log(`API request to ${endpoint} completed in ${duration}ms`);
118
171
  return result;
119
172
  }
120
173
  catch (error) {
121
- const endTime = Date.now();
122
- log(`Request failed after ${endTime - startTime}ms:`, error);
123
- if (error instanceof Error) {
124
- if (error.name === 'AbortError') {
125
- throw new Error('Request timeout after 30 seconds');
126
- }
127
- // 添加更多网络错误的详细信息
128
- const networkError = error;
129
- if (networkError.code) {
130
- throw new Error(`Network error (${networkError.code}): ${networkError.message}`);
131
- }
132
- }
174
+ const duration = Date.now() - startTime;
175
+ log(`API request to ${endpoint} failed after ${duration}ms:`, error);
133
176
  throw error;
134
177
  }
135
178
  }
136
- // 添加错误处理工具函数
179
+ // Add error handling utility function
137
180
  function formatError(error) {
138
181
  if (error instanceof Error) {
139
182
  return error.message;
@@ -182,7 +225,7 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
182
225
  });
183
226
  // Tool handlers
184
227
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
185
- tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL],
228
+ tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL],
186
229
  }));
187
230
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
188
231
  try {
@@ -258,6 +301,59 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
258
301
  throw formatError(error);
259
302
  }
260
303
  }
304
+ case "news": {
305
+ if (!isValidNewsArgs(args)) {
306
+ throw new McpError(ErrorCode.InvalidParams, "Invalid news arguments");
307
+ }
308
+ const { query, max_results = 10, search_service = "google" } = args;
309
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, {
310
+ query,
311
+ search_service,
312
+ max_results
313
+ });
314
+ return {
315
+ content: [{
316
+ type: "text",
317
+ mimeType: "application/json",
318
+ text: JSON.stringify(response.results, null, 2)
319
+ }]
320
+ };
321
+ }
322
+ case "reasoning": {
323
+ if (!args) {
324
+ throw new Error("No arguments provided");
325
+ }
326
+ const { content } = args;
327
+ const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.REASONING}`, {
328
+ method: 'POST',
329
+ headers: {
330
+ 'Authorization': `Bearer ${API_KEY}`,
331
+ 'Content-Type': 'application/json',
332
+ },
333
+ body: JSON.stringify({
334
+ model: "deepseek-r1-70b-fast-online",
335
+ messages: [
336
+ {
337
+ role: "user",
338
+ content: content
339
+ }
340
+ ],
341
+ stream: false
342
+ })
343
+ });
344
+ if (!response.ok) {
345
+ const errorData = await response.json().catch(() => ({}));
346
+ throw new Error(`API error: ${response.status} ${errorData.message || response.statusText}`);
347
+ }
348
+ const result = await response.json();
349
+ return {
350
+ content: [{
351
+ type: "text",
352
+ mimeType: "application/json",
353
+ text: JSON.stringify(result.choices[0].message)
354
+ }]
355
+ };
356
+ }
261
357
  default:
262
358
  throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
263
359
  }
@@ -274,7 +370,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
274
370
  };
275
371
  }
276
372
  });
277
- // 添加日志工具函数
373
+ // Add logging utility function
278
374
  function log(message, ...args) {
279
375
  const timestamp = new Date().toISOString();
280
376
  console.error(`[${timestamp}] ${message}`, ...args);
@@ -282,7 +378,7 @@ function log(message, ...args) {
282
378
  async function runServer() {
283
379
  const transport = new StdioServerTransport();
284
380
  log("Starting Search1API MCP Server...");
285
- // 添加全局错误处理
381
+ // Add global error handling
286
382
  process.on('uncaughtException', (error) => {
287
383
  log('Uncaught Exception:', error);
288
384
  });
package/build/types.js CHANGED
@@ -34,3 +34,29 @@ export function isValidSitemapArgs(args) {
34
34
  }
35
35
  return true;
36
36
  }
37
+ export function isValidNewsArgs(args) {
38
+ if (typeof args !== 'object' || args === null) {
39
+ return false;
40
+ }
41
+ const { query, max_results, search_service } = args;
42
+ if (typeof query !== 'string' || query.trim().length === 0) {
43
+ return false;
44
+ }
45
+ if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) {
46
+ return false;
47
+ }
48
+ if (search_service !== undefined && typeof search_service !== 'string') {
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+ export function isValidReasoningArgs(args) {
54
+ if (typeof args !== 'object' || args === null) {
55
+ return false;
56
+ }
57
+ const { content } = args;
58
+ if (typeof content !== 'string' || content.trim().length === 0) {
59
+ return false;
60
+ }
61
+ return true;
62
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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",
7
7
  "bin": {
8
- "search1api-mcp": "./build/index.js"
8
+ "search1api-mcp": "build/index.js"
9
9
  },
10
10
  "files": [
11
11
  "build"
@@ -37,7 +37,7 @@
37
37
  "license": "MIT",
38
38
  "repository": {
39
39
  "type": "git",
40
- "url": "https://github.com/fatwang2/search1api-mcp"
40
+ "url": "git+https://github.com/fatwang2/search1api-mcp.git"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=18.0.0"