search-knowledge-base
Query a knowledge base to retrieve relevant information using a specific ID and search term, with options to customize the number of results.
Instructions
Search a knowledge base for relevant information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| knowledgeBaseId | Yes | Knowledge base ID | |
| query | Yes | Search query | |
| resultCount | No | Number of results |
Implementation Reference
- src/index.ts:903-921 (handler)The asynchronous handler function for the 'search-knowledge-base' tool. It fetches an API key from environment variables, makes a POST request to the knowledge base query endpoint, handles errors, and returns the JSON response as text content.async ({ knowledgeBaseId, query, resultCount }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch( `${NWS_API_BASE}/api/v1/query-knowledge-base`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ knowledgeBaseId, query, resultCount }), } ); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:898-902 (schema)Input schema for the 'search-knowledge-base' tool using Zod validation: knowledgeBaseId (string), query (string), resultCount (optional number, default 5).{ knowledgeBaseId: z.string().describe("Knowledge base ID"), query: z.string().describe("Search query"), resultCount: z.number().optional().default(5).describe("Number of results"), },
- src/index.ts:895-922 (registration)Registration of the 'search-knowledge-base' tool on the MCP server using server.tool, including name, description, schema, and handler.server.tool( "search-knowledge-base", "Search a knowledge base for relevant information.", { knowledgeBaseId: z.string().describe("Knowledge base ID"), query: z.string().describe("Search query"), resultCount: z.number().optional().default(5).describe("Number of results"), }, async ({ knowledgeBaseId, query, resultCount }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch( `${NWS_API_BASE}/api/v1/query-knowledge-base`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ knowledgeBaseId, query, resultCount }), } ); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );