search1api-mcp 0.7.1 → 0.8.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 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
@@ -230,3 +240,9 @@ Agentic search: describe the need in natural language and Search1API picks up to
230
240
  ## License
231
241
 
232
242
  MIT
243
+
244
+ ## UI and third-party credits
245
+
246
+ 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).
247
+
248
+ 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,11 @@
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
+ ];
package/build/http.js CHANGED
@@ -7,6 +7,7 @@ import express from "express";
7
7
  import { createMcpServer, unauthenticatedCredential, UNAUTHENTICATED, } from "./server.js";
8
8
  import { ALL_TOOLS } from "./tools/index.js";
9
9
  import { PACKAGE_VERSION } from "./version.js";
10
+ import { SERVER_ICON_FILE, SERVER_ICON_PATH, SERVER_ICONS } from "./branding.js";
10
11
  import { log } from "./utils.js";
11
12
  const API_BASE_URL = process.env.SEARCH1API_API_URL || "https://api.search1api.com";
12
13
  const DEFAULT_AUTHORIZATION_SERVER = "https://clerk.s1.dev";
@@ -78,10 +79,10 @@ export function createHttpApp(options = {}) {
78
79
  }
79
80
  next();
80
81
  });
81
- // The service root is documentation, not an MCP transport endpoint. Keep
82
+ // The service root points to the MCP product page. Keep
82
83
  // query parameters so bookmarked campaign/support links remain attributable.
