search1api-mcp 0.7.1 → 0.9.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/LICENSE +3 -0
- package/README.md +29 -4
- package/THIRD_PARTY_NOTICES.md +42 -0
- package/assets/icon-square.png +0 -0
- package/build/branding.js +13 -0
- package/build/config.js +3 -0
- package/build/feedback.js +31 -0
- package/build/http.js +123 -7
- package/build/server.js +54 -2
- package/build/setup-page.js +50 -0
- package/build/tools/handlers.js +4 -1
- package/build/tools/index.js +62 -24
- package/build/tools/render-results.js +193 -0
- package/build/ui.js +71 -0
- package/docs/example-input.json +11 -0
- package/docs/example-output.json +21 -0
- package/docs/input.schema.json +62 -0
- package/docs/mcp-ui.md +70 -0
- package/docs/output.schema.json +69 -0
- package/docs/render-results.md +71 -0
- package/package.json +16 -7
- package/server.json +11 -2
- package/ui/dist/index.html +174 -0
package/LICENSE
CHANGED
|
@@ -19,3 +19,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Third-party exception: the Rare UI search component is governed by the terms in
|
|
24
|
+
THIRD_PARTY_NOTICES.md, which are included with this distribution.
|
package/README.md
CHANGED
|
@@ -29,6 +29,16 @@ Three methods are supported — use whichever your client supports:
|
|
|
29
29
|
|
|
30
30
|
Prefer OAuth or the Authorization header. Query-parameter credentials can be exposed in URLs, logs, and shell history.
|
|
31
31
|
|
|
32
|
+
### Optional search and news UI
|
|
33
|
+
|
|
34
|
+
Remote MCP exposes `render_results` at the standard endpoint above. Data tools such as `search`, `news` and `ask` return results without automatically showing cards. When a source list helps, the model can select or combine existing results and pass them to `render_results`. It returns source cards in MCP Apps clients and a complete readable text list elsewhere. Rendering does not repeat a search or consume search credits; no UI URL parameter is required.
|
|
35
|
+
|
|
36
|
+
Both HTTP and stdio advertise the square Search1API logo through standard `serverInfo.icons` metadata. The 512×512 PNG is served publicly at `https://mcp.search1api.com/assets/icon-square.png`, without authentication or redirects. The server card and registry manifest use the same icon. Clients choose whether to display it; this does not replace an icon stored separately by a plugin directory.
|
|
37
|
+
|
|
38
|
+
See [the rendering contract](docs/render-results.md) for arguments, limits and fallback behavior. The npm package includes this renderer from version 0.8.0. Update existing installations and restart the MCP connection; `npx -y search1api-mcp@latest` starts the latest published package.
|
|
39
|
+
|
|
40
|
+
After changing the URL, reconnect or refresh the connector's tool definitions; clients may cache them. This URL setting applies to Remote MCP only; local stdio behavior is unchanged. See [MCP Apps UI](docs/mcp-ui.md) for details and release status.
|
|
41
|
+
|
|
32
42
|
### Claude Desktop
|
|
33
43
|
|
|
34
44
|
```json
|
|
@@ -46,11 +56,9 @@ Prefer OAuth or the Authorization header. Query-parameter credentials can be exp
|
|
|
46
56
|
|
|
47
57
|
### Claude.ai (Web)
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
Install Search1API from the [Claude directory](https://claude.ai/directory/search1api), click **Connect**, and sign in with your Search1API account.
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
https://mcp.search1api.com/mcp?apiKey=YOUR_SEARCH1API_KEY
|
|
53
|
-
```
|
|
61
|
+
Avoid adding `https://mcp.search1api.com/mcp` through **Add custom connector**: that creates a separate custom connector, which Claude names after the URL's host (`mcp.search1api.com`) unless you type a name.
|
|
54
62
|
|
|
55
63
|
### Cursor
|
|
56
64
|
|
|
@@ -203,6 +211,17 @@ Agentic search: describe the need in natural language and Search1API picks up to
|
|
|
203
211
|
|-----------|----------|-------------|
|
|
204
212
|
| `query` | Yes | The request in natural language, up to 500 characters |
|
|
205
213
|
|
|
214
|
+
### send_feedback
|
|
215
|
+
Report a wrong, empty or incomplete result, an error you could not resolve, documentation that did not match behavior, or a missing capability to the Search1API team. Free; it spends no credits. When the server has a Search1API credential, the report is linked to that account so the team can follow up. Do not include credentials or private data.
|
|
216
|
+
|
|
217
|
+
| Parameter | Required | Description |
|
|
218
|
+
|-----------|----------|-------------|
|
|
219
|
+
| `message` | Yes | What went wrong or what was missing, up to 4000 characters |
|
|
220
|
+
| `intent` | No | What you were trying to accomplish |
|
|
221
|
+
| `category` | No | bug, feature_request, docs, other |
|
|
222
|
+
| `request_id` | No | Request id of the call that had the problem |
|
|
223
|
+
| `model` | No | Your model name |
|
|
224
|
+
|
|
206
225
|
## Version History
|
|
207
226
|
|
|
208
227
|
- v0.7.0: New `ask` tool for agentic search. `search` adds the `bingcn`, `yandex`, and `grokipedia` engines and a `page` parameter; `search` and `news` accept `time_range: "week"` and pass `published_date`, GitHub, and Hacker News fields through in result `metadata`
|
|
@@ -230,3 +249,9 @@ Agentic search: describe the need in natural language and Search1API picks up to
|
|
|
230
249
|
## License
|
|
231
250
|
|
|
232
251
|
MIT
|
|
252
|
+
|
|
253
|
+
## UI and third-party credits
|
|
254
|
+
|
|
255
|
+
The `render_results` MCP Apps view shows existing sources as cards with titles and domains. Every client also receives the full text and structured result list. The component is adapted from [Rare UI](https://rareui.com), by Swami Malode. Its MIT + Commons Clause + Attribution terms are reproduced in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
256
|
+
|
|
257
|
+
UI setup, sandbox origin, and release checks: [MCP Apps UI](docs/mcp-ui.md).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The search-result component is adapted from [Rare UI](https://rareui.com),
|
|
4
|
+
by Swami Malode: https://github.com/swamimalode07/rare-ui/blob/main/components/ui/web-search.tsx.
|
|
5
|
+
Modifications include MCP Apps integration, source expansion, host sizing, and animation controls.
|
|
6
|
+
This component retains the following license; it is not relicensed under the project MIT license.
|
|
7
|
+
|
|
8
|
+
MIT + Commons Clause License Condition v1.0 + Attribution
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 Swami Malode
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
13
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
14
|
+
the Software without restriction, including without limitation the rights to
|
|
15
|
+
use, copy, modify, merge, publish, and distribute the Software as part of an
|
|
16
|
+
application, website, or product, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
Attribution Requirement
|
|
22
|
+
|
|
23
|
+
Any project that ships any part of the Software must credit Rare UI with a
|
|
24
|
+
visible link to https://rareui.com, placed where a visitor or user can find it,
|
|
25
|
+
such as a site footer, an about page, a credits screen or a README. The credit
|
|
26
|
+
and the copyright notice above must not be removed from the source you copied.
|
|
27
|
+
|
|
28
|
+
Commons Clause Restriction
|
|
29
|
+
|
|
30
|
+
You may use this Software, including for any commercial purpose, so long as you
|
|
31
|
+
do not sell, sublicense, or redistribute the components themselves, whether
|
|
32
|
+
alone, in a bundle, or as a ported version.
|
|
33
|
+
|
|
34
|
+
No Warranty
|
|
35
|
+
|
|
36
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
37
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
39
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
40
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
41
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
42
|
+
SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
export const SERVER_ICON_PATH = "/assets/icon-square.png";
|
|
3
|
+
export const SERVER_ICON_FILE = fileURLToPath(new URL("../assets/icon-square.png", import.meta.url));
|
|
4
|
+
// Public, same-origin PNG shared by remote and stdio server metadata.
|
|
5
|
+
export const SERVER_ICONS = [
|
|
6
|
+
{
|
|
7
|
+
src: `https://mcp.search1api.com${SERVER_ICON_PATH}`,
|
|
8
|
+
mimeType: "image/png",
|
|
9
|
+
sizes: ["512x512"],
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
// Same wording as server.json, advertised in the MCP handshake serverInfo.
|
|
13
|
+
export const SERVER_DESCRIPTION = "Web search, agentic search, news, page retrieval, sitemaps, and trending topics through Search1API.";
|
package/build/config.js
CHANGED
|
@@ -45,5 +45,8 @@ export const API_CONFIG = {
|
|
|
45
45
|
ASK: '/ask'
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
// Agentback project public key for the send_feedback tool. It can only submit
|
|
49
|
+
// feedback, so it ships with the package like any other public client key.
|
|
50
|
+
export const AGENTBACK_PROJECT_KEY = 'af_97385a84ecf95968db2403eb6ef165ddcd8ee6716c1b2ceb72f1a35a69e52b8e';
|
|
48
51
|
// Export API key
|
|
49
52
|
export { API_KEY };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { API_CONFIG } from "./config.js";
|
|
2
|
+
import { log } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Look up the signed Agentback identity of the Search1API user behind
|
|
5
|
+
* `apiKey`, so their feedback shows up under their account. Returns undefined
|
|
6
|
+
* when there is no key or the lookup fails; the report is then sent without an
|
|
7
|
+
* account rather than not at all.
|
|
8
|
+
*/
|
|
9
|
+
export async function feedbackIdentity(apiKey) {
|
|
10
|
+
if (!apiKey)
|
|
11
|
+
return undefined;
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}/feedback/identity`, {
|
|
14
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
15
|
+
signal: AbortSignal.timeout(3000),
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
log(`Feedback identity lookup returned HTTP ${response.status}`);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const body = (await response.json());
|
|
22
|
+
return typeof body.account === "string" &&
|
|
23
|
+
typeof body.signature === "string"
|
|
24
|
+
? { account: body.account, signature: body.signature }
|
|
25
|
+
: undefined;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
log("Feedback identity lookup failed");
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/build/http.js
CHANGED
|
@@ -6,11 +6,14 @@ import { createMcpHandler, INTERNAL_ERROR, PARSE_ERROR, } from "@modelcontextpro
|
|
|
6
6
|
import express from "express";
|
|
7
7
|
import { createMcpServer, unauthenticatedCredential, UNAUTHENTICATED, } from "./server.js";
|
|
8
8
|
import { ALL_TOOLS } from "./tools/index.js";
|
|
9
|
+
import { renderSetupPage } from "./setup-page.js";
|
|
9
10
|
import { PACKAGE_VERSION } from "./version.js";
|
|
11
|
+
import { SERVER_ICON_FILE, SERVER_ICON_PATH, SERVER_ICONS } from "./branding.js";
|
|
10
12
|
import { log } from "./utils.js";
|
|
11
13
|
const API_BASE_URL = process.env.SEARCH1API_API_URL || "https://api.search1api.com";
|
|
12
14
|
const DEFAULT_AUTHORIZATION_SERVER = "https://clerk.s1.dev";
|
|
13
15
|
const OAUTH_DISCOVERY_CACHE_CONTROL = "public, max-age=60, s-maxage=60";
|
|
16
|
+
const OAUTH_SCOPES = ["offline_access"];
|
|
14
17
|
const MCP_RESOURCE = "https://mcp.search1api.com/mcp";
|
|
15
18
|
// Public by design: the OpenAI Platform reads it to verify that we own this
|
|
16
19
|
// host before listing the plugin.
|
|
@@ -43,6 +46,43 @@ export async function validateCredential(credential) {
|
|
|
43
46
|
}
|
|
44
47
|
return { credential, principal };
|
|
45
48
|
}
|
|
49
|
+
// A rejected credential stays rejected for this long before it is checked
|
|
50
|
+
// again. Clients holding a dead token keep retrying (one ping every few
|
|
51
|
+
// seconds, indefinitely), and without the cache each retry costs a /usage
|
|
52
|
+
// call that the API counts as a 401. Matches the gateway's own cache of
|
|
53
|
+
// failed token validation.
|
|
54
|
+
const REJECTED_CREDENTIAL_TTL_MS = 60_000;
|
|
55
|
+
const REJECTED_CREDENTIAL_MAX_ENTRIES = 10_000;
|
|
56
|
+
/**
|
|
57
|
+
* Remember credentials the API rejected so repeat attempts are refused
|
|
58
|
+
* locally. Only rejections are cached: accepted credentials are still checked
|
|
59
|
+
* on every exchange, and validation outages (thrown errors) are not cached.
|
|
60
|
+
*/
|
|
61
|
+
export function cacheRejectedCredentials(validator, { ttlMs = REJECTED_CREDENTIAL_TTL_MS, maxEntries = REJECTED_CREDENTIAL_MAX_ENTRIES, now = Date.now, } = {}) {
|
|
62
|
+
const rejectedUntil = new Map();
|
|
63
|
+
return async (credential) => {
|
|
64
|
+
const key = createHash("sha256").update(credential).digest("hex");
|
|
65
|
+
const expiresAt = rejectedUntil.get(key);
|
|
66
|
+
if (expiresAt !== undefined) {
|
|
67
|
+
if (expiresAt > now()) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
rejectedUntil.delete(key);
|
|
71
|
+
}
|
|
72
|
+
const authenticated = await validator(credential);
|
|
73
|
+
if (!authenticated) {
|
|
74
|
+
// Map keeps insertion order, so the first key is the oldest entry.
|
|
75
|
+
if (rejectedUntil.size >= maxEntries) {
|
|
76
|
+
const oldest = rejectedUntil.keys().next().value;
|
|
77
|
+
if (oldest !== undefined) {
|
|
78
|
+
rejectedUntil.delete(oldest);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
rejectedUntil.set(key, now() + ttlMs);
|
|
82
|
+
}
|
|
83
|
+
return authenticated;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
46
86
|
/**
|
|
47
87
|
* Build the HTTP application without starting a listener.
|
|
48
88
|
*
|
|
@@ -57,7 +97,7 @@ export async function validateCredential(credential) {
|
|
|
57
97
|
*/
|
|
58
98
|
export function createHttpApp(options = {}) {
|
|
59
99
|
const app = express();
|
|
60
|
-
const credentialValidator = options.validateCredential ?? validateCredential;
|
|
100
|
+
const credentialValidator = cacheRejectedCredentials(options.validateCredential ?? validateCredential);
|
|
61
101
|
const authorizationServer = normalizeAuthorizationServer(options.authorizationServer ??
|
|
62
102
|
process.env.OAUTH_AUTHORIZATION_SERVER ??
|
|
63
103
|
DEFAULT_AUTHORIZATION_SERVER);
|
|
@@ -72,22 +112,65 @@ export function createHttpApp(options = {}) {
|
|
|
72
112
|
const nodeHandler = toNodeHandler(mcpHandler, {
|
|
73
113
|
onerror: (error) => log("MCP Node adapter error:", error),
|
|
74
114
|
});
|
|
115
|
+
// Refusals (Host/Origin checks, rejected credentials, protocol errors) are
|
|
116
|
+
// otherwise silent, which leaves a failing directory scanner undiagnosable.
|
|
117
|
+
// The bare 401 challenge that starts OAuth discovery is routine and only
|
|
118
|
+
// logged when it opens a connection (initialize or server/discover), so each
|
|
119
|
+
// client's connect attempt shows up once with its outcome.
|
|
120
|
+
app.use("/mcp", (req, res, next) => {
|
|
121
|
+
res.on("finish", () => {
|
|
122
|
+
const hasCredential = extractCredential(req) !== undefined;
|
|
123
|
+
const body = req.body && typeof req.body === "object" ? req.body : undefined;
|
|
124
|
+
const rpcMethod = body && "method" in body ? String(body.method) : undefined;
|
|
125
|
+
const opensConnection = rpcMethod === "initialize" || rpcMethod === "server/discover";
|
|
126
|
+
const refused = res.statusCode >= 400 && !(res.statusCode === 401 && !hasCredential);
|
|
127
|
+
if (!refused && !opensConnection) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const clientInfo = body?.params?.clientInfo ??
|
|
131
|
+
body?.params?._meta?.["io.modelcontextprotocol/clientInfo"];
|
|
132
|
+
log(`${refused ? "MCP request refused" : "MCP connection"}: ${req.method} ${res.statusCode}`, JSON.stringify({
|
|
133
|
+
rpcMethod,
|
|
134
|
+
client: typeof clientInfo?.name === "string" ? clientInfo.name : undefined,
|
|
135
|
+
credential: hasCredential,
|
|
136
|
+
origin: req.headers.origin,
|
|
137
|
+
host: req.headers.host,
|
|
138
|
+
protocolVersion: req.headers["mcp-protocol-version"],
|
|
139
|
+
accept: req.headers.accept,
|
|
140
|
+
contentType: req.headers["content-type"],
|
|
141
|
+
userAgent: req.headers["user-agent"],
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
144
|
+
next();
|
|
145
|
+
});
|
|
75
146
|
app.use((req, res, next) => {
|
|
76
147
|
if (!validateHost(req, res)) {
|
|
77
148
|
return;
|
|
78
149
|
}
|
|
79
150
|
next();
|
|
80
151
|
});
|
|
81
|
-
// The service root
|
|
152
|
+
// The service root points to the MCP product page. Keep
|
|
82
153
|
// query parameters so bookmarked campaign/support links remain attributable.
|
|
154
|
+
// Answer 200 rather than redirecting: this origin is the declared widget
|
|
155
|
+
// domain, and directory checks treat a redirect as an unreachable domain.
|
|
83
156
|
app.get("/", (req, res) => {
|
|
84
|
-
const target = new URL("https://s1.dev/
|
|
157
|
+
const target = new URL("https://s1.dev/mcp-server");
|
|
85
158
|
for (const [key, value] of Object.entries(req.query)) {
|
|
86
159
|
if (typeof value === "string") {
|
|
87
160
|
target.searchParams.append(key, value);
|
|
88
161
|
}
|
|
89
162
|
}
|
|
90
|
-
|
|
163
|
+
// URLSearchParams percent-encodes quotes and angle brackets; only & needs escaping.
|
|
164
|
+
const href = target.toString().replaceAll("&", "&");
|
|
165
|
+
res
|
|
166
|
+
.status(200)
|
|
167
|
+
.set("Link", '<https://s1.dev/mcp-server>; rel="canonical"')
|
|
168
|
+
.type("html")
|
|
169
|
+
.send(`<!doctype html><html lang="en"><head><meta charset="utf-8">` +
|
|
170
|
+
`<title>Search1API MCP Server</title>` +
|
|
171
|
+
`<link rel="canonical" href="https://s1.dev/mcp-server">` +
|
|
172
|
+
`<meta http-equiv="refresh" content="0; url=${href}">` +
|
|
173
|
+
`</head><body><p>Search1API MCP Server. Continue to <a href="${href}">s1.dev/mcp-server</a>.</p></body></html>`);
|
|
91
174
|
});
|
|
92
175
|
// /mcp is a transport endpoint that answers nothing without a credential,
|
|
93
176
|
// so search engines gain nothing from walking this host. Keep the OAuth
|
|
@@ -100,11 +183,23 @@ export function createHttpApp(options = {}) {
|
|
|
100
183
|
app.get("/.well-known/openai-apps-challenge", (_req, res) => {
|
|
101
184
|
res.type("text/plain").send(OPENAI_APPS_CHALLENGE_TOKEN);
|
|
102
185
|
});
|
|
103
|
-
//
|
|
104
|
-
|
|
186
|
+
// MCP clients fetch implementation icons without cookies or credentials.
|
|
187
|
+
app.get(SERVER_ICON_PATH, (_req, res) => {
|
|
188
|
+
res
|
|
189
|
+
.set("Cache-Control", "public, max-age=3600")
|
|
190
|
+
.type("image/png")
|
|
191
|
+
.sendFile(SERVER_ICON_FILE);
|
|
192
|
+
});
|
|
193
|
+
// The resource needs no scope of its own, but clients that find no scope
|
|
194
|
+
// here fall back to every scope the authorization server lists, including
|
|
195
|
+
// Clerk's public_metadata and private_metadata, which dynamically registered
|
|
196
|
+
// clients may not request. Search1API checks no scope on the token, and
|
|
197
|
+
// offline_access alone is in every dynamic client's grant, including clients
|
|
198
|
+
// registered before openid joined Clerk's defaults.
|
|
105
199
|
const protectedResourceMetadata = {
|
|
106
200
|
resource: MCP_RESOURCE,
|
|
107
201
|
authorization_servers: [authorizationServer],
|
|
202
|
+
scopes_supported: OAUTH_SCOPES,
|
|
108
203
|
bearer_methods_supported: ["header"],
|
|
109
204
|
resource_documentation: "https://s1.dev/auth.md",
|
|
110
205
|
};
|
|
@@ -129,6 +224,7 @@ export function createHttpApp(options = {}) {
|
|
|
129
224
|
.json({
|
|
130
225
|
name: "Search1API",
|
|
131
226
|
version: PACKAGE_VERSION,
|
|
227
|
+
icons: SERVER_ICONS,
|
|
132
228
|
description: "Remote MCP server for Search1API. Exposes live web search, agentic search, news, page reading, sitemap discovery, and trending topics as tools for AI agents.",
|
|
133
229
|
serverUrl: MCP_RESOURCE,
|
|
134
230
|
tools: ALL_TOOLS.map((tool) => ({
|
|
@@ -142,6 +238,7 @@ export function createHttpApp(options = {}) {
|
|
|
142
238
|
name: "Search1API",
|
|
143
239
|
title: "Search1API MCP",
|
|
144
240
|
version: PACKAGE_VERSION,
|
|
241
|
+
icons: SERVER_ICONS,
|
|
145
242
|
},
|
|
146
243
|
protocolVersion: "2025-06-18",
|
|
147
244
|
transport: { type: "streamable-http", endpoint: MCP_RESOURCE },
|
|
@@ -170,6 +267,25 @@ export function createHttpApp(options = {}) {
|
|
|
170
267
|
}
|
|
171
268
|
next();
|
|
172
269
|
});
|
|
270
|
+
// A person opening the MCP URL in a browser gets setup instructions instead
|
|
271
|
+
// of a bare 401. MCP clients POST, or GET with text/event-stream, and still
|
|
272
|
+
// draw the challenge that starts OAuth; a presented credential always goes
|
|
273
|
+
// through to the transport.
|
|
274
|
+
app.get("/mcp", (req, res, next) => {
|
|
275
|
+
const accept = req.headers.accept ?? "";
|
|
276
|
+
if (extractCredential(req) !== undefined ||
|
|
277
|
+
accept.includes("text/event-stream") ||
|
|
278
|
+
!accept.includes("text/html")) {
|
|
279
|
+
next();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
res
|
|
283
|
+
.status(200)
|
|
284
|
+
.set("Cache-Control", "public, max-age=300")
|
|
285
|
+
.set("Vary", "Accept, Authorization")
|
|
286
|
+
.type("html")
|
|
287
|
+
.send(renderSetupPage());
|
|
288
|
+
});
|
|
173
289
|
app.use(express.json());
|
|
174
290
|
app.all("/mcp", async (req, res) => {
|
|
175
291
|
const outcome = await authenticateMcpRequest(req, res, credentialValidator);
|
|
@@ -295,7 +411,7 @@ function extractCredential(req) {
|
|
|
295
411
|
}
|
|
296
412
|
function challenge(res, message, error) {
|
|
297
413
|
const errorParameter = error ? `, error="${error}"` : "";
|
|
298
|
-
res.set("WWW-Authenticate", `Bearer resource_metadata="${MCP_RESOURCE_METADATA}"${errorParameter}`);
|
|
414
|
+
res.set("WWW-Authenticate", `Bearer resource_metadata="${MCP_RESOURCE_METADATA}", scope="${OAUTH_SCOPES.join(" ")}"${errorParameter}`);
|
|
299
415
|
res.status(401).json({
|
|
300
416
|
jsonrpc: "2.0",
|
|
301
417
|
error: { code: UNAUTHENTICATED, message },
|
package/build/server.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { INTERNAL_ERROR, McpServer, ProtocolError, fromJsonSchema, } from "@modelcontextprotocol/server";
|
|
2
|
+
import { Agentback } from "agentback";
|
|
3
|
+
import { attachToMcp } from "agentback/mcp";
|
|
4
|
+
import { AGENTBACK_PROJECT_KEY } from "./config.js";
|
|
5
|
+
import { feedbackIdentity } from "./feedback.js";
|
|
2
6
|
import { handleReadResource, RESOURCES } from "./resources.js";
|
|
3
7
|
import { handleToolCall } from "./tools/handlers.js";
|
|
4
8
|
import { ALL_TOOLS } from "./tools/index.js";
|
|
9
|
+
import { MCP_APP_MIME_TYPE, SEARCH_UI_META, SEARCH_UI_URI, SEARCH_UI_COMPAT_URIS, readSearchUi, } from "./ui.js";
|
|
5
10
|
import { formatError, log } from "./utils.js";
|
|
6
11
|
import { PACKAGE_VERSION } from "./version.js";
|
|
12
|
+
import { SERVER_DESCRIPTION, SERVER_ICONS } from "./branding.js";
|
|
7
13
|
/** JSON-RPC error code this server uses for a missing or rejected credential. */
|
|
8
14
|
export const UNAUTHENTICATED = -32001;
|
|
9
15
|
/**
|
|
@@ -24,13 +30,18 @@ export function unauthenticatedCredential(message) {
|
|
|
24
30
|
*
|
|
25
31
|
* The v2 serving entries call this factory once per modern HTTP exchange,
|
|
26
32
|
* once per stateless legacy HTTP request, or once per stdio connection.
|
|
33
|
+
* All transports expose the same data tools and optional rendering tool.
|
|
27
34
|
*/
|
|
28
35
|
export function createMcpServer(credential) {
|
|
29
36
|
log("Creating Search1API MCP server");
|
|
30
37
|
const server = new McpServer({
|
|
31
|
-
name: "search1api
|
|
38
|
+
name: "search1api",
|
|
39
|
+
title: "Search1API",
|
|
32
40
|
version: PACKAGE_VERSION,
|
|
33
|
-
|
|
41
|
+
icons: SERVER_ICONS,
|
|
42
|
+
websiteUrl: "https://s1.dev",
|
|
43
|
+
description: SERVER_DESCRIPTION,
|
|
44
|
+
}, { instructions: "Use search, news, ask, crawl, sitemap and trending to retrieve data. Call render_results with selected existing results only when the user wants to browse sources or a visual list helps. Rendering never repeats a search or consumes search credits; unsupported UI clients receive a readable text list." });
|
|
34
45
|
for (const tool of ALL_TOOLS) {
|
|
35
46
|
const inputSchema = fromJsonSchema(tool.inputSchema);
|
|
36
47
|
const outputSchema = tool.outputSchema
|
|
@@ -54,6 +65,12 @@ export function createMcpServer(credential) {
|
|
|
54
65
|
}
|
|
55
66
|
});
|
|
56
67
|
}
|
|
68
|
+
// Lets agents report wrong results, unresolved errors or missing
|
|
69
|
+
// capabilities. Reporting is free and spends no Search1API credit.
|
|
70
|
+
attachToMcp(server, new Agentback({ projectKey: AGENTBACK_PROJECT_KEY }), {
|
|
71
|
+
product: "Search1API",
|
|
72
|
+
identify: () => feedbackIdentity(resolveCredential(credential)),
|
|
73
|
+
});
|
|
57
74
|
for (const resource of RESOURCES) {
|
|
58
75
|
server.registerResource(resource.name, resource.uri, {
|
|
59
76
|
description: resource.description,
|
|
@@ -76,8 +93,43 @@ export function createMcpServer(credential) {
|
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
95
|
}
|
|
96
|
+
if (SEARCH_UI_URI) {
|
|
97
|
+
for (const resourceUri of [SEARCH_UI_URI, ...SEARCH_UI_COMPAT_URIS]) {
|
|
98
|
+
server.registerResource(resourceUri === SEARCH_UI_URI ? "search-ui" : "search-ui-compat", resourceUri, {
|
|
99
|
+
title: "Source results view",
|
|
100
|
+
description: "Interactive view of already retrieved source results",
|
|
101
|
+
mimeType: MCP_APP_MIME_TYPE,
|
|
102
|
+
_meta: SEARCH_UI_META,
|
|
103
|
+
}, async (uri) => {
|
|
104
|
+
try {
|
|
105
|
+
return {
|
|
106
|
+
contents: [
|
|
107
|
+
{
|
|
108
|
+
uri: uri.href,
|
|
109
|
+
mimeType: MCP_APP_MIME_TYPE,
|
|
110
|
+
text: readSearchUi(),
|
|
111
|
+
_meta: SEARCH_UI_META,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw normalizeProtocolError("reading search UI", error);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
79
122
|
return server;
|
|
80
123
|
}
|
|
124
|
+
// Unlike tool calls, feedback goes out without a credential when none resolves.
|
|
125
|
+
function resolveCredential(credential) {
|
|
126
|
+
try {
|
|
127
|
+
return typeof credential === "function" ? credential() : credential;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
81
133
|
function normalizeProtocolError(context, error) {
|
|
82
134
|
log(`Error ${context}:`, error);
|
|
83
135
|
if (error instanceof ProtocolError) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ALL_TOOLS } from "./tools/index.js";
|
|
2
|
+
const MCP_URL = "https://mcp.search1api.com/mcp";
|
|
3
|
+
function escapeHtml(value) {
|
|
4
|
+
return value
|
|
5
|
+
.replaceAll("&", "&")
|
|
6
|
+
.replaceAll("<", "<")
|
|
7
|
+
.replaceAll(">", ">")
|
|
8
|
+
.replaceAll('"', """);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Human-readable setup instructions served when a browser opens the MCP URL.
|
|
12
|
+
* MCP clients never see this page: they POST, or GET with text/event-stream,
|
|
13
|
+
* and still receive the 401 challenge that starts OAuth.
|
|
14
|
+
*/
|
|
15
|
+
export function renderSetupPage() {
|
|
16
|
+
const tools = ALL_TOOLS.map((tool) => `<li><code>${escapeHtml(tool.name)}</code> ${escapeHtml(tool.title ?? "")}</li>`).join("");
|
|
17
|
+
const cursorConfig = escapeHtml(JSON.stringify({ mcpServers: { search1api: { url: MCP_URL } } }, null, 2));
|
|
18
|
+
return `<!doctype html>
|
|
19
|
+
<html lang="en">
|
|
20
|
+
<head>
|
|
21
|
+
<meta charset="utf-8">
|
|
22
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
23
|
+
<title>Search1API MCP Server: setup</title>
|
|
24
|
+
<link rel="canonical" href="https://s1.dev/mcp-server">
|
|
25
|
+
<style>
|
|
26
|
+
body{font:16px/1.6 system-ui,sans-serif;max-width:720px;margin:0 auto;padding:24px 16px;color:#111;background:#fff}
|
|
27
|
+
pre,code{font-family:ui-monospace,monospace;font-size:14px}
|
|
28
|
+
pre{background:#f4f4f5;padding:12px;border-radius:8px;overflow-x:auto}
|
|
29
|
+
a{color:#1d4ed8}
|
|
30
|
+
@media (prefers-color-scheme:dark){body{color:#eee;background:#111}pre{background:#222}a{color:#93c5fd}}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<h1>Search1API MCP Server</h1>
|
|
35
|
+
<p>This is a remote MCP endpoint for AI clients, not a web page. Add this URL to your MCP client:</p>
|
|
36
|
+
<pre>${MCP_URL}</pre>
|
|
37
|
+
<h2>Sign in</h2>
|
|
38
|
+
<p>Connect without a key and your client will open the Search1API sign-in (OAuth). Or send an API key from <a href="https://app.s1.dev">your dashboard</a> as <code>Authorization: Bearer YOUR_SEARCH1API_KEY</code>.</p>
|
|
39
|
+
<h2>Clients</h2>
|
|
40
|
+
<p><strong>Claude.ai</strong>: install Search1API from the <a href="https://claude.ai/directory/search1api">Claude directory</a> and click Connect.</p>
|
|
41
|
+
<p><strong>Claude Code</strong>:</p>
|
|
42
|
+
<pre>claude mcp add --transport http search1api ${MCP_URL}</pre>
|
|
43
|
+
<p><strong>Cursor, Windsurf, Claude Desktop and other clients</strong> (mcp.json):</p>
|
|
44
|
+
<pre>${cursorConfig}</pre>
|
|
45
|
+
<h2>Tools</h2>
|
|
46
|
+
<ul>${tools}</ul>
|
|
47
|
+
<p>Full guide: <a href="https://s1.dev/mcp-server">s1.dev/mcp-server</a></p>
|
|
48
|
+
</body>
|
|
49
|
+
</html>`;
|
|
50
|
+
}
|
package/build/tools/handlers.js
CHANGED
|
@@ -5,8 +5,9 @@ import { handleCrawl } from "./crawl.js";
|
|
|
5
5
|
import { handleSitemap } from "./sitemap.js";
|
|
6
6
|
import { handleNews } from "./news.js";
|
|
7
7
|
import { handleTrending } from "./trending.js";
|
|
8
|
+
import { handleRenderResults } from "./render-results.js";
|
|
8
9
|
import { handleAsk } from "./ask.js";
|
|
9
|
-
import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL, ASK_TOOL, } from "./index.js";
|
|
10
|
+
import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL, ASK_TOOL, RENDER_RESULTS_TOOL, } from "./index.js";
|
|
10
11
|
/**
|
|
11
12
|
* Dispatch request based on tool name
|
|
12
13
|
* @param toolName Name of the tool
|
|
@@ -29,6 +30,8 @@ export async function handleToolCall(toolName, args, apiKey) {
|
|
|
29
30
|
return await handleTrending(args, apiKey);
|
|
30
31
|
case ASK_TOOL.name:
|
|
31
32
|
return await handleAsk(args, apiKey);
|
|
33
|
+
case RENDER_RESULTS_TOOL.name:
|
|
34
|
+
return await handleRenderResults(args);
|
|
32
35
|
default:
|
|
33
36
|
log(`Unknown tool: ${toolName}`);
|
|
34
37
|
throw new ProtocolError(INVALID_PARAMS, `Unknown tool: ${toolName}`);
|