Skip to main content
Glama

kobold_chat

Generate text responses using KoboldAI's chat completion capabilities through an OpenAI-compatible API interface for conversational AI applications.

Instructions

Chat completion (OpenAI-compatible)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiUrlNohttp://localhost:5001
messagesYes
temperatureNo
top_pNo
max_tokensNo
stopNo

Implementation Reference

  • Implementation of the kobold_chat tool handler: appends incoming messages to in-memory chat history, sends full history to KoboldAI /v1/chat/completions endpoint (overriding with full history), adds response to history, and returns the API response as text.
    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,
        };
    }
  • Zod input schema for kobold_chat tool: OpenAI-compatible chat completion parameters including messages array and optional sampling params.
    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)
    Registration of the kobold_chat tool in the ListTools response, referencing its schema.
    {
        name: "kobold_chat",
        description: "Chat completion (OpenAI-compatible)",
        inputSchema: zodToJsonSchema(ChatCompletionSchema),
    },
  • Global in-memory chat history array used exclusively by the kobold_chat handler to maintain conversation context.
    const chatHistory: Array<{
        role: 'system' | 'user' | 'assistant',
        content: string
    }> = [];
    // Generate check schemas

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PhialsBasement/KoboldCPP-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server