kobold_chat
Enable chat completion through OpenAI-compatible API integration, allowing dynamic text generation and conversation handling with customizable parameters for temperature, max tokens, and more.
Instructions
Chat completion (OpenAI-compatible)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiUrl | No | http://localhost:5001 | |
| max_tokens | No | ||
| messages | Yes | ||
| stop | No | ||
| temperature | No | ||
| top_p | No |
Implementation Reference
- src/index.ts:278-305 (handler)Executes the kobold_chat tool: maintains in-memory chat history, appends new messages, sends request to KoboldAI /v1/chat/completions endpoint with full history, appends response to history, and returns the result.if (name === 'kobold_chat') { // Add new messages to chat history const newMessages = (requestData as any).messages || []; chatHistory.push(...newMessages); // Get last 4 messages const recentMessages = chatHistory.slice(-4); console.error('Last 4 messages in chat:'); console.error(JSON.stringify(recentMessages, null, 2)); // Make the API request with all context const result = await makeRequest( `${apiUrl}/v1/chat/completions`, 'POST', { ...requestData, messages: chatHistory } ); // Add assistant's response to history const typedResult = result as any; if (typedResult.choices?.[0]?.message) { chatHistory.push(typedResult.choices[0].message); } return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: false, }; }
- src/index.ts:102-111 (schema)Zod schema defining input parameters for kobold_chat tool, extending BaseConfigSchema with messages array, temperature, top_p, max_tokens, and stop sequences.const ChatCompletionSchema = BaseConfigSchema.extend({ messages: z.array(z.object({ role: z.enum(['system', 'user', 'assistant']), content: z.string(), })), temperature: z.number().optional(), top_p: z.number().optional(), max_tokens: z.number().optional(), stop: z.array(z.string()).optional(), });
- src/index.ts:260-264 (registration)Registers the kobold_chat tool in the MCP server's listTools response with name, description, and input schema reference.{ name: "kobold_chat", description: "Chat completion (OpenAI-compatible)", inputSchema: zodToJsonSchema(ChatCompletionSchema), },
- src/index.ts:37-40 (helper)In-memory array storing chat history (system/user/assistant messages) specifically used by the kobold_chat handler.const chatHistory: Array<{ role: 'system' | 'user' | 'assistant', content: string }> = [];