generate-agent-completion
Produce AI-generated text completions with tailored parameters such as agent ID, message arrays, and JSON parsing for customized responses in Dumpling AI MCP Server.
Instructions
Generate AI text completions with customizable parameters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agentId | Yes | Agent ID | |
| messages | Yes | Array of messages | |
| parseJson | No | Parse response as JSON | |
| threadId | No | Thread ID for conversation history |
Implementation Reference
- src/index.ts:873-891 (handler)The handler function for the 'generate-agent-completion' tool. It fetches completions from the Dumpling API endpoint using the provided messages, agentId, parseJson, and threadId parameters.async ({ messages, agentId, parseJson, threadId }) => { 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/agents/generate-completion`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ messages, agentId, parseJson, threadId }), } ); 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:860-872 (schema)Zod schema defining the input parameters for the 'generate-agent-completion' tool: messages (array of role/content objects), agentId (string), parseJson (optional boolean), threadId (optional string).{ messages: z .array( z.object({ role: z.enum(["user", "assistant"]), content: z.string() }) ) .describe("Array of messages"), agentId: z.string().describe("Agent ID"), parseJson: z.boolean().optional().describe("Parse response as JSON"), threadId: z .string() .optional() .describe("Thread ID for conversation history"), },
- src/index.ts:857-892 (registration)Registration of the 'generate-agent-completion' tool on the MCP server, including name, description, input schema, and inline handler function.server.tool( "generate-agent-completion", "Generate AI text completions with customizable parameters.", { messages: z .array( z.object({ role: z.enum(["user", "assistant"]), content: z.string() }) ) .describe("Array of messages"), agentId: z.string().describe("Agent ID"), parseJson: z.boolean().optional().describe("Parse response as JSON"), threadId: z .string() .optional() .describe("Thread ID for conversation history"), }, async ({ messages, agentId, parseJson, threadId }) => { 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/agents/generate-completion`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ messages, agentId, parseJson, threadId }), } ); 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) }] }; } );