answers
Search the web to answer questions and return structured JSON data with sources and citations for research and analysis.
Instructions
Search the web and return AI-powered answers in the JSON structure you want, with sources and citations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | Question or task to answer using web data. | |
| json | No | Optional JSON schema/object or a short description of the desired output shape. Example object: { "book_title": "", "author": "", "release_date": "" } |
Implementation Reference
- src/tools/answers.ts:29-90 (handler)The handler function executes the core logic of the 'answers' tool by sending a POST request to the Olostep Answers API with the task and optional JSON schema, processing the response, and returning formatted content or error messages.handler: async ( { task, json }: { task: string; json?: Record<string, unknown> | string }, apiKey: string, ) => { try { const headers = new Headers({ "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }); const payload: Record<string, unknown> = { task }; if (typeof json !== "undefined") { payload.json = json; } const response = await fetch(OLOSTEP_ANSWERS_API_URL, { method: "POST", headers, body: JSON.stringify(payload), }); if (!response.ok) { let errorDetails: unknown = null; try { errorDetails = await response.json(); } catch { // ignore } return { isError: true, content: [ { type: "text", text: `Olostep API Error: ${response.status} ${response.statusText}. Details: ${JSON.stringify( errorDetails, )}`, }, ], }; } const data = (await response.json()) as OlostepAnswersResponse; return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error: unknown) { return { isError: true, content: [ { type: "text", text: `Error: Failed to get answer. ${error instanceof Error ? error.message : String(error)}`, }, ], }; } },
- src/tools/answers.ts:20-28 (schema)The input schema for the 'answers' tool, defining 'task' as required string and 'json' as optional union of string or object for output shaping.schema: { task: z.string().describe("Question or task to answer using web data."), json: z .union([z.string(), z.record(z.any())]) .optional() .describe( 'Optional JSON schema/object or a short description of the desired output shape. Example object: { "book_title": "", "author": "", "release_date": "" }', ), },
- src/index.ts:88-100 (registration)The registration of the 'answers' tool on the MCP server using server.tool(), including API key check and wrapper for the handler.// Register Answers (AI) tool server.tool( answers.name, answers.description, answers.schema, async (params) => { if (!OLOSTEP_API_KEY) return missingApiKeyError; const result = await answers.handler(params, OLOSTEP_API_KEY); return { ...result, content: result.content.map(item => ({ ...item, type: item.type as "text" })) }; }