generate-agent-completion
Generate AI text completions using customizable parameters like agent selection and conversation history for tailored responses.
Instructions
Generate AI text completions with customizable parameters.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"messages": "<messages>",
"agentId": "<agentId>"
},
"name": "generate-agent-completion"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messages | Yes | Array of messages | |
| agentId | Yes | Agent ID | |
| parseJson | No | Parse response as JSON | |
| threadId | No | Thread ID for conversation history |
Implementation Reference
- src/index.ts:873-891 (handler)The async handler function that executes the tool logic by making a POST request to the external Dumpling AI API endpoint `/api/v1/agents/generate-completion` with the provided parameters and returns the JSON response formatted as MCP content.
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 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)The server.tool registration call that defines and registers the 'generate-agent-completion' tool with its name, description, input schema, and 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) }] }; } );