getKnowledgeBase
Retrieve structured knowledge base entries using a unique ID to access and manage information efficiently within the MCP-Smallest.ai system.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- index.ts:85-110 (handler)Handler function that retrieves a specific knowledge base by ID from the Smallest.ai API via HTTP GET request, returning formatted JSON details or an error message.async (args) => { try { const response = await fetch(`${config.BASE_URL}/knowledgebase/${args.id}`, { method: 'GET', headers: { 'Authorization': `Bearer ${config.API_KEY}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; console.error('Error fetching knowledge base:', error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } }
- index.ts:82-84 (schema)Zod input schema defining the required 'id' parameter as a string for the getKnowledgeBase tool.{ id: z.string() },
- index.ts:80-111 (registration)MCP server registration of the 'getKnowledgeBase' tool, specifying input schema and handler function.server.tool( "getKnowledgeBase", { id: z.string() }, async (args) => { try { const response = await fetch(`${config.BASE_URL}/knowledgebase/${args.id}`, { method: 'GET', headers: { 'Authorization': `Bearer ${config.API_KEY}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; console.error('Error fetching knowledge base:', error); return { content: [{ type: "text", text: `Error: ${errorMessage}` }], isError: true }; } } );
- config.ts:1-4 (helper)Exported configuration constants used by the tool handler for API endpoint and authentication.export const config = { API_KEY: 'smallest-ai-api-key', BASE_URL: 'https://atoms-api.smallest.ai/api/v1' };