search1api-mcp 0.3.0 → 0.3.1

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 CHANGED
@@ -4,23 +4,26 @@
4
4
 
5
5
  The official MCP server for [Search1API](https://www.search1api.com/?utm_source=mcp) — web search, news, crawling, and more in one API.
6
6
 
7
- ## Get Your API Key
7
+ ## Authentication
8
8
 
9
- 1. Register at [Search1API](https://www.search1api.com/?utm_source=mcp)
10
- 2. Get your API key from the dashboard
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. Just configure your MCP client with the remote URL and your API key.
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
- Two methods are supported — use whichever your client supports:
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:
@@ -155,13 +167,6 @@ Get all related links from a URL.
155
167
  |-----------|----------|-------------|
156
168
  | `url` | Yes | URL to get sitemap |
157
169
 
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
170
  ### trending
166
171
  Get trending topics from popular platforms.
167
172
 
@@ -172,13 +177,13 @@ Get trending topics from popular platforms.
172
177
 
173
178
  ## Version History
174
179
 
180
+ - v0.3.1: OAuth 2.1 support for Remote MCP; retired reasoning tool removed
175
181
  - v0.3.0: Remote MCP support via Streamable HTTP; per-session API key authentication
176
182
  - v0.2.0: Fallback `.env` support for LibreChat integration
177
183
  - v0.1.8: X (Twitter) and Reddit search services
178
184
  - v0.1.7: Trending tool for GitHub and Hacker News
179
185
  - v0.1.6: Wikipedia search service
180
186
  - v0.1.5: New search parameters and services (arxiv, wechat, bilibili, imdb)
181
- - v0.1.4: Reasoning tool with DeepSeek R1
182
187
  - v0.1.3: News search
183
188
  - v0.1.2: Sitemap
184
189
  - v0.1.1: Web crawling
package/build/config.js CHANGED
@@ -41,7 +41,6 @@ export const API_CONFIG = {
41
41
  CRAWL: '/crawl',
42
42
  SITEMAP: '/sitemap',
43
43
  NEWS: '/news',
44
- REASONING: '/v1/chat/completions',
45
44
  TRENDING: '/trending'
46
45
  }
47
46
  };
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 → { transport, server }
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
- * Extract API key from request: Authorization header > URL query parameter
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
- * Check if a JSON-RPC request body is an initialize request
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((msg) => typeof msg === "object" && msg !== null && msg.method === "initialize");
131
+ return body.some((message) => typeof message === "object" &&
132
+ message !== null &&
133
+ message.method === "initialize");
33
134
  }
34
- return typeof body === "object" && body !== null && body.method === "initialize";
135
+ return (typeof body === "object" &&
136
+ body !== null &&
137
+ body.method === "initialize");
35
138
  }
