search1api-mcp 0.1.0
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 +39 -0
- package/build/index.js +154 -0
- package/build/types.js +16 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Search1API MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides search functionality using Search1API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Web search functionality through Search1API
|
|
8
|
+
- Seamless integration with Claude Desktop
|
|
9
|
+
|
|
10
|
+
## Setup Guide
|
|
11
|
+
|
|
12
|
+
### 1. Get Search1API Key
|
|
13
|
+
1. Register at [Search1API](https://www.search1api.com/)
|
|
14
|
+
2. Choose a pricing plan (starts from $0.99)
|
|
15
|
+
3. After payment, copy your API key from the confirmation email
|
|
16
|
+
|
|
17
|
+
### 2. Configure Claude Desktop
|
|
18
|
+
Update your Claude configuration file (`claude_desktop_config.json`) with the following content:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"search1api": {
|
|
24
|
+
"command": "search1api-mcp",
|
|
25
|
+
"env": {
|
|
26
|
+
"SEARCH1API_KEY": "your search1api key"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Configuration file location:
|
|
34
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
35
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
package/build/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
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 axios from "axios";
|
|
6
|
+
import dotenv from "dotenv";
|
|
7
|
+
import { isValidSearchArgs } from "./types.js";
|
|
8
|
+
dotenv.config();
|
|
9
|
+
const API_KEY = process.env.SEARCH1API_KEY;
|
|
10
|
+
if (!API_KEY) {
|
|
11
|
+
throw new Error("SEARCH1API_KEY environment variable is required");
|
|
12
|
+
}
|
|
13
|
+
const API_CONFIG = {
|
|
14
|
+
BASE_URL: 'https://api.search1api.com',
|
|
15
|
+
DEFAULT_QUERY: 'latest news in the world',
|
|
16
|
+
ENDPOINTS: {
|
|
17
|
+
SEARCH: 'search'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
class SearchServer {
|
|
21
|
+
server;
|
|
22
|
+
axiosInstance;
|
|
23
|
+
constructor() {
|
|
24
|
+
this.server = new Server({
|
|
25
|
+
name: "search1api-mcp",
|
|
26
|
+
version: "0.1.0"
|
|
27
|
+
}, {
|
|
28
|
+
capabilities: {
|
|
29
|
+
resources: {},
|
|
30
|
+
tools: {}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Configure axios with defaults
|
|
34
|
+
this.axiosInstance = axios.create({
|
|
35
|
+
baseURL: API_CONFIG.BASE_URL,
|
|
36
|
+
headers: {
|
|
37
|
+
'Authorization': `Bearer ${API_KEY}`,
|
|
38
|
+
'Content-Type': 'application/json'
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
this.setupHandlers();
|
|
42
|
+
this.setupErrorHandling();
|
|
43
|
+
}
|
|
44
|
+
setupErrorHandling() {
|
|
45
|
+
this.server.onerror = (error) => {
|
|
46
|
+
console.error("[MCP Error]", error);
|
|
47
|
+
};
|
|
48
|
+
process.on('SIGINT', async () => {
|
|
49
|
+
await this.server.close();
|
|
50
|
+
process.exit(0);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
setupHandlers() {
|
|
54
|
+
this.setupResourceHandlers();
|
|
55
|
+
this.setupToolHandlers();
|
|
56
|
+
}
|
|
57
|
+
setupResourceHandlers() {
|
|
58
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
59
|
+
resources: [{
|
|
60
|
+
uri: `search://${encodeURIComponent(API_CONFIG.DEFAULT_QUERY)}`,
|
|
61
|
+
name: `Search results for "${API_CONFIG.DEFAULT_QUERY}"`,
|
|
62
|
+
mimeType: "application/json",
|
|
63
|
+
description: "Search results including title, link, and snippet"
|
|
64
|
+
}]
|
|
65
|
+
}));
|
|
66
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
67
|
+
const defaultQuery = API_CONFIG.DEFAULT_QUERY;
|
|
68
|
+
if (request.params.uri !== `search://${encodeURIComponent(defaultQuery)}`) {
|
|
69
|
+
throw new McpError(ErrorCode.InvalidRequest, `Unknown resource: ${request.params.uri}`);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const response = await this.axiosInstance.post(API_CONFIG.ENDPOINTS.SEARCH, {
|
|
73
|
+
query: defaultQuery,
|
|
74
|
+
search_service: "google",
|
|
75
|
+
max_results: 10
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
contents: [{
|
|
79
|
+
uri: request.params.uri,
|
|
80
|
+
mimeType: "application/json",
|
|
81
|
+
text: JSON.stringify(response.data.results, null, 2)
|
|
82
|
+
}]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (axios.isAxiosError(error)) {
|
|
87
|
+
throw new McpError(ErrorCode.InternalError, `Search API error: ${error.response?.data?.message ?? error.message}`);
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
setupToolHandlers() {
|
|
94
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
95
|
+
tools: [{
|
|
96
|
+
name: "search1api",
|
|
97
|
+
description: "Search for information using Search1API service",
|
|
98
|
+
inputSchema: {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: {
|
|
101
|
+
query: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "Search query"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
required: ["query"]
|
|
107
|
+
}
|
|
108
|
+
}]
|
|
109
|
+
}));
|
|
110
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
111
|
+
if (request.params.name !== "search1api") {
|
|
112
|
+
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
|
|
113
|
+
}
|
|
114
|
+
if (!isValidSearchArgs(request.params.arguments)) {
|
|
115
|
+
throw new McpError(ErrorCode.InvalidParams, "Invalid search arguments");
|
|
116
|
+
}
|
|
117
|
+
const { query, max_results = 10, search_service = "google" } = request.params.arguments;
|
|
118
|
+
try {
|
|
119
|
+
const response = await this.axiosInstance.post(API_CONFIG.ENDPOINTS.SEARCH, {
|
|
120
|
+
query,
|
|
121
|
+
search_service,
|
|
122
|
+
max_results
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
content: [{
|
|
126
|
+
type: "text",
|
|
127
|
+
mimeType: "application/json",
|
|
128
|
+
text: JSON.stringify(response.data.results, null, 2)
|
|
129
|
+
}]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (axios.isAxiosError(error)) {
|
|
134
|
+
return {
|
|
135
|
+
content: [{
|
|
136
|
+
type: "text",
|
|
137
|
+
mimeType: "text/plain",
|
|
138
|
+
text: `Search API error: ${error.response?.data?.message ?? error.message}`
|
|
139
|
+
}],
|
|
140
|
+
isError: true
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async run() {
|
|
148
|
+
const transport = new StdioServerTransport();
|
|
149
|
+
await this.server.connect(transport);
|
|
150
|
+
console.error("Search1API MCP server running on stdio");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const server = new SearchServer();
|
|
154
|
+
server.run().catch(console.error);
|
package/build/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isValidSearchArgs(args) {
|
|
2
|
+
if (typeof args !== 'object' || args === null) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const { query, max_results, search_service } = args;
|
|
6
|
+
if (typeof query !== 'string' || query.trim().length === 0) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (search_service !== undefined && typeof search_service !== 'string') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "search1api-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Model Context Protocol (MCP) server that provides search functionality using Search1API",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"search1api-mcp": "./build/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"build"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"watch": "tsc --watch",
|
|
17
|
+
"inspector": "npx @modelcontextprotocol/inspector build/index.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@modelcontextprotocol/sdk": "0.6.0",
|
|
21
|
+
"axios": "^1.7.8",
|
|
22
|
+
"dotenv": "^16.4.5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.11.24",
|
|
26
|
+
"typescript": "^5.3.3"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mcp",
|
|
30
|
+
"claude",
|
|
31
|
+
"search",
|
|
32
|
+
"search1api"
|
|
33
|
+
],
|
|
34
|
+
"author": "fatwang2",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/fatwang2/search1api-mcp"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|