This MCP (Model Context Protocol) server implementation enables integration between KoboldAI's text generation capabilities and MCP-compatible applications, featuring chat completion with memory persistence, OpenAI-compatible API endpoints, and Stable Diffusion integration.
Install the package using npm:
npm install kobold-mcp-server
The server can be configured using environment variables or by passing a configuration object when initializing:
import { KoboldMCPServer } from 'kobold-mcp-server';
// Basic initialization with defaults
const server = new KoboldMCPServer();
// Or with custom configuration
const config = {
apiUrl: 'http://localhost:5001' // KoboldAI API endpoint
};
const server = new KoboldMCPServer(config);
After configuring, start the server:
// Initialize and start the server
server.start();
import { KoboldMCPServer } from 'kobold-mcp-server';
const server = new KoboldMCPServer({
apiUrl: 'http://localhost:5001'
});
server.start();
The server supports chat completion with memory persistence, allowing for contextual conversations:
// Client-side example of using the chat completion API
const response = await fetch('http://your-server-address/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [
{ role: 'user', content: 'Hello, how are you?' }
],
model: 'your-kobold-model'
})
});
const result = await response.json();
The server also provides endpoints for image generation capabilities:
// Example of text-to-image request
const response = await fetch('http://your-server-address/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A beautiful sunset over mountains',
n: 1,
size: '512x512'
})
});
const images = await response.json();
For production deployments, you may want to configure additional parameters:
const config = {
apiUrl: 'http://your-kobold-instance:5001',
port: 3000, // Port to run the MCP server on
host: '0.0.0.0', // Host to bind to
enableLogging: true, // Enable detailed logging
maxContextLength: 2048 // Maximum context length for generation
};
const server = new KoboldMCPServer(config);
server.start();
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.