MCP Support in OpenKBS

December 21, 2025
OpenKBS + MCP Integration
While OpenKBS provides full control over context and custom tool syntax, MCP (Model Context Protocol) has become the de facto standard for AI tool integration. With MCP support, OpenKBS auto-discovers tools from any MCP server and generates context automatically - tool names, descriptions, and parameter schemas are injected into the system prompt without manual documentation.

Connect Any MCP Server

app/settings.json:
{
"options": {
"mcpServerUrl": "https://your-mcp-server.com",
"mcpServers": {
"your-server": {}
}
}
}
Use any MCP-compatible endpoint. See MCP server list.

SDK

await openkbs.mcp.callTool('your-server', 'tool_name', { ...args });
await openkbs.mcp.listTools('your-server');
await openkbs.mcp.listServers();

How It Works

1. On first chat, OpenKBS calls tools/list on each MCP server
2. Tool schemas (names, descriptions, parameters) are injected into system prompt
3. Agent outputs: <mcp_{server}_{tool}>{JSON}</mcp_{server}_{tool}>
4. Handler calls openkbs.mcp.callTool()

Caching

Tool schemas are cached for 24 hours to avoid repeated discovery calls.

Cache auto-refreshes when:
• 24 hours passed
mcpServers config changed (add/remove servers)
mcpServerUrl changed

Update your config → new tools discovered on next chat. No restart needed.

Handler

A single universal handler in src/Events/actions.js enables all MCP tools from one place:
[/<mcp_([a-z0-9-]+)_([a-z0-9_]+)>([\s\S]*?)<\/mcp_\1_\2>/s, async (match) => {
try {
const server = match[1];
const toolName = match[2];
const args = match[3].trim() ? JSON.parse(match[3].trim()) : {};
const result = await openkbs.mcp.callTool(server, toolName, args);
return {
type: 'MCP_RESULT',
server,
tool: toolName,
data: result?.content || [],
_meta_actions: ['REQUEST_CHAT_MODEL']
};
} catch (e) {
return {
type: 'MCP_ERROR',
error: e.message,
_meta_actions: ['REQUEST_CHAT_MODEL']
};
}
}]

Note: This handler is included in the default OpenKBS app template. New agents created via Create App have it already. Older agents created before MCP integration may need to add this handler to their actions.js manually.
Plamen Petrov
Plamen Petrov
Founder & CEO
Early GPT advocate who began implementing agentic systems in 2022. Developed OpenKBS vision through continuous experimentation with cutting-edge LLMs.