search1api-mcp 0.1.1 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 fatwang2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,12 +2,16 @@
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
8
- - Web page content extraction (crawling)
10
+ - Web search functionality
11
+ - News search functionality
12
+ - Web page content extraction
13
+ - Website sitemap extraction
9
14
  - Seamless integration with Claude Desktop
10
- - Support for Google search engine
11
15
 
12
16
  ## Tools
13
17
 
@@ -19,12 +23,26 @@ A Model Context Protocol (MCP) server that provides search and crawl functionali
19
23
  * `max_results` (optional, default: 10): Number of results to return
20
24
  * `search_service` (optional, default: "google"): Search service to use
21
25
 
22
- ### 2. Crawl Tool
26
+ ### 2. News Tool
27
+ - Name: `news`
28
+ - Description: Search for news articles using Search1API
29
+ - Parameters:
30
+ * `query` (required): Search query
31
+ * `max_results` (optional, default: 10): Number of results to return
32
+ * `search_service` (optional, default: "google"): Search service to use
33
+
34
+ ### 3. Crawl Tool
23
35
  - Name: `crawl`
24
36
  - Description: Extract content from a URL using Search1API
25
37
  - Parameters:
26
38
  * `url` (required): URL to crawl
27
39
 
40
+ ### 4. Sitemap Tool
41
+ - Name: `sitemap`
42
+ - Description: Get all related links from a URL
43
+ - Parameters:
44
+ * `url` (required): URL to get sitemap
45
+
28
46
  ## Setup Guide
29
47
 
30
48
  ### 1. Get Search1API Key
@@ -55,6 +73,8 @@ Configuration file location:
55
73
 
56
74
  ## Version History
57
75
 
76
+ - v0.1.3: Added news search functionality
77
+ - v0.1.2: Added sitemap functionality
58
78
  - v0.1.1: Added web crawling functionality
59
79
  - v0.1.0: Initial release with search functionality
60
80
 
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 } 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) {
@@ -14,7 +14,9 @@ const API_CONFIG = {
14
14
  DEFAULT_QUERY: 'latest news in the world',
15
15
  ENDPOINTS: {
16
16
  SEARCH: '/search',
17
- CRAWL: '/crawl'
17
+ CRAWL: '/crawl',
18
+ SITEMAP: '/sitemap',
19
+ NEWS: '/news'
18
20
  }
19
21
  };
20
22
  const SEARCH_TOOL = {
@@ -41,9 +43,33 @@ const SEARCH_TOOL = {
41
43
  required: ["query"]
42
44
  }
43
45
  };
46
+ const NEWS_TOOL = {
47
+ name: "news",
48
+ description: "Search for news articles",
49
+ inputSchema: {
50
+ type: "object",
51
+ properties: {
52
+ query: {
53
+ type: "string",
54
+ description: "News search query"
55
+ },
56
+ max_results: {
57
+ type: "number",
58
+ description: "Maximum number of results to return (default: 10)",
59
+ default: 10
60
+ },
61
+ search_service: {
62
+ type: "string",
63
+ description: "Search service to use (default: google)",
64
+ default: "google"
65
+ }
66
+ },
67
+ required: ["query"]
68
+ }
69
+ };
44
70
  const CRAWL_TOOL = {
45
71
  name: "crawl",
46
- description: "Crawl and extract content from a specific URL",
72
+ description: "Extract content from URL",
47
73
  inputSchema: {
48
74
  type: "object",
49
75
  properties: {
@@ -55,14 +81,43 @@ const CRAWL_TOOL = {
55
81
  required: ["url"]
56
82
  }
57
83
  };
84
+ const SITEMAP_TOOL = {
85
+ name: "sitemap",
86
+ description: "Get all related links from a URL",
87
+ inputSchema: {
88
+ type: "object",
89
+ properties: {
90
+ url: {
91
+ type: "string",
92
+ description: "URL to get sitemap"
93
+ }
94
+ },
95
+ required: ["url"]
96
+ }
97
+ };
58
98
  // Server implementation
59
99
  const server = new Server({
60
100
  name: "search1api-mcp",
61
- version: "0.1.0",
101
+ version: "0.1.3",
62
102
  }, {
63
103
  capabilities: {
64
- resources: {},
65
- tools: {},
104
+ resources: {
105
+ supportedTypes: ["application/json", "text/plain"],
106
+ },
107
+ tools: {
108
+ search: {
109
+ description: "Search functionality"
110
+ },
111
+ news: {
112
+ description: "News search functionality"
113
+ },
114
+ crawl: {
115
+ description: "Web crawling functionality"
116
+ },
117
+ sitemap: {
118
+ description: "Sitemap extraction functionality"
119
+ }
120
+ },
66
121
  },
67
122
  });
68
123
  // 添加服务器事件监听
@@ -167,7 +222,7 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
167
222
  });
168
223
  // Tool handlers
169
224
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
170
- tools: [SEARCH_TOOL, CRAWL_TOOL],
225
+ tools: [SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL],
171
226
  }));
172
227
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
173
228
  try {
@@ -225,6 +280,42 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
225
280
  };
226
281
  }
227
282
  }
283
+ case "sitemap": {
284
+ if (!isValidSitemapArgs(args)) {
285
+ throw new McpError(ErrorCode.InvalidParams, "Invalid sitemap arguments");
286
+ }
287
+ try {
288
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.SITEMAP, args);
289
+ return {
290
+ content: [{
291
+ type: "text",
292
+ mimeType: "application/json",
293
+ text: JSON.stringify(response.links, null, 2)
294
+ }]
295
+ };
296
+ }
297
+ catch (error) {
298
+ throw formatError(error);
299
+ }
300
+ }
301
+ case "news": {
302
+ if (!isValidNewsArgs(args)) {
303
+ throw new McpError(ErrorCode.InvalidParams, "Invalid news arguments");
304
+ }
305
+ const { query, max_results = 10, search_service = "google" } = args;
306
+ const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, {
307
+ query,
308
+ search_service,
309
+ max_results
310
+ });
311
+ return {
312
+ content: [{
313
+ type: "text",
314
+ mimeType: "application/json",
315
+ text: JSON.stringify(response.results, null, 2)
316
+ }]
317
+ };
318
+ }
228
319
  default:
229
320
  throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
230
321
  }
package/build/types.js CHANGED
@@ -24,3 +24,29 @@ export function isValidCrawlArgs(args) {
24
24
  }
25
25
  return true;
26
26
  }
27
+ export function isValidSitemapArgs(args) {
28
+ if (typeof args !== 'object' || args === null) {
29
+ return false;
30
+ }
31
+ const { url } = args;
32
+ if (typeof url !== 'string' || url.trim().length === 0) {
33
+ return false;
34
+ }
35
+ return true;
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
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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"