83
84
  app.get("/", (req, res) => {
84
- const target = new URL("https://s1.dev/docs/integrations/mcp");
85
+ const target = new URL("https://s1.dev/mcp-server");
85
86
  for (const [key, value] of Object.entries(req.query)) {
86
87
  if (typeof value === "string") {
87
88
  target.searchParams.append(key, value);
@@ -100,6 +101,13 @@ export function createHttpApp(options = {}) {
100
101
  app.get("/.well-known/openai-apps-challenge", (_req, res) => {
101
102
  res.type("text/plain").send(OPENAI_APPS_CHALLENGE_TOKEN);
102
103
  });
104
+ // MCP clients fetch implementation icons without cookies or credentials.
105
+ app.get(SERVER_ICON_PATH, (_req, res) => {
106
+ res
107
+ .set("Cache-Control", "public, max-age=3600")
108
+ .type("image/png")
109
+ .sendFile(SERVER_ICON_FILE);
110
+ });
103
111
  // OIDC scopes such as openid and offline_access belong to the client/AS
104
112
  // exchange; this resource does not require any resource-specific scope.
105
113
  const protectedResourceMetadata = {
@@ -129,6 +137,7 @@ export function createHttpApp(options = {}) {
129
137
  .json({
130
138
  name: "Search1API",
131
139
  version: PACKAGE_VERSION,
140
+ icons: SERVER_ICONS,
132
141
  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
142
  serverUrl: MCP_RESOURCE,
134
143
  tools: ALL_TOOLS.map((tool) => ({
@@ -142,6 +151,7 @@ export function createHttpApp(options = {}) {
142
151
  name: "Search1API",
143
152
  title: "Search1API MCP",
144
153
  version: PACKAGE_VERSION,
154
+ icons: SERVER_ICONS,
145
155
  },
146
156
  protocolVersion: "2025-06-18",
147
157
  transport: { type: "streamable-http", endpoint: MCP_RESOURCE },
package/build/server.js CHANGED
@@ -2,8 +2,10 @@ import { INTERNAL_ERROR, McpServer, ProtocolError, fromJsonSchema, } from "@mode
2
2
  import { handleReadResource, RESOURCES } from "./resources.js";
3
3
  import { handleToolCall } from "./tools/handlers.js";
4
4
  import { ALL_TOOLS } from "./tools/index.js";
5
+ import { MCP_APP_MIME_TYPE, SEARCH_UI_META, SEARCH_UI_URI, SEARCH_UI_COMPAT_URIS, readSearchUi, } from "./ui.js";
5
6
  import { formatError, log } from "./utils.js";
6
7
  import { PACKAGE_VERSION } from "./version.js";
8
+ import { SERVER_ICONS } from "./branding.js";
7
9
  /** JSON-RPC error code this server uses for a missing or rejected credential. */
8
10
  export const UNAUTHENTICATED = -32001;
9
11
  /**
@@ -24,13 +26,11 @@ export function unauthenticatedCredential(message) {
24
26
  *
25
27
  * The v2 serving entries call this factory once per modern HTTP exchange,
26
28
  * once per stateless legacy HTTP request, or once per stdio connection.
29
+ * All transports expose the same data tools and optional rendering tool.
27
30
  */
28
31
  export function createMcpServer(credential) {
29
32
  log("Creating Search1API MCP server");
30
- const server = new McpServer({
31
- name: "search1api-server",
32
- version: PACKAGE_VERSION,
33
- });
33
+ const server = new McpServer({ name: "search1api-server", version: PACKAGE_VERSION, icons: SERVER_ICONS }, { 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
34
  for (const tool of ALL_TOOLS) {
35
35
  const inputSchema = fromJsonSchema(tool.inputSchema);
36
36
  const outputSchema = tool.outputSchema
@@ -76,6 +76,32 @@ export function createMcpServer(credential) {
76
76
  }
77
77
  });
78
78
  }
79
+ if (SEARCH_UI_URI) {
80
+ for (const resourceUri of [SEARCH_UI_URI, ...SEARCH_UI_COMPAT_URIS]) {
81
+ server.registerResource(resourceUri === SEARCH_UI_URI ? "search-ui" : "search-ui-compat", resourceUri, {
82
+ title: "Source results view",
83
+ description: "Interactive view of already retrieved source results",
84
+ mimeType: MCP_APP_MIME_TYPE,
85
+ _meta: SEARCH_UI_META,
86
+ }, async (uri) => {
87
+ try {
88
+ return {
89
+ contents: [
90
+ {
91
+ uri: uri.href,
92
+ mimeType: MCP_APP_MIME_TYPE,
93
+ text: readSearchUi(),
94
+ _meta: SEARCH_UI_META,
95
+ },
96
+ ],
97
+ };
98
+ }
99
+ catch (error) {
100
+ throw normalizeProtocolError("reading search UI", error);
101
+ }
102
+ });
103
+ }
104
+ }
79
105
  return server;
80
106
  }
81
107
  function normalizeProtocolError(context, error) {
@@ -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}`);
@@ -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.
@@ -62,7 +64,7 @@ const SEARCH_OUTPUT_SCHEMA = {
62
64
  // Search tool definition
63
65
  export const SEARCH_TOOL = {
64
66
  name: "search",
65
- title: "Search the web",
67
+ title: "Web search",
66
68
  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
69
  ...AUTHENTICATED_READ_ONLY_WEB,
68
70
  inputSchema: {
@@ -123,11 +125,16 @@ export const SEARCH_TOOL = {
123
125
  required: ["query"],
124
126
  },
125
127
  outputSchema: SEARCH_OUTPUT_SCHEMA,
128
+ _meta: {
129
+ ...AUTHENTICATED_READ_ONLY_WEB._meta,
130
+ "openai/toolInvocation/invoking": "Searching the web…",
131
+ "openai/toolInvocation/invoked": "Search results",
132
+ },
126
133
  };
127
134
  // News tool definition
128
135
  export const NEWS_TOOL = {
129
136
  name: "news",
130
- title: "Search current news",
137
+ title: "News search",
131
138
  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
139
  ...AUTHENTICATED_READ_ONLY_WEB,
133
140
  inputSchema: {
@@ -181,6 +188,11 @@ export const NEWS_TOOL = {
181
188
  required: ["query"],
182
189
  },
183
190
  outputSchema: SEARCH_OUTPUT_SCHEMA,
191
+ _meta: {
192
+ ...AUTHENTICATED_READ_ONLY_WEB._meta,
193
+ "openai/toolInvocation/invoking": "Searching news…",
194
+ "openai/toolInvocation/invoked": "News results",
195
+ },
184
196
  };
185
197
  // Crawl tool definition
186
198
  export const CRAWL_TOOL = {
@@ -335,6 +347,21 @@ export const ASK_TOOL = {
335
347
  required: ["intent", "results", "errors"],
336
348
  },
337
349
  };
350
+ export const RENDER_RESULTS_TOOL = {
351
+ name: "render_results",
352
+ title: "Render the results",
353
+ 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.",
354
+ ...AUTHENTICATED_READ_ONLY_WEB,
355
+ annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false, idempotentHint: true },
356
+ inputSchema: RENDER_INPUT_SCHEMA,
357
+ outputSchema: RENDER_OUTPUT_SCHEMA,
358
+ _meta: {
359
+ ...AUTHENTICATED_READ_ONLY_WEB._meta,
360
+ "openai/toolInvocation/invoking": "Preparing results…",
361
+ "openai/toolInvocation/invoked": "Results ready",
362
+ ...(SEARCH_UI_URI && { ui: { resourceUri: SEARCH_UI_URI, visibility: ["model", "app"] } }),
363
+ },
364
+ };
338
365
  export const ALL_TOOLS = [
339
366
  SEARCH_TOOL,
340
367
  NEWS_TOOL,
@@ -342,4 +369,5 @@ export const ALL_TOOLS = [
342
369
  SITEMAP_TOOL,
343
370
  TRENDING_TOOL,
344
371
  ASK_TOOL,
372
+ RENDER_RESULTS_TOOL,
345
373
  ];
@@ -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": "Optional human-readable list heading. Defaults to Results."
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": "Copy the original result ID when available. If absent, the server uses its URL."
25
+ },
26
+ "title": {
27
+ "type": "string",
28
+ "minLength": 1,
29
+ "maxLength": 300,
30
+ "description": "Copy the source title; do not invent or rewrite factual source titles."
31
+ },
32
+ "url": {
33
+ "type": "string",
34
+ "format": "uri",
35
+ "pattern": "^https?://",
36
+ "maxLength": 2048,
37
+ "description": "Absolute HTTP(S) source URL, without embedded credentials."
38
+ },
39
+ "text": {
40
+ "type": "string",
41
+ "maxLength": 2000,
42
+ "description": "Optional source snippet or faithful excerpt, not a full page or model-written answer."
43
+ },
44
+ "metadata": {
45
+ "type": "object",
46
+ "additionalProperties": true,
47
+ "description": "Optional original JSON source metadata. Do not put credentials or UI implementation details here."
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": "Copy the original result ID when available. If absent, the server uses its URL."
90
+ },
91
+ "title": {
92
+ "type": "string",
93
+ "minLength": 1,
94
+ "maxLength": 300,
95
+ "description": "Copy the source title; do not invent or rewrite factual source titles."
96
+ },
97
+ "url": {
98
+ "type": "string",
99
+ "format": "uri",
100
+ "pattern": "^https?://",
101
+ "maxLength": 2048,
102
+ "description": "Absolute HTTP(S) source URL, without embedded credentials."
103
+ },
104
+ "text": {
105
+ "type": "string",
106
+ "maxLength": 2000,
107
+ "description": "Optional source snippet or faithful excerpt, not a full page or model-written answer."
108
+ },
109
+ "metadata": {
110
+ "type": "object",
111
+ "additionalProperties": true,
112
+ "description": "Optional original JSON source metadata. Do not put credentials or UI implementation details here."
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,11 @@
1
+ {
2
+ "title": "Search1API sources",
3
+ "results": [
4
+ {
5
+ "id": "https://s1.dev/docs",
6
+ "title": "Search1API documentation",
7
+ "url": "https://s1.dev/docs",
8
+ "text": "Documentation for Search1API."
9
+ }
10
+ ]
11
+ }
@@ -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
+ }