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/build/tools/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SEARCH_UI_URI } from "../ui.js";
|
|
2
|
+
import { RENDER_INPUT_SCHEMA, RENDER_OUTPUT_SCHEMA } from "./render-results.js";
|
|
1
3
|
const AUTHENTICATED_READ_ONLY_WEB = {
|
|
2
4
|
// Authentication is required, but the API does not enforce a
|
|
3
5
|
// resource-specific OAuth scope for these tools.
|
|
@@ -18,6 +20,8 @@ const AUTHENTICATED_READ_ONLY_WEB = {
|
|
|
18
20
|
annotations: {
|
|
19
21
|
readOnlyHint: true,
|
|
20
22
|
destructiveHint: false,
|
|
23
|
+
// Every call is billed in credits, so a repeat is not free of effects.
|
|
24
|
+
idempotentHint: false,
|
|
21
25
|
openWorldHint: true,
|
|
22
26
|
},
|
|
23
27
|
};
|
|
@@ -54,6 +58,7 @@ const SEARCH_OUTPUT_SCHEMA = {
|
|
|
54
58
|
properties: {
|
|
55
59
|
results: {
|
|
56
60
|
type: "array",
|
|
61
|
+
description: "Matching sources, most relevant first; read any url in full with crawl",
|
|
57
62
|
items: CITABLE_RESULT_SCHEMA,
|
|
58
63
|
},
|
|
59
64
|
},
|
|
@@ -62,7 +67,7 @@ const SEARCH_OUTPUT_SCHEMA = {
|
|
|
62
67
|
// Search tool definition
|
|
63
68
|
export const SEARCH_TOOL = {
|
|
64
69
|
name: "search",
|
|
65
|
-
title: "
|
|
70
|
+
title: "Web search",
|
|
66
71
|
description: "Search the live public web when the user needs current information, sources, or research. Returns citable results with id, title, URL, and text. Each result includes a URL that can be read in full.",
|
|
67
72
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
68
73
|
inputSchema: {
|
|
@@ -76,7 +81,7 @@ export const SEARCH_TOOL = {
|
|
|
76
81
|
type: "number",
|
|
77
82
|
minimum: 1,
|
|
78
83
|
maximum: 50,
|
|
79
|
-
description: "
|
|
84
|
+
description: "How many sources the answer needs; a handful suits most questions, more suits a broad survey",
|
|
80
85
|
default: 10,
|
|
81
86
|
},
|
|
82
87
|
search_service: {
|
|
@@ -89,13 +94,13 @@ export const SEARCH_TOOL = {
|
|
|
89
94
|
type: "number",
|
|
90
95
|
minimum: 1,
|
|
91
96
|
maximum: 100,
|
|
92
|
-
description: "
|
|
97
|
+
description: "Which page of results to fetch when the first page was not enough; only bing, bingcn, and grokipedia paginate, other engines ignore it",
|
|
93
98
|
default: 1,
|
|
94
99
|
},
|
|
95
100
|
crawl_results: {
|
|
96
101
|
type: "number",
|
|
97
102
|
minimum: 0,
|
|
98
|
-
description: "
|
|
103
|
+
description: "How many top results to also read in full, so their text holds the whole page instead of a snippet. Each successful page retrieval adds 1 credit to the base 1-credit search request",
|
|
99
104
|
default: 0,
|
|
100
105
|
},
|
|
101
106
|
include_sites: {
|
|
@@ -116,18 +121,23 @@ export const SEARCH_TOOL = {
|
|
|
116
121
|
},
|
|
117
122
|
time_range: {
|
|
118
123
|
type: "string",
|
|
119
|
-
description: "
|
|
124
|
+
description: "Restrict results to those published recently, for time-sensitive questions; leave unset for evergreen topics",
|
|
120
125
|
enum: ["day", "week", "month", "year"],
|
|
121
126
|
},
|
|
122
127
|
},
|
|
123
128
|
required: ["query"],
|
|
124
129
|
},
|
|
125
130
|
outputSchema: SEARCH_OUTPUT_SCHEMA,
|
|
131
|
+
_meta: {
|
|
132
|
+
...AUTHENTICATED_READ_ONLY_WEB._meta,
|
|
133
|
+
"openai/toolInvocation/invoking": "Searching the web…",
|
|
134
|
+
"openai/toolInvocation/invoked": "Search results",
|
|
135
|
+
},
|
|
126
136
|
};
|
|
127
137
|
// News tool definition
|
|
128
138
|
export const NEWS_TOOL = {
|
|
129
139
|
name: "news",
|
|
130
|
-
title: "
|
|
140
|
+
title: "News search",
|
|
131
141
|
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.",
|
|
132
142
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
133
143
|
inputSchema: {
|
|
@@ -141,12 +151,12 @@ export const NEWS_TOOL = {
|
|
|
141
151
|
type: "number",
|
|
142
152
|
minimum: 1,
|
|
143
153
|
maximum: 50,
|
|
144
|
-
description: "
|
|
154
|
+
description: "How many articles the answer needs; a handful suits most questions, more suits broad coverage",
|
|
145
155
|
default: 10,
|
|
146
156
|
},
|
|
147
157
|
search_service: {
|
|
148
158
|
type: "string",
|
|
149
|
-
description: "News
|
|
159
|
+
description: "News engine to use; hackernews returns Hacker News discussions instead of publisher articles",
|
|
150
160
|
default: "bing",
|
|
151
161
|
enum: ["google", "bing", "duckduckgo", "yahoo", "hackernews"],
|
|
152
162
|
},
|
|
@@ -174,19 +184,24 @@ export const NEWS_TOOL = {
|
|
|
174
184
|
},
|
|
175
185
|
time_range: {
|
|
176
186
|
type: "string",
|
|
177
|
-
description: "
|
|
187
|
+
description: "Only return articles published within this window; use day for breaking news",
|
|
178
188
|
enum: ["day", "week", "month", "year"],
|
|
179
189
|
},
|
|
180
190
|
},
|
|
181
191
|
required: ["query"],
|
|
182
192
|
},
|
|
183
193
|
outputSchema: SEARCH_OUTPUT_SCHEMA,
|
|
194
|
+
_meta: {
|
|
195
|
+
...AUTHENTICATED_READ_ONLY_WEB._meta,
|
|
196
|
+
"openai/toolInvocation/invoking": "Searching news…",
|
|
197
|
+
"openai/toolInvocation/invoked": "News results",
|
|
198
|
+
},
|
|
184
199
|
};
|
|
185
200
|
// Crawl tool definition
|
|
186
201
|
export const CRAWL_TOOL = {
|
|
187
202
|
name: "crawl",
|
|
188
203
|
title: "Read a web page",
|
|
189
|
-
description: "
|
|
204
|
+
description: "Read a public web page supplied by the user or returned by search. Returns its title, URL, and main content as text, so you can answer from the full page instead of a snippet.",
|
|
190
205
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
191
206
|
inputSchema: {
|
|
192
207
|
type: "object",
|
|
@@ -194,7 +209,7 @@ export const CRAWL_TOOL = {
|
|
|
194
209
|
url: {
|
|
195
210
|
type: "string",
|
|
196
211
|
format: "uri",
|
|
197
|
-
description: "
|
|
212
|
+
description: "Address of the page to read, such as a link the user shared or a URL from search results",
|
|
198
213
|
},
|
|
199
214
|
},
|
|
200
215
|
required: ["url"],
|
|
@@ -202,7 +217,10 @@ export const CRAWL_TOOL = {
|
|
|
202
217
|
outputSchema: {
|
|
203
218
|
type: "object",
|
|
204
219
|
properties: {
|
|
205
|
-
result:
|
|
220
|
+
result: {
|
|
221
|
+
...CITABLE_RESULT_SCHEMA,
|
|
222
|
+
description: "The page that was read; text holds its main content",
|
|
223
|
+
},
|
|
206
224
|
},
|
|
207
225
|
required: ["result"],
|
|
208
226
|
},
|
|
@@ -211,7 +229,7 @@ export const CRAWL_TOOL = {
|
|
|
211
229
|
export const SITEMAP_TOOL = {
|
|
212
230
|
name: "sitemap",
|
|
213
231
|
title: "Discover links on a site",
|
|
214
|
-
description: "Discover related public links from a page or domain when the user wants to explore a site's structure or available pages.",
|
|
232
|
+
description: "Discover related public links from a page or domain when the user wants to explore a site's structure or available pages. Returns a list of absolute URLs found on that site, which can then be read with crawl.",
|
|
215
233
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
216
234
|
inputSchema: {
|
|
217
235
|
type: "object",
|
|
@@ -229,6 +247,7 @@ export const SITEMAP_TOOL = {
|
|
|
229
247
|
properties: {
|
|
230
248
|
links: {
|
|
231
249
|
type: "array",
|
|
250
|
+
description: "Absolute URLs discovered on the site, without titles or page content",
|
|
232
251
|
items: {
|
|
233
252
|
type: "string",
|
|
234
253
|
format: "uri",
|
|
@@ -242,14 +261,14 @@ export const SITEMAP_TOOL = {
|
|
|
242
261
|
export const TRENDING_TOOL = {
|
|
243
262
|
name: "trending",
|
|
244
263
|
title: "Explore trending topics",
|
|
245
|
-
description: "List currently trending repositories or stories from GitHub or Hacker News when the user asks what is popular now.",
|
|
264
|
+
description: "List currently trending repositories or stories from GitHub or Hacker News when the user asks what is popular now. Returns each item's title, URL, and a short description when the platform provides one.",
|
|
246
265
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
247
266
|
inputSchema: {
|
|
248
267
|
type: "object",
|
|
249
268
|
properties: {
|
|
250
269
|
search_service: {
|
|
251
270
|
type: "string",
|
|
252
|
-
description: "
|
|
271
|
+
description: "Where to look: GitHub for popular open-source repositories, Hacker News for stories developers are discussing",
|
|
253
272
|
enum: ["github", "hackernews"],
|
|
254
273
|
default: "github",
|
|
255
274
|
},
|
|
@@ -257,7 +276,7 @@ export const TRENDING_TOOL = {
|
|
|
257
276
|
type: "number",
|
|
258
277
|
minimum: 1,
|
|
259
278
|
maximum: 50,
|
|
260
|
-
description: "
|
|
279
|
+
description: "How many trending items the answer needs, from the top of the list",
|
|
261
280
|
default: 10,
|
|
262
281
|
},
|
|
263
282
|
},
|
|
@@ -268,12 +287,13 @@ export const TRENDING_TOOL = {
|
|
|
268
287
|
properties: {
|
|
269
288
|
results: {
|
|
270
289
|
type: "array",
|
|
290
|
+
description: "Trending items reported by the platform",
|
|
271
291
|
items: {
|
|
272
292
|
type: "object",
|
|
273
293
|
properties: {
|
|
274
|
-
title: { type: "string" },
|
|
275
|
-
url: { type: "string", format: "uri" },
|
|
276
|
-
description: { type: "string" },
|
|
294
|
+
title: { type: "string", description: "Repository name or story headline" },
|
|
295
|
+
url: { type: "string", format: "uri", description: "Link to the repository or story" },
|
|
296
|
+
description: { type: "string", description: "Repository summary or story context, when available" },
|
|
277
297
|
},
|
|
278
298
|
required: ["title", "url"],
|
|
279
299
|
},
|
|
@@ -285,8 +305,8 @@ export const TRENDING_TOOL = {
|
|
|
285
305
|
// Ask tool definition
|
|
286
306
|
export const ASK_TOOL = {
|
|
287
307
|
name: "ask",
|
|
288
|
-
title: "Ask across
|
|
289
|
-
description: "
|
|
308
|
+
title: "Ask across sources",
|
|
309
|
+
description: "Search several sources at once from a natural-language request when the right engine is unclear. Search1API picks up to five engines (web, Hacker News, Reddit, GitHub, X, arXiv, Wikipedia, and more) and a time window from the wording, then returns up to 10 citable results ranked by relevance, plus the intent it used and any engines that failed. Costs 5 credits per call; use search when you already know the engine.",
|
|
290
310
|
...AUTHENTICATED_READ_ONLY_WEB,
|
|
291
311
|
inputSchema: {
|
|
292
312
|
type: "object",
|
|
@@ -294,7 +314,7 @@ export const ASK_TOOL = {
|
|
|
294
314
|
query: {
|
|
295
315
|
type: "string",
|
|
296
316
|
maxLength: 500,
|
|
297
|
-
description: "
|
|
317
|
+
description: "What the user is looking for, in their own words; naming a platform (\"on Reddit\", \"papers\") or a period (\"this week\") steers which engines and time window are used",
|
|
298
318
|
},
|
|
299
319
|
},
|
|
300
320
|
required: ["query"],
|
|
@@ -306,10 +326,11 @@ export const ASK_TOOL = {
|
|
|
306
326
|
type: "object",
|
|
307
327
|
description: "Keywords, engines, and time window that were used",
|
|
308
328
|
properties: {
|
|
309
|
-
search_query: { type: "string" },
|
|
310
|
-
sources: { type: "array", items: { type: "string" } },
|
|
329
|
+
search_query: { type: "string", description: "Keywords sent to the engines" },
|
|
330
|
+
sources: { type: "array", items: { type: "string" }, description: "Engines that were searched" },
|
|
311
331
|
time_range: {
|
|
312
332
|
type: ["string", "null"],
|
|
333
|
+
description: "Recency window inferred from the request, or null for any time",
|
|
313
334
|
enum: ["day", "week", "month", "year", null],
|
|
314
335
|
},
|
|
315
336
|
},
|
|
@@ -317,6 +338,7 @@ export const ASK_TOOL = {
|
|
|
317
338
|
},
|
|
318
339
|
results: {
|
|
319
340
|
type: "array",
|
|
341
|
+
description: "Up to 10 sources across the chosen engines, most relevant first",
|
|
320
342
|
items: CITABLE_RESULT_SCHEMA,
|
|
321
343
|
},
|
|
322
344
|
errors: {
|
|
@@ -335,6 +357,21 @@ export const ASK_TOOL = {
|
|
|
335
357
|
required: ["intent", "results", "errors"],
|
|
336
358
|
},
|
|
337
359
|
};
|
|
360
|
+
export const RENDER_RESULTS_TOOL = {
|
|
361
|
+
name: "render_results",
|
|
362
|
+
title: "Render the results",
|
|
363
|
+
description: "Present already retrieved source results as source cards when the host supports UI, with a complete readable text list otherwise. Use when the user wants to browse sources or a visual list helps the task. Pass existing results in the desired order; never invent source URLs or factual titles. Does not search, crawl, fetch URLs, verify sources, or consume search credits. Do not call for intermediate research results or when a text answer is sufficient.",
|
|
364
|
+
...AUTHENTICATED_READ_ONLY_WEB,
|
|
365
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false, idempotentHint: true },
|
|
366
|
+
inputSchema: RENDER_INPUT_SCHEMA,
|
|
367
|
+
outputSchema: RENDER_OUTPUT_SCHEMA,
|
|
368
|
+
_meta: {
|
|
369
|
+
...AUTHENTICATED_READ_ONLY_WEB._meta,
|
|
370
|
+
"openai/toolInvocation/invoking": "Preparing results…",
|
|
371
|
+
"openai/toolInvocation/invoked": "Results ready",
|
|
372
|
+
...(SEARCH_UI_URI && { ui: { resourceUri: SEARCH_UI_URI, visibility: ["model", "app"] } }),
|
|
373
|
+
},
|
|
374
|
+
};
|
|
338
375
|
export const ALL_TOOLS = [
|
|
339
376
|
SEARCH_TOOL,
|
|
340
377
|
NEWS_TOOL,
|
|
@@ -342,4 +379,5 @@ export const ALL_TOOLS = [
|
|
|
342
379
|
SITEMAP_TOOL,
|
|
343
380
|
TRENDING_TOOL,
|
|
344
381
|
ASK_TOOL,
|
|
382
|
+
RENDER_RESULTS_TOOL,
|
|
345
383
|
];
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { INVALID_PARAMS, ProtocolError } from "@modelcontextprotocol/server";
|
|
2
|
+
export const RENDER_INPUT_SCHEMA = {
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"title": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"minLength": 1,
|
|
9
|
+
"maxLength": 120,
|
|
10
|
+
"description": "Heading shown above the cards, such as the research topic"
|
|
11
|
+
},
|
|
12
|
+
"results": {
|
|
13
|
+
"type": "array",
|
|
14
|
+
"minItems": 0,
|
|
15
|
+
"maxItems": 50,
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"additionalProperties": false,
|
|
19
|
+
"properties": {
|
|
20
|
+
"id": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"minLength": 1,
|
|
23
|
+
"maxLength": 2048,
|
|
24
|
+
"description": "The id from the original search result; the server falls back to the URL when there is none"
|
|
25
|
+
},
|
|
26
|
+
"title": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"minLength": 1,
|
|
29
|
+
"maxLength": 300,
|
|
30
|
+
"description": "Source title exactly as the search returned it; never invent or rewrite it"
|
|
31
|
+
},
|
|
32
|
+
"url": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"format": "uri",
|
|
35
|
+
"pattern": "^https?://",
|
|
36
|
+
"maxLength": 2048,
|
|
37
|
+
"description": "Link to the source as the search returned it, never one carrying credentials"
|
|
38
|
+
},
|
|
39
|
+
"text": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"maxLength": 2000,
|
|
42
|
+
"description": "Snippet or faithful excerpt from the source, not a full page or a model-written answer"
|
|
43
|
+
},
|
|
44
|
+
"metadata": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"additionalProperties": true,
|
|
47
|
+
"description": "Metadata from the original result, such as the publication date; never credentials or UI details"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"required": [
|
|
51
|
+
"title",
|
|
52
|
+
"url"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"description": "Already retrieved results, in the order to display. No new search is performed."
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"required": [
|
|
59
|
+
"results"
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
export const RENDER_OUTPUT_SCHEMA = {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"additionalProperties": false,
|
|
65
|
+
"properties": {
|
|
66
|
+
"title": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"minLength": 1,
|
|
69
|
+
"maxLength": 120
|
|
70
|
+
},
|
|
71
|
+
"total": {
|
|
72
|
+
"type": "integer",
|
|
73
|
+
"minimum": 0,
|
|
74
|
+
"maximum": 50,
|
|
75
|
+
"description": "Number of results in this rendered list, not a provider-wide search total."
|
|
76
|
+
},
|
|
77
|
+
"results": {
|
|
78
|
+
"type": "array",
|
|
79
|
+
"minItems": 0,
|
|
80
|
+
"maxItems": 50,
|
|
81
|
+
"items": {
|
|
82
|
+
"type": "object",
|
|
83
|
+
"additionalProperties": false,
|
|
84
|
+
"properties": {
|
|
85
|
+
"id": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"minLength": 1,
|
|
88
|
+
"maxLength": 2048,
|
|
89
|
+
"description": "The id from the original search result; the server falls back to the URL when there is none"
|
|
90
|
+
},
|
|
91
|
+
"title": {
|
|
92
|
+
"type": "string",
|
|
93
|
+
"minLength": 1,
|
|
94
|
+
"maxLength": 300,
|
|
95
|
+
"description": "Source title exactly as the search returned it; never invent or rewrite it"
|
|
96
|
+
},
|
|
97
|
+
"url": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"format": "uri",
|
|
100
|
+
"pattern": "^https?://",
|
|
101
|
+
"maxLength": 2048,
|
|
102
|
+
"description": "Link to the source as the search returned it, never one carrying credentials"
|
|
103
|
+
},
|
|
104
|
+
"text": {
|
|
105
|
+
"type": "string",
|
|
106
|
+
"maxLength": 2000,
|
|
107
|
+
"description": "Snippet or faithful excerpt from the source, not a full page or a model-written answer"
|
|
108
|
+
},
|
|
109
|
+
"metadata": {
|
|
110
|
+
"type": "object",
|
|
111
|
+
"additionalProperties": true,
|
|
112
|
+
"description": "Metadata from the original result, such as the publication date; never credentials or UI details"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"required": [
|
|
116
|
+
"id",
|
|
117
|
+
"title",
|
|
118
|
+
"url"
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"required": [
|
|
124
|
+
"title",
|
|
125
|
+
"total",
|
|
126
|
+
"results"
|
|
127
|
+
]
|
|
128
|
+
};
|
|
129
|
+
function invalid(field, message) {
|
|
130
|
+
throw new ProtocolError(INVALID_PARAMS, `${field}: ${message}`);
|
|
131
|
+
}
|
|
132
|
+
function object(value, field) {
|
|
133
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
134
|
+
invalid(field, "must be an object");
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function string(value, field, max, allowEmpty = false) {
|
|
138
|
+
if (typeof value !== "string")
|
|
139
|
+
invalid(field, "must be a string");
|
|
140
|
+
if (!allowEmpty && !value.trim())
|
|
141
|
+
invalid(field, "must not be blank");
|
|
142
|
+
if ([...value].length > max)
|
|
143
|
+
invalid(field, `must be at most ${max} characters`);
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
function keys(value, allowed, field) {
|
|
147
|
+
if (Object.keys(value).some(key => !allowed.includes(key)))
|
|
148
|
+
invalid(field, "contains an unsupported field");
|
|
149
|
+
}
|
|
150
|
+
/** Pure presentation: no URL fetches, storage, searches or balance charges. */
|
|
151
|
+
export async function handleRenderResults(args) {
|
|
152
|
+
const input = object(args, "arguments");
|
|
153
|
+
keys(input, ["title", "results"], "arguments");
|
|
154
|
+
let serialized;
|
|
155
|
+
try {
|
|
156
|
+
serialized = JSON.stringify(input);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
invalid("arguments", "must contain JSON data");
|
|
160
|
+
}
|
|
161
|
+
if (Buffer.byteLength(serialized, "utf8") > 65_536)
|
|
162
|
+
invalid("arguments", "must be at most 65536 UTF-8 bytes");
|
|
163
|
+
const title = input.title === undefined ? "Results" : string(input.title, "title", 120);
|
|
164
|
+
if (!Array.isArray(input.results))
|
|
165
|
+
invalid("results", "must be an array");
|
|
166
|
+
if (input.results.length > 50)
|
|
167
|
+
invalid("results", "must contain at most 50 results");
|
|
168
|
+
const results = input.results.map((value, index) => {
|
|
169
|
+
const field = `results[${index}]`;
|
|
170
|
+
const item = object(value, field);
|
|
171
|
+
keys(item, ["id", "title", "url", "text", "metadata"], field);
|
|
172
|
+
const title = string(item.title, `${field}.title`, 300);
|
|
173
|
+
const url = string(item.url, `${field}.url`, 2048);
|
|
174
|
+
let parsed;
|
|
175
|
+
try {
|
|
176
|
+
parsed = new URL(url);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
invalid(`${field}.url`, "must be an absolute HTTP(S) URL without credentials");
|
|
180
|
+
}
|
|
181
|
+
if (!/^https?:\/\//.test(url) || !parsed.hostname || parsed.username || parsed.password || /\s|[\u0000-\u001f\u007f]/u.test(url)) {
|
|
182
|
+
invalid(`${field}.url`, "must be an absolute HTTP(S) URL without credentials or whitespace");
|
|
183
|
+
}
|
|
184
|
+
const id = item.id === undefined ? url : string(item.id, `${field}.id`, 2048);
|
|
185
|
+
const text = item.text === undefined ? undefined : string(item.text, `${field}.text`, 2000, true);
|
|
186
|
+
const metadata = item.metadata === undefined ? undefined : object(item.metadata, `${field}.metadata`);
|
|
187
|
+
return { id, title, url, ...(text !== undefined && { text }), ...(metadata !== undefined && { metadata }) };
|
|
188
|
+
});
|
|
189
|
+
const text = results.length
|
|
190
|
+
? `${title}\n\n${results.map((item, index) => `${index + 1}. ${item.title}\nURL: ${item.url}${item.text ? `\nSnippet: ${item.text}` : ""}`).join("\n\n")}`
|
|
191
|
+
: `${title}\n\nNo results to display.`;
|
|
192
|
+
return { isError: false, structuredContent: { title, total: results.length, results }, content: [{ type: "text", text }] };
|
|
193
|
+
}
|
package/build/ui.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
// Built by `npm run build` in ui/, relative to build/ui.js.
|
|
6
|
+
const SEARCH_UI_PATH = join(dirname(fileURLToPath(import.meta.url)), "../ui/dist/index.html");
|
|
7
|
+
export function readSearchUi() {
|
|
8
|
+
return readFileSync(SEARCH_UI_PATH, "utf8");
|
|
9
|
+
}
|
|
10
|
+
function searchUiVersion() {
|
|
11
|
+
try {
|
|
12
|
+
return createHash("sha256")
|
|
13
|
+
.update(readSearchUi())
|
|
14
|
+
.update(JSON.stringify(SEARCH_UI_META))
|
|
15
|
+
.digest("hex").slice(0, 10);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
22
|
+
/**
|
|
23
|
+
* Directory listings omit the content-hashed view link. Copy metadata so
|
|
24
|
+
* shared runtime tool definitions stay intact.
|
|
25
|
+
*/
|
|
26
|
+
export function withoutUiMeta(tool) {
|
|
27
|
+
if (!tool._meta)
|
|
28
|
+
return tool;
|
|
29
|
+
const { ui: _ui, "ui/resourceUri": _legacy, ...meta } = tool._meta;
|
|
30
|
+
return { ...tool, _meta: meta };
|
|
31
|
+
}
|
|
32
|
+
// ChatGPT accepts an HTTPS origin; other hosts validate ui.domain differently.
|
|
33
|
+
// Keep this identity in the OpenAI alias so portable hosts choose their origin.
|
|
34
|
+
function uiDomain() {
|
|
35
|
+
const value = process.env.SEARCH1API_UI_DOMAIN ?? "https://mcp.search1api.com";
|
|
36
|
+
const url = new URL(value);
|
|
37
|
+
if (url.protocol !== "https:" || url.origin !== value) {
|
|
38
|
+
throw new Error("SEARCH1API_UI_DOMAIN must be an HTTPS origin without a path or credentials");
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
// Standard size-changed notifications remain authoritative once the view loads.
|
|
43
|
+
export const SEARCH_UI_META = {
|
|
44
|
+
ui: {
|
|
45
|
+
csp: { connectDomains: [], resourceDomains: ["https://icons.duckduckgo.com"] },
|
|
46
|
+
prefersBorder: true,
|
|
47
|
+
},
|
|
48
|
+
"openai/widgetDomain": uiDomain(),
|
|
49
|
+
"openai/ui": {
|
|
50
|
+
availableDisplayModes: ["inline"],
|
|
51
|
+
preferredDisplayMode: "inline",
|
|
52
|
+
},
|
|
53
|
+
// Optional hints supported by the current ChatGPT desktop host, not portable
|
|
54
|
+
// MCP Apps fields. The shared view measures 154px for both search and news.
|
|
55
|
+
// Reserve one result row initially and allow the internal toggle to shrink it.
|
|
56
|
+
"openai/widgetHeightHint": 154,
|
|
57
|
+
"openai/widgetMinFrameHeight": 0,
|
|
58
|
+
"openai/widgetDescription": "Search1API source cards with titles, domains, and links. Displays results passed to render_results; expanding sources does not run a search or consume credits.",
|
|
59
|
+
};
|
|
60
|
+
const version = searchUiVersion();
|
|
61
|
+
/**
|
|
62
|
+
* Reused source-card view. Version both HTML and metadata because hosts may
|
|
63
|
+
* cache the entire resource by URI, including its initial sizing hints.
|
|
64
|
+
* Without a UI build, render_results still returns its full text list.
|
|
65
|
+
*/
|
|
66
|
+
export const SEARCH_UI_URI = version
|
|
67
|
+
? `ui://search1api/web-search-${version}.html`
|
|
68
|
+
: undefined;
|
|
69
|
+
// Keep the deployed renderer link readable for hosts with cached tool metadata.
|
|
70
|
+
// The HTML contract is unchanged; only its host-specific sandbox hint changed.
|
|
71
|
+
export const SEARCH_UI_COMPAT_URIS = ["ui://search1api/web-search-135d050d9e.html"];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"isError": false,
|
|
3
|
+
"structuredContent": {
|
|
4
|
+
"title": "Search1API sources",
|
|
5
|
+
"total": 1,
|
|
6
|
+
"results": [
|
|
7
|
+
{
|
|
8
|
+
"id": "https://s1.dev/docs",
|
|
9
|
+
"title": "Search1API documentation",
|
|
10
|
+
"url": "https://s1.dev/docs",
|
|
11
|
+
"text": "Documentation for Search1API."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"content": [
|
|
16
|
+
{
|
|
17
|
+
"type": "text",
|
|
18
|
+
"text": "Search1API sources\n\n1. Search1API documentation\nURL: https://s1.dev/docs\nSnippet: Documentation for Search1API."
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "render_results input",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"additionalProperties": false,
|
|
6
|
+
"properties": {
|
|
7
|
+
"title": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"minLength": 1,
|
|
10
|
+
"maxLength": 120,
|
|
11
|
+
"description": "Optional human-readable list heading. Defaults to Results."
|
|
12
|
+
},
|
|
13
|
+
"results": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"minItems": 0,
|
|
16
|
+
"maxItems": 50,
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"properties": {
|
|
21
|
+
"id": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"minLength": 1,
|
|
24
|
+
"maxLength": 2048,
|
|
25
|
+
"description": "Copy the original result ID when available. If absent, the server uses its URL."
|
|
26
|
+
},
|
|
27
|
+
"title": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"minLength": 1,
|
|
30
|
+
"maxLength": 300,
|
|
31
|
+
"description": "Copy the source title; do not invent or rewrite factual source titles."
|
|
32
|
+
},
|
|
33
|
+
"url": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"format": "uri",
|
|
36
|
+
"pattern": "^https?://",
|
|
37
|
+
"maxLength": 2048,
|
|
38
|
+
"description": "Absolute HTTP(S) source URL, without embedded credentials."
|
|
39
|
+
},
|
|
40
|
+
"text": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"maxLength": 2000,
|
|
43
|
+
"description": "Optional source snippet or faithful excerpt, not a full page or model-written answer."
|
|
44
|
+
},
|
|
45
|
+
"metadata": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": true,
|
|
48
|
+
"description": "Optional original JSON source metadata. Do not put credentials or UI implementation details here."
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": [
|
|
52
|
+
"title",
|
|
53
|
+
"url"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"description": "Already retrieved results, in the order to display. No new search is performed."
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"required": [
|
|
60
|
+
"results"
|
|
61
|
+
]
|
|
62
|
+
}
|