36
- // Handle POST /mcp — initialize or route to existing session
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 apiKey = extractApiKey(req);
48
- if (!apiKey) {
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, { transport, server });
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(apiKey);
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: { code: -32600, message: "Bad request: no valid session or not an initialize request" },
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 — SSE stream for existing session
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
- await sessions.get(sessionId).transport.handleRequest(req, res);
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 — session termination
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
- else {
107
- res.status(400).json({
108
- jsonrpc: "2.0",
109
- error: { code: -32600, message: "Invalid or missing session ID" },
110
- id: null,
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 apiKey Optional per-session API key (used in HTTP mode)
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(apiKey) {
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: "1.0.0"
19
+ version: PACKAGE_VERSION
17
20
  }, {
18
21
  capabilities: {
19
22
  resources: {},
20
23
  tools: {}
21
24
  }
22
25
  });
23
- setupRequestHandlers(server, apiKey);
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, apiKey) {
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
- return await handleToolCall(toolName, toolArgs, apiKey);
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);
@@ -4,9 +4,8 @@ import { handleSearch } from './search.js';
4
4
  import { handleCrawl } from './crawl.js';
5
5
  import { handleSitemap } from './sitemap.js';
6
6
  import { handleNews } from './news.js';
7
- import { handleReasoning } from './reasoning.js';
8
7
  import { handleTrending } from './trending.js';
9
- import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL, TRENDING_TOOL } from './index.js';
8
+ import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, TRENDING_TOOL } from './index.js';
10
9
  /**
11
10
  * Dispatch request based on tool name
12
11
  * @param toolName Name of the tool
@@ -25,8 +24,6 @@ export async function handleToolCall(toolName, args, apiKey) {
25
24
  return await handleSitemap(args, apiKey);
26
25
  case NEWS_TOOL.name:
27
26
  return await handleNews(args, apiKey);
28
- case REASONING_TOOL.name:
29
- return await handleReasoning(args, apiKey);
30
27
  case TRENDING_TOOL.name:
31
28
  return await handleTrending(args, apiKey);
32
29
  default:
@@ -132,21 +132,6 @@ export const SITEMAP_TOOL = {
132
132
  required: ["url"]
133
133
  }
134
134
  };
135
- // Reasoning tool definition
136
- export const REASONING_TOOL = {
137
- name: "reasoning",
138
- description: "Deep thinking and complex problem solving",
139
- inputSchema: {
140
- type: "object",
141
- properties: {
142
- content: {
143
- type: "string",
144
- description: "The question or problem that needs deep thinking"
145
- }
146
- },
147
- required: ["content"]
148
- }
149
- };
150
135
  // Trending tool definition
151
136
  export const TRENDING_TOOL = {
152
137
  name: "trending",
@@ -175,6 +160,5 @@ export const ALL_TOOLS = [
175
160
  NEWS_TOOL,
176
161
  CRAWL_TOOL,
177
162
  SITEMAP_TOOL,
178
- REASONING_TOOL,
179
163
  TRENDING_TOOL
180
164
  ];
package/build/types.js CHANGED
@@ -116,16 +116,6 @@ export function isValidNewsArgs(args) {
116
116
  }
117
117
  return true;
118
118
  }
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
119
  export var TrendingService;
130
120
  (function (TrendingService) {
131
121
  TrendingService["GITHUB"] = "github";
@@ -0,0 +1,4 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ const packageJson = require("../package.json");
4
+ export const PACKAGE_VERSION = packageJson.version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search1api-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A Model Context Protocol (MCP) server that provides search and crawl functionality using Search1API",
5
5
  "private": false,
6
6
  "type": "module",
@@ -11,22 +11,23 @@
11
11
  "build"
12
12
  ],
13
13
  "scripts": {
14
- "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\" && node -e \"if (!require('fs').existsSync('.env.example')) { require('fs').writeFileSync('.env.example', '# Search1API Configuration\\n# Get your API key from https://www.search1api.com/?utm_source=mcp\\nSEARCH1API_KEY=your_api_key_here\\n') }\"",
14
+ "build": "node -e \"require('node:fs').rmSync('build', { recursive: true, force: true })\" && tsc && node -e \"require('node:fs').chmodSync('build/index.js', '755')\"",
15
+ "test": "npm run build && node --test tests/*.test.mjs",
15
16
  "start": "node build/http.js",
16
- "prepare": "npm run build",
17
+ "prepack": "npm run build",
17
18
  "watch": "tsc --watch",
18
19
  "inspector": "npx @modelcontextprotocol/inspector build/index.js",
19
20
  "start:http": "node build/http.js"
20
21
  },
21
22
  "dependencies": {
22
- "@modelcontextprotocol/sdk": "^1.12.0",
23
- "dotenv": "^16.4.5",
24
- "express": "^4.21.0"
23
+ "@modelcontextprotocol/sdk": "^1.29.0",
24
+ "dotenv": "^16.6.1",
25
+ "express": "^4.22.2"
25
26
  },
26
27
  "devDependencies": {
27
- "@types/express": "^5.0.0",
28
- "@types/node": "^20.11.24",
29
- "typescript": "^5.3.3"
28
+ "@types/express": "^5.0.6",
29
+ "@types/node": "^20.19.43",
30
+ "typescript": "^5.9.3"
30
31
  },
31
32
  "keywords": [
32
33
  "mcp",
@@ -36,11 +37,18 @@
36
37
  "google",
37
38
  "search1api"
38
39
  ],
39
- "author": "fatwang2",
40
+ "author": "Search1API",
40
41
  "license": "MIT",
41
42
  "repository": {
42
43
  "type": "git",
43
- "url": "git+https://github.com/fatwang2/search1api-mcp.git"
44
+ "url": "git+https://github.com/superagents-lab/search1api-mcp.git"
45
+ },
46
+ "homepage": "https://github.com/superagents-lab/search1api-mcp#readme",
47
+ "bugs": {
48
+ "url": "https://github.com/superagents-lab/search1api-mcp/issues"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
44
52
  },
45
53
  "engines": {
46
54
  "node": ">=18.0.0"
@@ -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
- }