search1api-mcp 0.3.0 → 0.4.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 +33 -18
- package/build/config.js +0 -1
- package/build/http.js +156 -41
- package/build/server.js +10 -6
- package/build/tools/crawl.js +12 -1
- package/build/tools/fetch.js +51 -0
- package/build/tools/handlers.js +4 -4
- package/build/tools/index.js +204 -69
- package/build/tools/news.js +13 -1
- package/build/tools/search.js +13 -1
- package/build/tools/sitemap.js +3 -1
- package/build/tools/trending.js +3 -1
- package/build/types.js +7 -10
- package/build/version.js +4 -0
- package/package.json +24 -13
- package/server.json +36 -0
- package/build/tools/reasoning.js +0 -51
package/README.md
CHANGED
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
[中文文档](./README_zh.md)
|
|
4
4
|
|
|
5
|
-
The official MCP server for [Search1API](https://www.search1api.com/?utm_source=mcp) — web search, news,
|
|
5
|
+
The official MCP server for [Search1API](https://www.search1api.com/?utm_source=mcp) — web search, news, page retrieval, sitemap discovery, and trending topics in one API.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Authentication
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
- OAuth-aware clients can connect to the Remote MCP URL directly, then sign in and approve access in the browser.
|
|
10
|
+
- Existing integrations can continue to use an API key from the [Search1API dashboard](https://dashboard.search1api.com).
|
|
11
11
|
|
|
12
12
|
## Quick Start (Remote MCP)
|
|
13
13
|
|
|
14
|
-
No installation required.
|
|
14
|
+
No installation required. Configure your MCP client with the remote URL. Use OAuth when the client supports it, or provide an API key.
|
|
15
15
|
|
|
16
16
|
### Authentication
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Three methods are supported — use whichever your client supports:
|
|
19
19
|
|
|
20
20
|
| Method | Format |
|
|
21
21
|
|--------|--------|
|
|
22
|
+
| OAuth 2.1 | Connect to `https://mcp.search1api.com/mcp` without a key and follow the client sign-in flow |
|
|
22
23
|
| Authorization Header | `Authorization: Bearer YOUR_SEARCH1API_KEY` |
|
|
23
|
-
| URL Query Parameter | `https://mcp.search1api.com/mcp?apiKey=YOUR_SEARCH1API_KEY` |
|
|
24
|
+
| URL Query Parameter (legacy) | `https://mcp.search1api.com/mcp?apiKey=YOUR_SEARCH1API_KEY` |
|
|
25
|
+
|
|
26
|
+
Prefer OAuth or the Authorization header. Query-parameter credentials can be exposed in URLs, logs, and shell history.
|
|
24
27
|
|
|
25
28
|
### Claude Desktop
|
|
26
29
|
|
|
@@ -95,6 +98,15 @@ claude mcp add --transport http search1api https://mcp.search1api.com/mcp \
|
|
|
95
98
|
}
|
|
96
99
|
```
|
|
97
100
|
|
|
101
|
+
## Agent Skill
|
|
102
|
+
|
|
103
|
+
The Agent Skill has moved to [search1api-cli](https://github.com/superagents-lab/search1api-cli). Install it with:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm install -g search1api-cli
|
|
107
|
+
npx skills add superagents-lab/search1api-cli
|
|
108
|
+
```
|
|
109
|
+
|
|
98
110
|
## Local Mode (stdio)
|
|
99
111
|
|
|
100
112
|
If you prefer to run the server locally, use npx — no cloning required:
|
|
@@ -116,18 +128,27 @@ If you prefer to run the server locally, use npx — no cloning required:
|
|
|
116
128
|
## Tools
|
|
117
129
|
|
|
118
130
|
### search
|
|
119
|
-
Search the web using Search1API.
|
|
131
|
+
Search the web using Search1API. Results use the standard citable
|
|
132
|
+
`id`/`title`/`url` shape expected by ChatGPT deep research and company
|
|
133
|
+
knowledge.
|
|
120
134
|
|
|
121
135
|
| Parameter | Required | Default | Description |
|
|
122
136
|
|-----------|----------|---------|-------------|
|
|
123
137
|
| `query` | Yes | - | Search query |
|
|
124
138
|
| `max_results` | No | 10 | Number of results |
|
|
125
139
|
| `search_service` | No | google | google, bing, duckduckgo, yahoo, x, reddit, github, youtube, arxiv, wechat, bilibili, imdb, wikipedia |
|
|
126
|
-
| `crawl_results` | No | 0 | Number of results to crawl for full content |
|
|
140
|
+
| `crawl_results` | No | 0 | Number of top results to crawl for full content; each successful crawl adds 1 credit to the base 1-credit search request |
|
|
127
141
|
| `include_sites` | No | [] | Sites to include |
|
|
128
142
|
| `exclude_sites` | No | [] | Sites to exclude |
|
|
129
143
|
| `time_range` | No | - | day, month, year |
|
|
130
144
|
|
|
145
|
+
### fetch
|
|
146
|
+
Retrieve the full readable contents of a result returned by `search`.
|
|
147
|
+
|
|
148
|
+
| Parameter | Required | Description |
|
|
149
|
+
|-----------|----------|-------------|
|
|
150
|
+
| `id` | Yes | Result ID returned by `search` (the canonical page URL) |
|
|
151
|
+
|
|
131
152
|
### news
|
|
132
153
|
Search for news articles.
|
|
133
154
|
|
|
@@ -136,7 +157,7 @@ Search for news articles.
|
|
|
136
157
|
| `query` | Yes | - | Search query |
|
|
137
158
|
| `max_results` | No | 10 | Number of results |
|
|
138
159
|
| `search_service` | No | bing | google, bing, duckduckgo, yahoo, hackernews |
|
|
139
|
-
| `crawl_results` | No | 0 | Number of results to crawl for full content |
|
|
160
|
+
| `crawl_results` | No | 0 | Number of top results to crawl for full content; each successful crawl adds 1 credit to the base 1-credit news request |
|
|
140
161
|
| `include_sites` | No | [] | Sites to include |
|
|
141
162
|
| `exclude_sites` | No | [] | Sites to exclude |
|
|
142
163
|
| `time_range` | No | - | day, month, year |
|
|
@@ -155,13 +176,6 @@ Get all related links from a URL.
|
|
|
155
176
|
|-----------|----------|-------------|
|
|
156
177
|
| `url` | Yes | URL to get sitemap |
|
|
157
178
|
|
|
158
|
-
### reasoning
|
|
159
|
-
Deep thinking and complex problem solving with DeepSeek R1.
|
|
160
|
-
|
|
161
|
-
| Parameter | Required | Description |
|
|
162
|
-
|-----------|----------|-------------|
|
|
163
|
-
| `content` | Yes | The question or problem |
|
|
164
|
-
|
|
165
179
|
### trending
|
|
166
180
|
Get trending topics from popular platforms.
|
|
167
181
|
|
|
@@ -172,13 +186,14 @@ Get trending topics from popular platforms.
|
|
|
172
186
|
|
|
173
187
|
## Version History
|
|
174
188
|
|
|
189
|
+
- v0.4.0: Standard `search`/`fetch` compatibility, structured output schemas, OAuth security schemes, safety annotations, and Official MCP Registry metadata
|
|
190
|
+
- v0.3.1: OAuth 2.1 support for Remote MCP; retired reasoning tool removed
|
|
175
191
|
- v0.3.0: Remote MCP support via Streamable HTTP; per-session API key authentication
|
|
176
192
|
- v0.2.0: Fallback `.env` support for LibreChat integration
|
|
177
193
|
- v0.1.8: X (Twitter) and Reddit search services
|
|
178
194
|
- v0.1.7: Trending tool for GitHub and Hacker News
|
|
179
195
|
- v0.1.6: Wikipedia search service
|
|
180
196
|
- v0.1.5: New search parameters and services (arxiv, wechat, bilibili, imdb)
|
|
181
|
-
- v0.1.4: Reasoning tool with DeepSeek R1
|
|
182
197
|
- v0.1.3: News search
|
|
183
198
|
- v0.1.2: Sitemap
|
|
184
199
|
- v0.1.1: Web crawling
|
package/build/config.js
CHANGED
package/build/http.js
CHANGED
|
@@ -1,65 +1,169 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import express from "express";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
3
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
|
+
import express from "express";
|
|
5
5
|
import { createMcpServer } from "./server.js";
|
|
6
6
|
import { log } from "./utils.js";
|
|
7
7
|
const app = express();
|
|
8
|
+
const API_BASE_URL = process.env.SEARCH1API_API_URL || "https://api.search1api.com";
|
|
9
|
+
const AUTHORIZATION_SERVER = "https://clerk.search1api.com";
|
|
10
|
+
const MCP_RESOURCE = "https://mcp.search1api.com/mcp";
|
|
11
|
+
const MCP_RESOURCE_METADATA = "https://mcp.search1api.com/.well-known/oauth-protected-resource/mcp";
|
|
12
|
+
// The service root is documentation, not an MCP transport endpoint. Keep
|
|
13
|
+
// query parameters so bookmarked campaign/support links remain attributable.
|
|
14
|
+
app.get("/", (req, res) => {
|
|
15
|
+
const target = new URL("https://www.search1api.com/docs/integrations/mcp");
|
|
16
|
+
for (const [key, value] of Object.entries(req.query)) {
|
|
17
|
+
if (typeof value === "string") {
|
|
18
|
+
target.searchParams.append(key, value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
res.redirect(301, target.toString());
|
|
22
|
+
});
|
|
23
|
+
const protectedResourceMetadata = {
|
|
24
|
+
resource: MCP_RESOURCE,
|
|
25
|
+
authorization_servers: [AUTHORIZATION_SERVER],
|
|
26
|
+
bearer_methods_supported: ["header"],
|
|
27
|
+
scopes_supported: ["openid", "offline_access"],
|
|
28
|
+
resource_documentation: "https://www.search1api.com/auth.md",
|
|
29
|
+
};
|
|
30
|
+
app.get([
|
|
31
|
+
"/.well-known/oauth-protected-resource",
|
|
32
|
+
"/.well-known/oauth-protected-resource/mcp",
|
|
33
|
+
], (_req, res) => {
|
|
34
|
+
res.type("application/json").json(protectedResourceMetadata);
|
|
35
|
+
});
|
|
36
|
+
app.get("/.well-known/oauth-authorization-server", (_req, res) => {
|
|
37
|
+
res.redirect(302, `${AUTHORIZATION_SERVER}/.well-known/oauth-authorization-server`);
|
|
38
|
+
});
|
|
8
39
|
app.use(express.json());
|
|
9
|
-
// Session storage: sessionId
|
|
40
|
+
// Session storage: sessionId -> MCP transport, server, and authenticated
|
|
41
|
+
// principal. The credential itself is mutable so a refreshed OAuth access
|
|
42
|
+
// token can continue the same session after it is validated.
|
|
10
43
|
const sessions = new Map();
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
function extractApiKey(req) {
|
|
15
|
-
// 1. Authorization: Bearer <key>
|
|
44
|
+
/** Extract a Bearer credential, retaining the legacy query-key fallback. */
|
|
45
|
+
function extractCredential(req) {
|
|
16
46
|
const auth = req.headers.authorization;
|
|
17
47
|
if (auth?.startsWith("Bearer ")) {
|
|
18
48
|
return auth.slice(7).trim() || undefined;
|
|
19
49
|
}
|
|
20
|
-
// 2. ?apiKey=<key>
|
|
21
50
|
const queryKey = req.query.apiKey;
|
|
22
51
|
if (typeof queryKey === "string" && queryKey.trim()) {
|
|
23
52
|
return queryKey.trim();
|
|
24
53
|
}
|
|
25
54
|
return undefined;
|
|
26
55
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
56
|
+
function challenge(res, message, error) {
|
|
57
|
+
const errorParameter = error ? `, error="${error}"` : "";
|
|
58
|
+
res.set("WWW-Authenticate", `Bearer resource_metadata="${MCP_RESOURCE_METADATA}"${errorParameter}`);
|
|
59
|
+
res.status(401).json({
|
|
60
|
+
jsonrpc: "2.0",
|
|
61
|
+
error: { code: -32001, message },
|
|
62
|
+
id: null,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Validate both Clerk OAuth tokens and legacy Search1API API keys at the API. */
|
|
66
|
+
async function validateCredential(credential) {
|
|
67
|
+
const response = await fetch(`${API_BASE_URL}/usage`, {
|
|
68
|
+
headers: { Authorization: `Bearer ${credential}` },
|
|
69
|
+
});
|
|
70
|
+
if (response.status === 401 || response.status === 403) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(`Search1API credential validation returned ${response.status}`);
|
|
75
|
+
}
|
|
76
|
+
const identity = (await response.json());
|
|
77
|
+
let principal;
|
|
78
|
+
if (identity.credential_type === "oauth" &&
|
|
79
|
+
identity.user_id &&
|
|
80
|
+
identity.client_id) {
|
|
81
|
+
principal = `oauth:${identity.user_id}:${identity.client_id}`;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
principal = `api-key:${createHash("sha256")
|
|
85
|
+
.update(credential)
|
|
86
|
+
.digest("hex")}`;
|
|
87
|
+
}
|
|
88
|
+
return { credential, principal };
|
|
89
|
+
}
|
|
90
|
+
async function authenticateMcpRequest(req, res, expectedPrincipal) {
|
|
91
|
+
const credential = extractCredential(req);
|
|
92
|
+
if (!credential) {
|
|
93
|
+
challenge(res, "Authentication is required. Use OAuth 2.1 discovery or provide a Search1API API key as a Bearer token.");
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
let authenticated;
|
|
97
|
+
try {
|
|
98
|
+
authenticated = await validateCredential(credential);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
log("Credential validation failed:", error);
|
|
102
|
+
res.status(503).json({
|
|
103
|
+
jsonrpc: "2.0",
|
|
104
|
+
error: {
|
|
105
|
+
code: -32002,
|
|
106
|
+
message: "Search1API authentication is temporarily unavailable.",
|
|
107
|
+
},
|
|
108
|
+
id: null,
|
|
109
|
+
});
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (!authenticated) {
|
|
113
|
+
challenge(res, "The Bearer credential is invalid or expired.", "invalid_token");
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
if (expectedPrincipal && authenticated.principal !== expectedPrincipal) {
|
|
117
|
+
res.status(403).json({
|
|
118
|
+
jsonrpc: "2.0",
|
|
119
|
+
error: {
|
|
120
|
+
code: -32003,
|
|
121
|
+
message: "The credential does not belong to this MCP session.",
|
|
122
|
+
},
|
|
123
|
+
id: null,
|
|
124
|
+
});
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return authenticated;
|
|
128
|
+
}
|
|
30
129
|
function isInitializeRequest(body) {
|
|
31
130
|
if (Array.isArray(body)) {
|
|
32
|
-
return body.some((
|
|
131
|
+
return body.some((message) => typeof message === "object" &&
|
|
132
|
+
message !== null &&
|
|
133
|
+
message.method === "initialize");
|
|
33
134
|
}
|
|
34
|
-
return typeof body === "object" &&
|
|
135
|
+
return (typeof body === "object" &&
|
|
136
|
+
body !== null &&
|
|
137
|
+
body.method === "initialize");
|
|
35
138
|
}
|
|
36
|
-
// Handle POST /mcp
|
|
139
|
+
// Handle POST /mcp - initialize or route to an existing session.
|
|
37
140
|
app.post("/mcp", async (req, res) => {
|
|
38
141
|
const sessionId = req.headers["mcp-session-id"];
|
|
39
|
-
// Route to existing session
|
|
40
142
|
if (sessionId && sessions.has(sessionId)) {
|
|
41
143
|
const session = sessions.get(sessionId);
|
|
144
|
+
const authenticated = await authenticateMcpRequest(req, res, session.principal);
|
|
145
|
+
if (!authenticated) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
session.credential.current = authenticated.credential;
|
|
42
149
|
await session.transport.handleRequest(req, res, req.body);
|
|
43
150
|
return;
|
|
44
151
|
}
|
|
45
|
-
// New session — must be an initialize request
|
|
46
152
|
if (!sessionId && isInitializeRequest(req.body)) {
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
res.status(401).json({
|
|
50
|
-
jsonrpc: "2.0",
|
|
51
|
-
error: {
|
|
52
|
-
code: -32001,
|
|
53
|
-
message: "API key is required. Pass it via 'Authorization: Bearer <key>' header or '?apiKey=<key>' query parameter.",
|
|
54
|
-
},
|
|
55
|
-
id: null,
|
|
56
|
-
});
|
|
153
|
+
const authenticated = await authenticateMcpRequest(req, res);
|
|
154
|
+
if (!authenticated) {
|
|
57
155
|
return;
|
|
58
156
|
}
|
|
157
|
+
const credential = { current: authenticated.credential };
|
|
59
158
|
const transport = new StreamableHTTPServerTransport({
|
|
60
159
|
sessionIdGenerator: () => randomUUID(),
|
|
61
160
|
onsessioninitialized: (sid) => {
|
|
62
|
-
sessions.set(sid, {
|
|
161
|
+
sessions.set(sid, {
|
|
162
|
+
transport,
|
|
163
|
+
server,
|
|
164
|
+
principal: authenticated.principal,
|
|
165
|
+
credential,
|
|
166
|
+
});
|
|
63
167
|
log(`Session created: ${sid}`);
|
|
64
168
|
},
|
|
65
169
|
});
|
|
@@ -69,18 +173,21 @@ app.post("/mcp", async (req, res) => {
|
|
|
69
173
|
log(`Session closed: ${transport.sessionId}`);
|
|
70
174
|
}
|
|
71
175
|
};
|
|
72
|
-
const server = createMcpServer(
|
|
176
|
+
const server = createMcpServer(() => credential.current);
|
|
73
177
|
await server.connect(transport);
|
|
74
178
|
await transport.handleRequest(req, res, req.body);
|
|
75
179
|
return;
|
|
76
180
|
}
|
|
77
181
|
res.status(400).json({
|
|
78
182
|
jsonrpc: "2.0",
|
|
79
|
-
error: {
|
|
183
|
+
error: {
|
|
184
|
+
code: -32600,
|
|
185
|
+
message: "Bad request: no valid session or not an initialize request",
|
|
186
|
+
},
|
|
80
187
|
id: null,
|
|
81
188
|
});
|
|
82
189
|
});
|
|
83
|
-
// Handle GET /mcp
|
|
190
|
+
// Handle GET /mcp - SSE stream for an existing session.
|
|
84
191
|
app.get("/mcp", async (req, res) => {
|
|
85
192
|
const sessionId = req.headers["mcp-session-id"];
|
|
86
193
|
if (!sessionId || !sessions.has(sessionId)) {
|
|
@@ -91,31 +198,39 @@ app.get("/mcp", async (req, res) => {
|
|
|
91
198
|
});
|
|
92
199
|
return;
|
|
93
200
|
}
|
|
94
|
-
|
|
201
|
+
const session = sessions.get(sessionId);
|
|
202
|
+
const authenticated = await authenticateMcpRequest(req, res, session.principal);
|
|
203
|
+
if (!authenticated) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
session.credential.current = authenticated.credential;
|
|
207
|
+
await session.transport.handleRequest(req, res);
|
|
95
208
|
});
|
|
96
|
-
// Handle DELETE /mcp
|
|
209
|
+
// Handle DELETE /mcp - authenticated session termination.
|
|
97
210
|
app.delete("/mcp", async (req, res) => {
|
|
98
211
|
const sessionId = req.headers["mcp-session-id"];
|
|
99
212
|
if (sessionId && sessions.has(sessionId)) {
|
|
100
213
|
const session = sessions.get(sessionId);
|
|
214
|
+
const authenticated = await authenticateMcpRequest(req, res, session.principal);
|
|
215
|
+
if (!authenticated) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
101
218
|
await session.transport.handleRequest(req, res);
|
|
102
219
|
await session.server.close();
|
|
103
220
|
sessions.delete(sessionId);
|
|
104
221
|
log(`Session terminated: ${sessionId}`);
|
|
222
|
+
return;
|
|
105
223
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
}
|
|
224
|
+
res.status(400).json({
|
|
225
|
+
jsonrpc: "2.0",
|
|
226
|
+
error: { code: -32600, message: "Invalid or missing session ID" },
|
|
227
|
+
id: null,
|
|
228
|
+
});
|
|
113
229
|
});
|
|
114
230
|
const PORT = parseInt(process.env.PORT || "3000", 10);
|
|
115
231
|
app.listen(PORT, () => {
|
|
116
232
|
log(`Search1API MCP HTTP server listening on http://localhost:${PORT}/mcp`);
|
|
117
233
|
});
|
|
118
|
-
// Handle global errors
|
|
119
234
|
process.on("uncaughtException", (error) => {
|
|
120
235
|
log("Uncaught exception:", error);
|
|
121
236
|
});
|
package/build/server.js
CHANGED
|
@@ -4,23 +4,26 @@ import { handleToolCall } from "./tools/handlers.js";
|
|
|
4
4
|
import { log, formatError } from "./utils.js";
|
|
5
5
|
import { handleListResources, handleReadResource } from "./resources.js";
|
|
6
6
|
import { ALL_TOOLS } from "./tools/index.js";
|
|
7
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
7
8
|
/**
|
|
8
9
|
* Create and configure MCP server
|
|
9
|
-
* @param
|
|
10
|
+
* @param credential Optional per-session credential or mutable credential
|
|
11
|
+
* provider (used in HTTP mode so refreshed OAuth tokens can replace expired
|
|
12
|
+
* access tokens without changing the MCP session principal)
|
|
10
13
|
* @returns Server instance ready to be connected to a transport
|
|
11
14
|
*/
|
|
12
|
-
export function createMcpServer(
|
|
15
|
+
export function createMcpServer(credential) {
|
|
13
16
|
log("Creating Search1API MCP server");
|
|
14
17
|
const server = new Server({
|
|
15
18
|
name: "search1api-server",
|
|
16
|
-
version:
|
|
19
|
+
version: PACKAGE_VERSION
|
|
17
20
|
}, {
|
|
18
21
|
capabilities: {
|
|
19
22
|
resources: {},
|
|
20
23
|
tools: {}
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
|
-
setupRequestHandlers(server,
|
|
26
|
+
setupRequestHandlers(server, credential);
|
|
24
27
|
return server;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
@@ -36,14 +39,15 @@ function handleError(context, error) {
|
|
|
36
39
|
/**
|
|
37
40
|
* Set up server request handlers
|
|
38
41
|
*/
|
|
39
|
-
function setupRequestHandlers(server,
|
|
42
|
+
function setupRequestHandlers(server, credential) {
|
|
40
43
|
// Handle tool calls
|
|
41
44
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
42
45
|
try {
|
|
43
46
|
const toolName = request.params.name;
|
|
44
47
|
const toolArgs = request.params.arguments;
|
|
45
48
|
log(`Tool call received: ${toolName}`);
|
|
46
|
-
|
|
49
|
+
const bearerCredential = typeof credential === "function" ? credential() : credential;
|
|
50
|
+
return await handleToolCall(toolName, toolArgs, bearerCredential);
|
|
47
51
|
}
|
|
48
52
|
catch (error) {
|
|
49
53
|
handleError("handling tool call", error);
|
package/build/tools/crawl.js
CHANGED
|
@@ -17,11 +17,22 @@ export async function handleCrawl(args, apiKey) {
|
|
|
17
17
|
const response = await makeRequest(API_CONFIG.ENDPOINTS.CRAWL, { url }, apiKey);
|
|
18
18
|
const endTime = Date.now();
|
|
19
19
|
log(`Crawl completed successfully in ${endTime - startTime}ms`);
|
|
20
|
+
const result = {
|
|
21
|
+
id: response.results.link || url,
|
|
22
|
+
title: response.results.title,
|
|
23
|
+
url: response.results.link || url,
|
|
24
|
+
text: response.results.content,
|
|
25
|
+
metadata: {
|
|
26
|
+
source: "search1api",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const structuredContent = { result };
|
|
20
30
|
return {
|
|
31
|
+
structuredContent,
|
|
21
32
|
content: [{
|
|
22
33
|
type: "text",
|
|
23
34
|
mimeType: "application/json",
|
|
24
|
-
text: JSON.stringify(
|
|
35
|
+
text: JSON.stringify(structuredContent)
|
|
25
36
|
}]
|
|
26
37
|
};
|
|
27
38
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { makeRequest } from "../api.js";
|
|
3
|
+
import { API_CONFIG } from "../config.js";
|
|
4
|
+
import { isValidFetchArgs, } from "../types.js";
|
|
5
|
+
import { formatError, log } from "../utils.js";
|
|
6
|
+
/**
|
|
7
|
+
* ChatGPT-compatible fetch implementation. Search result IDs are canonical
|
|
8
|
+
* URLs, so fetch can pass the ID directly to the crawl endpoint.
|
|
9
|
+
*/
|
|
10
|
+
export async function handleFetch(args, apiKey) {
|
|
11
|
+
if (!isValidFetchArgs(args)) {
|
|
12
|
+
throw new McpError(ErrorCode.InvalidParams, "Invalid fetch arguments");
|
|
13
|
+
}
|
|
14
|
+
const { id } = args;
|
|
15
|
+
log("Fetching search result:", id);
|
|
16
|
+
try {
|
|
17
|
+
const response = await makeRequest(API_CONFIG.ENDPOINTS.CRAWL, { url: id }, apiKey);
|
|
18
|
+
const result = {
|
|
19
|
+
id,
|
|
20
|
+
title: response.results.title,
|
|
21
|
+
text: response.results.content,
|
|
22
|
+
url: response.results.link || id,
|
|
23
|
+
metadata: {
|
|
24
|
+
source: "search1api",
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
structuredContent: result,
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: "text",
|
|
32
|
+
mimeType: "application/json",
|
|
33
|
+
text: JSON.stringify(result),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
log("Fetch error:", error);
|
|
40
|
+
return {
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
mimeType: "text/plain",
|
|
45
|
+
text: `Fetch API error: ${formatError(error)}`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
isError: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
package/build/tools/handlers.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import { log } from '../utils.js';
|
|
3
3
|
import { handleSearch } from './search.js';
|
|
4
|
+
import { handleFetch } from './fetch.js';
|
|
4
5
|
import { handleCrawl } from './crawl.js';
|
|
5
6
|
import { handleSitemap } from './sitemap.js';
|
|
6
7
|
import { handleNews } from './news.js';
|
|
7
|
-
import { handleReasoning } from './reasoning.js';
|
|
8
8
|
import { handleTrending } from './trending.js';
|
|
9
|
-
import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL,
|
|
9
|
+
import { SEARCH_TOOL, FETCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL } from './index.js';
|
|
10
10
|
/**
|
|
11
11
|
* Dispatch request based on tool name
|
|
12
12
|
* @param toolName Name of the tool
|
|
@@ -19,14 +19,14 @@ export async function handleToolCall(toolName, args, apiKey) {
|
|
|
19
19
|
switch (toolName) {
|
|
20
20
|
case SEARCH_TOOL.name:
|
|
21
21
|
return await handleSearch(args, apiKey);
|
|
22
|
+
case FETCH_TOOL.name:
|
|
23
|
+
return await handleFetch(args, apiKey);
|
|
22
24
|
case CRAWL_TOOL.name:
|
|
23
25
|
return await handleCrawl(args, apiKey);
|
|
24
26
|
case SITEMAP_TOOL.name:
|
|
25
27
|
return await handleSitemap(args, apiKey);
|
|
26
28
|
case NEWS_TOOL.name:
|
|
27
29
|
return await handleNews(args, apiKey);
|
|
28
|
-
case REASONING_TOOL.name:
|
|
29
|
-
return await handleReasoning(args, apiKey);
|
|
30
30
|
case TRENDING_TOOL.name:
|
|
31
31
|
return await handleTrending(args, apiKey);
|
|
32
32
|
default:
|
package/build/tools/index.js
CHANGED
|
@@ -1,180 +1,315 @@
|
|
|
1
|
+
const AUTHENTICATED_READ_ONLY_WEB = {
|
|
2
|
+
securitySchemes: [
|
|
3
|
+
{
|
|
4
|
+
type: "oauth2",
|
|
5
|
+
scopes: ["openid", "offline_access"],
|
|
6
|
+
},
|
|
7
|
+
],
|
|
8
|
+
_meta: {
|
|
9
|
+
securitySchemes: [
|
|
10
|
+
{
|
|
11
|
+
type: "oauth2",
|
|
12
|
+
scopes: ["openid", "offline_access"],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
destructiveHint: false,
|
|
19
|
+
openWorldHint: true,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const CITABLE_RESULT_SCHEMA = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
id: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Stable identifier for this result; for web results this is the canonical URL",
|
|
28
|
+
},
|
|
29
|
+
title: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Human-readable result title",
|
|
32
|
+
},
|
|
33
|
+
url: {
|
|
34
|
+
type: "string",
|
|
35
|
+
format: "uri",
|
|
36
|
+
description: "Canonical URL that clients can cite and users can open",
|
|
37
|
+
},
|
|
38
|
+
text: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Result snippet or extracted page text when available",
|
|
41
|
+
},
|
|
42
|
+
metadata: {
|
|
43
|
+
type: "object",
|
|
44
|
+
description: "Additional source metadata",
|
|
45
|
+
additionalProperties: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
required: ["id", "title", "url"],
|
|
49
|
+
};
|
|
50
|
+
const SEARCH_OUTPUT_SCHEMA = {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
results: {
|
|
54
|
+
type: "array",
|
|
55
|
+
items: CITABLE_RESULT_SCHEMA,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["results"],
|
|
59
|
+
};
|
|
60
|
+
const FETCH_OUTPUT_SCHEMA = {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
id: { type: "string" },
|
|
64
|
+
title: { type: "string" },
|
|
65
|
+
text: { type: "string" },
|
|
66
|
+
url: { type: "string", format: "uri" },
|
|
67
|
+
metadata: {
|
|
68
|
+
type: "object",
|
|
69
|
+
additionalProperties: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
required: ["id", "title", "text", "url"],
|
|
73
|
+
};
|
|
1
74
|
// Search tool definition
|
|
2
75
|
export const SEARCH_TOOL = {
|
|
3
76
|
name: "search",
|
|
4
|
-
|
|
77
|
+
title: "Search the web",
|
|
78
|
+
description: "Search the live public web when the user needs current information, sources, or research. Returns citable results with id, title, URL, and text. Pass a result id to fetch to retrieve the full page.",
|
|
79
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
5
80
|
inputSchema: {
|
|
6
81
|
type: "object",
|
|
7
82
|
properties: {
|
|
8
83
|
query: {
|
|
9
84
|
type: "string",
|
|
10
|
-
description: "
|
|
85
|
+
description: "Short, focused search query",
|
|
11
86
|
},
|
|
12
87
|
max_results: {
|
|
13
88
|
type: "number",
|
|
89
|
+
minimum: 1,
|
|
90
|
+
maximum: 50,
|
|
14
91
|
description: "Maximum number of results to return",
|
|
15
|
-
default: 10
|
|
92
|
+
default: 10,
|
|
16
93
|
},
|
|
17
94
|
search_service: {
|
|
18
95
|
type: "string",
|
|
19
|
-
description: "
|
|
96
|
+
description: "Search engine to use; choose one only when it matches the user's source intent",
|
|
20
97
|
default: "google",
|
|
21
|
-
enum: ["google", "bing", "duckduckgo", "yahoo", "x", "reddit", "github", "youtube", "arxiv", "wechat", "bilibili", "imdb", "wikipedia"]
|
|
98
|
+
enum: ["google", "bing", "duckduckgo", "yahoo", "x", "reddit", "github", "youtube", "arxiv", "wechat", "bilibili", "imdb", "wikipedia"],
|
|
22
99
|
},
|
|
23
100
|
crawl_results: {
|
|
24
101
|
type: "number",
|
|
25
|
-
|
|
26
|
-
|
|
102
|
+
minimum: 0,
|
|
103
|
+
description: "Number of top results to retrieve as full pages. Each successful page retrieval adds 1 credit to the base 1-credit search request",
|
|
104
|
+
default: 0,
|
|
27
105
|
},
|
|
28
106
|
include_sites: {
|
|
29
107
|
type: "array",
|
|
30
108
|
items: {
|
|
31
|
-
type: "string"
|
|
109
|
+
type: "string",
|
|
32
110
|
},
|
|
33
|
-
description: "
|
|
34
|
-
default: []
|
|
111
|
+
description: "Domains to include when the user explicitly scopes the search",
|
|
112
|
+
default: [],
|
|
35
113
|
},
|
|
36
114
|
exclude_sites: {
|
|
37
115
|
type: "array",
|
|
38
116
|
items: {
|
|
39
|
-
type: "string"
|
|
117
|
+
type: "string",
|
|
40
118
|
},
|
|
41
|
-
description: "
|
|
42
|
-
default: []
|
|
119
|
+
description: "Domains to exclude from the search",
|
|
120
|
+
default: [],
|
|
43
121
|
},
|
|
44
122
|
time_range: {
|
|
45
123
|
type: "string",
|
|
46
|
-
description: "
|
|
47
|
-
enum: ["day", "month", "year"]
|
|
48
|
-
}
|
|
124
|
+
description: "Optional recency window for time-sensitive searches",
|
|
125
|
+
enum: ["day", "month", "year"],
|
|
126
|
+
},
|
|
49
127
|
},
|
|
50
|
-
required: ["query"]
|
|
51
|
-
}
|
|
128
|
+
required: ["query"],
|
|
129
|
+
},
|
|
130
|
+
outputSchema: SEARCH_OUTPUT_SCHEMA,
|
|
131
|
+
};
|
|
132
|
+
// Fetch tool definition for ChatGPT deep research and company knowledge.
|
|
133
|
+
export const FETCH_TOOL = {
|
|
134
|
+
name: "fetch",
|
|
135
|
+
title: "Fetch a search result",
|
|
136
|
+
description: "Retrieve the full readable contents of a result returned by search. Pass the result id, which is the canonical page URL. Returns id, title, full text, URL, and metadata.",
|
|
137
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
138
|
+
inputSchema: {
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: {
|
|
141
|
+
id: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "Result id returned by search; for web results this is the canonical URL",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
required: ["id"],
|
|
147
|
+
},
|
|
148
|
+
outputSchema: FETCH_OUTPUT_SCHEMA,
|
|
52
149
|
};
|
|
53
150
|
// News tool definition
|
|
54
151
|
export const NEWS_TOOL = {
|
|
55
152
|
name: "news",
|
|
56
|
-
|
|
153
|
+
title: "Search current news",
|
|
154
|
+
description: "Search current news when the user asks about recent events, announcements, or coverage. Returns citable article results with title, URL, snippet, and optional extracted text.",
|
|
155
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
57
156
|
inputSchema: {
|
|
58
157
|
type: "object",
|
|
59
158
|
properties: {
|
|
60
159
|
query: {
|
|
61
160
|
type: "string",
|
|
62
|
-
description: "
|
|
161
|
+
description: "Short, focused news query",
|
|
63
162
|
},
|
|
64
163
|
max_results: {
|
|
65
164
|
type: "number",
|
|
66
|
-
|
|
67
|
-
|
|
165
|
+
minimum: 1,
|
|
166
|
+
maximum: 50,
|
|
167
|
+
description: "Maximum number of articles to return",
|
|
168
|
+
default: 10,
|
|
68
169
|
},
|
|
69
170
|
search_service: {
|
|
70
171
|
type: "string",
|
|
71
|
-
description: "
|
|
172
|
+
description: "News search engine to use",
|
|
72
173
|
default: "bing",
|
|
73
|
-
enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"]
|
|
174
|
+
enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"],
|
|
74
175
|
},
|
|
75
176
|
crawl_results: {
|
|
76
177
|
type: "number",
|
|
77
|
-
|
|
78
|
-
|
|
178
|
+
minimum: 0,
|
|
179
|
+
description: "Number of top articles to retrieve as full pages. Each successful retrieval adds 1 credit to the base 1-credit news request",
|
|
180
|
+
default: 0,
|
|
79
181
|
},
|
|
80
182
|
include_sites: {
|
|
81
183
|
type: "array",
|
|
82
184
|
items: {
|
|
83
|
-
type: "string"
|
|
185
|
+
type: "string",
|
|
84
186
|
},
|
|
85
|
-
description: "
|
|
86
|
-
default: []
|
|
187
|
+
description: "News domains to include",
|
|
188
|
+
default: [],
|
|
87
189
|
},
|
|
88
190
|
exclude_sites: {
|
|
89
191
|
type: "array",
|
|
90
192
|
items: {
|
|
91
|
-
type: "string"
|
|
193
|
+
type: "string",
|
|
92
194
|
},
|
|
93
|
-
description: "
|
|
94
|
-
default: []
|
|
195
|
+
description: "News domains to exclude",
|
|
196
|
+
default: [],
|
|
95
197
|
},
|
|
96
198
|
time_range: {
|
|
97
199
|
type: "string",
|
|
98
|
-
description: "
|
|
99
|
-
enum: ["day", "month", "year"]
|
|
100
|
-
}
|
|
200
|
+
description: "Optional recency window; use day for breaking news",
|
|
201
|
+
enum: ["day", "month", "year"],
|
|
202
|
+
},
|
|
101
203
|
},
|
|
102
|
-
required: ["query"]
|
|
103
|
-
}
|
|
204
|
+
required: ["query"],
|
|
205
|
+
},
|
|
206
|
+
outputSchema: SEARCH_OUTPUT_SCHEMA,
|
|
104
207
|
};
|
|
105
208
|
// Crawl tool definition
|
|
106
209
|
export const CRAWL_TOOL = {
|
|
107
210
|
name: "crawl",
|
|
108
|
-
|
|
211
|
+
title: "Read a web page",
|
|
212
|
+
description: "Extract the readable title and full text from a specific public URL supplied by the user. Use fetch instead when following a result returned by search.",
|
|
213
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
109
214
|
inputSchema: {
|
|
110
215
|
type: "object",
|
|
111
216
|
properties: {
|
|
112
217
|
url: {
|
|
113
218
|
type: "string",
|
|
114
|
-
|
|
115
|
-
|
|
219
|
+
format: "uri",
|
|
220
|
+
description: "Public HTTP or HTTPS URL to retrieve",
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
required: ["url"],
|
|
224
|
+
},
|
|
225
|
+
outputSchema: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
result: CITABLE_RESULT_SCHEMA,
|
|
116
229
|
},
|
|
117
|
-
required: ["
|
|
118
|
-
}
|
|
230
|
+
required: ["result"],
|
|
231
|
+
},
|
|
119
232
|
};
|
|
120
233
|
// Sitemap tool definition
|
|
121
234
|
export const SITEMAP_TOOL = {
|
|
122
235
|
name: "sitemap",
|
|
123
|
-
|
|
236
|
+
title: "Discover links on a site",
|
|
237
|
+
description: "Discover related public links from a page or domain when the user wants to explore a site's structure or available pages.",
|
|
238
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
124
239
|
inputSchema: {
|
|
125
240
|
type: "object",
|
|
126
241
|
properties: {
|
|
127
242
|
url: {
|
|
128
243
|
type: "string",
|
|
129
|
-
|
|
130
|
-
|
|
244
|
+
format: "uri",
|
|
245
|
+
description: "Public page or domain URL whose links should be discovered",
|
|
246
|
+
},
|
|
131
247
|
},
|
|
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: {
|
|
248
|
+
required: ["url"],
|
|
249
|
+
},
|
|
250
|
+
outputSchema: {
|
|
140
251
|
type: "object",
|
|
141
252
|
properties: {
|
|
142
|
-
|
|
143
|
-
type: "
|
|
144
|
-
|
|
145
|
-
|
|
253
|
+
links: {
|
|
254
|
+
type: "array",
|
|
255
|
+
items: {
|
|
256
|
+
type: "string",
|
|
257
|
+
format: "uri",
|
|
258
|
+
},
|
|
259
|
+
},
|
|
146
260
|
},
|
|
147
|
-
required: ["
|
|
148
|
-
}
|
|
261
|
+
required: ["links"],
|
|
262
|
+
},
|
|
149
263
|
};
|
|
150
264
|
// Trending tool definition
|
|
151
265
|
export const TRENDING_TOOL = {
|
|
152
266
|
name: "trending",
|
|
153
|
-
|
|
267
|
+
title: "Explore trending topics",
|
|
268
|
+
description: "List currently trending repositories or stories from GitHub or Hacker News when the user asks what is popular now.",
|
|
269
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
154
270
|
inputSchema: {
|
|
155
271
|
type: "object",
|
|
156
272
|
properties: {
|
|
157
273
|
search_service: {
|
|
158
274
|
type: "string",
|
|
159
|
-
description: "
|
|
275
|
+
description: "Platform whose trending items should be returned",
|
|
160
276
|
enum: ["github", "hackernews"],
|
|
161
|
-
default: "github"
|
|
277
|
+
default: "github",
|
|
162
278
|
},
|
|
163
279
|
max_results: {
|
|
164
280
|
type: "number",
|
|
281
|
+
minimum: 1,
|
|
282
|
+
maximum: 50,
|
|
165
283
|
description: "Maximum number of trending items to return",
|
|
166
|
-
default: 10
|
|
167
|
-
}
|
|
284
|
+
default: 10,
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
required: ["search_service"],
|
|
288
|
+
},
|
|
289
|
+
outputSchema: {
|
|
290
|
+
type: "object",
|
|
291
|
+
properties: {
|
|
292
|
+
results: {
|
|
293
|
+
type: "array",
|
|
294
|
+
items: {
|
|
295
|
+
type: "object",
|
|
296
|
+
properties: {
|
|
297
|
+
title: { type: "string" },
|
|
298
|
+
url: { type: "string", format: "uri" },
|
|
299
|
+
description: { type: "string" },
|
|
300
|
+
},
|
|
301
|
+
required: ["title", "url"],
|
|
302
|
+
},
|
|
303
|
+
},
|
|
168
304
|
},
|
|
169
|
-
required: ["
|
|
170
|
-
}
|
|
305
|
+
required: ["results"],
|
|
306
|
+
},
|
|
171
307
|
};
|
|
172
|
-
// Export all tools
|
|
173
308
|
export const ALL_TOOLS = [
|
|
174
309
|
SEARCH_TOOL,
|
|
310
|
+
FETCH_TOOL,
|
|
175
311
|
NEWS_TOOL,
|
|
176
312
|
CRAWL_TOOL,
|
|
177
313
|
SITEMAP_TOOL,
|
|
178
|
-
|
|
179
|
-
TRENDING_TOOL
|
|
314
|
+
TRENDING_TOOL,
|
|
180
315
|
];
|
package/build/tools/news.js
CHANGED
|
@@ -13,11 +13,23 @@ export async function handleNews(args, apiKey) {
|
|
|
13
13
|
log("Processing news search with query:", args.query);
|
|
14
14
|
try {
|
|
15
15
|
const response = await makeRequest(API_CONFIG.ENDPOINTS.NEWS, args, apiKey);
|
|
16
|
+
const results = response.results.map((result) => ({
|
|
17
|
+
id: result.link,
|
|
18
|
+
title: result.title,
|
|
19
|
+
url: result.link,
|
|
20
|
+
text: result.content || result.snippet,
|
|
21
|
+
metadata: {
|
|
22
|
+
snippet: result.snippet,
|
|
23
|
+
...(result.content ? { has_full_content: true } : {}),
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
const structuredContent = { results };
|
|
16
27
|
return {
|
|
28
|
+
structuredContent,
|
|
17
29
|
content: [{
|
|
18
30
|
type: "text",
|
|
19
31
|
mimeType: "application/json",
|
|
20
|
-
text: JSON.stringify(
|
|
32
|
+
text: JSON.stringify(structuredContent)
|
|
21
33
|
}]
|
|
22
34
|
};
|
|
23
35
|
}
|
package/build/tools/search.js
CHANGED
|
@@ -12,11 +12,23 @@ export async function handleSearch(args, apiKey) {
|
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
14
|
const response = await makeRequest(API_CONFIG.ENDPOINTS.SEARCH, args, apiKey);
|
|
15
|
+
const results = response.results.map((result) => ({
|
|
16
|
+
id: result.link,
|
|
17
|
+
title: result.title,
|
|
18
|
+
url: result.link,
|
|
19
|
+
text: result.content || result.snippet,
|
|
20
|
+
metadata: {
|
|
21
|
+
snippet: result.snippet,
|
|
22
|
+
...(result.content ? { has_full_content: true } : {}),
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
const structuredContent = { results };
|
|
15
26
|
return {
|
|
27
|
+
structuredContent,
|
|
16
28
|
content: [{
|
|
17
29
|
type: "text",
|
|
18
30
|
mimeType: "application/json",
|
|
19
|
-
text: JSON.stringify(
|
|
31
|
+
text: JSON.stringify(structuredContent)
|
|
20
32
|
}]
|
|
21
33
|
};
|
|
22
34
|
}
|
package/build/tools/sitemap.js
CHANGED
|
@@ -12,11 +12,13 @@ export async function handleSitemap(args, apiKey) {
|
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
14
|
const response = await makeRequest(API_CONFIG.ENDPOINTS.SITEMAP, args, apiKey);
|
|
15
|
+
const structuredContent = { links: response.links };
|
|
15
16
|
return {
|
|
17
|
+
structuredContent,
|
|
16
18
|
content: [{
|
|
17
19
|
type: "text",
|
|
18
20
|
mimeType: "application/json",
|
|
19
|
-
text: JSON.stringify(
|
|
21
|
+
text: JSON.stringify(structuredContent)
|
|
20
22
|
}]
|
|
21
23
|
};
|
|
22
24
|
}
|
package/build/tools/trending.js
CHANGED
|
@@ -12,11 +12,13 @@ export async function handleTrending(args, apiKey) {
|
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
14
|
const response = await makeRequest(API_CONFIG.ENDPOINTS.TRENDING, args, apiKey);
|
|
15
|
+
const structuredContent = { results: response.results };
|
|
15
16
|
return {
|
|
17
|
+
structuredContent,
|
|
16
18
|
content: [{
|
|
17
19
|
type: "text",
|
|
18
20
|
mimeType: "application/json",
|
|
19
|
-
text: JSON.stringify(
|
|
21
|
+
text: JSON.stringify(structuredContent)
|
|
20
22
|
}]
|
|
21
23
|
};
|
|
22
24
|
}
|
package/build/types.js
CHANGED
|
@@ -62,6 +62,13 @@ export function isValidSearchArgs(args) {
|
|
|
62
62
|
}
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
|
+
export function isValidFetchArgs(args) {
|
|
66
|
+
if (typeof args !== "object" || args === null) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const { id } = args;
|
|
70
|
+
return typeof id === "string" && id.trim().length > 0;
|
|
71
|
+
}
|
|
65
72
|
export function isValidCrawlArgs(args) {
|
|
66
73
|
if (typeof args !== 'object' || args === null) {
|
|
67
74
|
return false;
|
|
@@ -116,16 +123,6 @@ export function isValidNewsArgs(args) {
|
|
|
116
123
|
}
|
|
117
124
|
return true;
|
|
118
125
|
}
|
|
119
|
-
export function isValidReasoningArgs(args) {
|
|
120
|
-
if (typeof args !== 'object' || args === null) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
const { content } = args;
|
|
124
|
-
if (typeof content !== 'string' || content.trim().length === 0) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
126
|
export var TrendingService;
|
|
130
127
|
(function (TrendingService) {
|
|
131
128
|
TrendingService["GITHUB"] = "github";
|
package/build/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "search1api-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"mcpName": "io.github.superagents-lab/search1api",
|
|
4
5
|
"description": "A Model Context Protocol (MCP) server that provides search and crawl functionality using Search1API",
|
|
5
6
|
"private": false,
|
|
6
7
|
"type": "module",
|
|
@@ -8,25 +9,28 @@
|
|
|
8
9
|
"search1api-mcp": "build/index.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
|
-
"build"
|
|
12
|
+
"build",
|
|
13
|
+
"server.json"
|
|
12
14
|
],
|
|
13
15
|
"scripts": {
|
|
14
|
-
"build": "
|
|
16
|
+
"build": "node -e \"require('node:fs').rmSync('build', { recursive: true, force: true })\" && tsc && node -e \"require('node:fs').chmodSync('build/index.js', '755')\"",
|
|
17
|
+
"test": "npm run build && node --test tests/*.test.mjs",
|
|
15
18
|
"start": "node build/http.js",
|
|
16
|
-
"
|
|
19
|
+
"prepack": "npm run build",
|
|
17
20
|
"watch": "tsc --watch",
|
|
18
21
|
"inspector": "npx @modelcontextprotocol/inspector build/index.js",
|
|
19
|
-
"start:http": "node build/http.js"
|
|
22
|
+
"start:http": "node build/http.js",
|
|
23
|
+
"sync:manifest": "npm run build && node scripts/sync-lobe-manifest.mjs"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
23
|
-
"dotenv": "^16.
|
|
24
|
-
"express": "^4.
|
|
26
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
27
|
+
"dotenv": "^16.6.1",
|
|
28
|
+
"express": "^4.22.2"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
27
|
-
"@types/express": "^5.0.
|
|
28
|
-
"@types/node": "^20.
|
|
29
|
-
"typescript": "^5.
|
|
31
|
+
"@types/express": "^5.0.6",
|
|
32
|
+
"@types/node": "^20.19.43",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
30
34
|
},
|
|
31
35
|
"keywords": [
|
|
32
36
|
"mcp",
|
|
@@ -36,11 +40,18 @@
|
|
|
36
40
|
"google",
|
|
37
41
|
"search1api"
|
|
38
42
|
],
|
|
39
|
-
"author": "
|
|
43
|
+
"author": "Search1API",
|
|
40
44
|
"license": "MIT",
|
|
41
45
|
"repository": {
|
|
42
46
|
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/superagents-lab/search1api-mcp.git"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/superagents-lab/search1api-mcp#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/superagents-lab/search1api-mcp/issues"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
44
55
|
},
|
|
45
56
|
"engines": {
|
|
46
57
|
"node": ">=18.0.0"
|
package/server.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.superagents-lab/search1api",
|
|
4
|
+
"title": "Search1API",
|
|
5
|
+
"description": "Web search, news, page retrieval, sitemaps, and trending topics through Search1API.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/superagents-lab/search1api-mcp",
|
|
8
|
+
"source": "github"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.4.0",
|
|
11
|
+
"remotes": [
|
|
12
|
+
{
|
|
13
|
+
"type": "streamable-http",
|
|
14
|
+
"url": "https://mcp.search1api.com/mcp"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"packages": [
|
|
18
|
+
{
|
|
19
|
+
"registryType": "npm",
|
|
20
|
+
"identifier": "search1api-mcp",
|
|
21
|
+
"version": "0.4.0",
|
|
22
|
+
"transport": {
|
|
23
|
+
"type": "stdio"
|
|
24
|
+
},
|
|
25
|
+
"environmentVariables": [
|
|
26
|
+
{
|
|
27
|
+
"name": "SEARCH1API_KEY",
|
|
28
|
+
"description": "Search1API API key for local stdio mode",
|
|
29
|
+
"isRequired": true,
|
|
30
|
+
"isSecret": true,
|
|
31
|
+
"format": "string"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
package/build/tools/reasoning.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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, apiKey) {
|
|
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
|
-
// Convert to API required format
|
|
17
|
-
const apiRequestData = {
|
|
18
|
-
model: "deepseek-r1-70b-fast-online",
|
|
19
|
-
messages: [
|
|
20
|
-
{
|
|
21
|
-
role: "user",
|
|
22
|
-
content: content
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
stream: false
|
|
26
|
-
};
|
|
27
|
-
const response = await makeRequest(API_CONFIG.ENDPOINTS.REASONING, apiRequestData, apiKey);
|
|
28
|
-
// Directly use the correct structure of ReasoningResponse
|
|
29
|
-
const resultText = response.choices && response.choices.length > 0
|
|
30
|
-
? response.choices[0].message.content
|
|
31
|
-
: JSON.stringify(response);
|
|
32
|
-
return {
|
|
33
|
-
content: [{
|
|
34
|
-
type: "text",
|
|
35
|
-
mimeType: "text/plain",
|
|
36
|
-
text: resultText
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
log("Reasoning API error:", error);
|
|
42
|
-
return {
|
|
43
|
-
content: [{
|
|
44
|
-
type: "text",
|
|
45
|
-
mimeType: "text/plain",
|
|
46
|
-
text: `Reasoning API error: ${formatError(error)}`
|
|
47
|
-
}],
|
|
48
|
-
isError: true
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|