add-to-knowledge-base
Add text resources to a knowledge base for organizing and storing information within Dumpling AI's knowledge management system.
Instructions
Add new text resources to a knowledge base.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| knowledgeBaseId | Yes | Knowledge base ID | |
| name | Yes | Resource name | |
| content | Yes | Text content to add |
Implementation Reference
- src/index.ts:933-948 (handler)Handler function that executes the tool by sending a POST request to the external API endpoint to add text resources to a specified knowledge base.async ({ knowledgeBaseId, name, content }) => { 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/knowledge-bases/add`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ knowledgeBaseId, name, content }), }); 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:929-932 (schema)Zod schema defining the input parameters for the tool: knowledgeBaseId, name, and content.knowledgeBaseId: z.string().describe("Knowledge base ID"), name: z.string().describe("Resource name"), content: z.string().describe("Text content to add"), },
- src/index.ts:925-949 (registration)Registration of the 'add-to-knowledge-base' tool using server.tool(), including description, input schema, and handler function.server.tool( "add-to-knowledge-base", "Add new text resources to a knowledge base.", { knowledgeBaseId: z.string().describe("Knowledge base ID"), name: z.string().describe("Resource name"), content: z.string().describe("Text content to add"), }, async ({ knowledgeBaseId, name, content }) => { 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/knowledge-bases/add`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ knowledgeBaseId, name, content }), }); 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) }] }; } );