kobold_generate
Generate text content using KoboldAI's language model by providing prompts and adjusting parameters like length, temperature, and context.
Instructions
Generate text with KoboldAI
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": {
"prompt": "<prompt>"
},
"name": "kobold_generate"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiUrl | No | http://localhost:5001 | |
| prompt | Yes | ||
| max_length | No | ||
| max_context_length | No | ||
| temperature | No | ||
| top_p | No | ||
| top_k | No | ||
| repetition_penalty | No | ||
| stop_sequence | No | ||
| seed | No |
Implementation Reference
- src/index.ts:346-357 (handler)Handler logic for POST-based tools like kobold_generate: validates arguments using the tool's schema, then forwards the request via HTTP POST to the specified KoboldAI API endpoint and returns the JSON response.
if (postEndpoints[name]) { const { endpoint, schema } = postEndpoints[name]; const parsed = schema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments: ${parsed.error}`); } const result = await makeRequest(`${apiUrl}${endpoint}`, 'POST', requestData); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: false, }; - src/index.ts:18-28 (schema)Zod schema defining the input parameters for the kobold_generate tool, including prompt and various generation options.
const GenerateSchema = BaseConfigSchema.extend({ prompt: z.string(), max_length: z.number().optional(), max_context_length: z.number().optional(), temperature: z.number().optional(), top_p: z.number().optional(), top_k: z.number().optional(), repetition_penalty: z.number().optional(), stop_sequence: z.array(z.string()).optional(), seed: z.number().optional(), }); - src/index.ts:177-181 (registration)Tool registration in the listTools response, specifying name, description, and input schema.
{ name: "kobold_generate", description: "Generate text with KoboldAI", inputSchema: zodToJsonSchema(GenerateSchema), }, - src/index.ts:332-332 (registration)Endpoint mapping for kobold_generate in the POST dispatch table, linking tool name to API path and schema.
kobold_generate: { endpoint: '/api/v1/generate', schema: GenerateSchema }, - src/index.ts:146-162 (helper)Helper function that performs HTTP requests to the KoboldAI API, used by the tool handlers.
async function makeRequest(url: string, method = 'GET', body: Record<string, unknown> | null = null) { const options: RequestInit = { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, }; if (body && method !== 'GET') { options.body = JSON.stringify(body); } const response = await fetch(url, options); if (!response.ok) { throw new Error(`KoboldAI API error: ${response.statusText}`); } return response.json(); }