Kognita
All posts
Tutorial2026-03-28·14 min read

Building an MCP server backed by a managed knowledge base

The Model Context Protocol lets AI agents pull context on demand. We walk through wiring Kognita's API into an MCP server your models can query directly.

The Model Context Protocol (MCP) lets AI agents pull context on demand from external tools. Here is how to wire Kognita into an MCP server.

What is MCP?

MCP is an open protocol that standardises how AI agents communicate with context providers. An MCP server exposes tools, which are callable functions with typed inputs and outputs, that an LLM can invoke when it needs information it does not have in context.

What we are building

An MCP server with a single tool:

search_knowledge_base(query: string, top_k?: number) → SearchResult[]

When an LLM calls this tool, the server queries Kognita's hybrid search API and returns the top results.

Prerequisites

  • A Kognita account with an API key and organisation ID
  • Node.js 20+
  • The @modelcontextprotocol/sdk package

Step 1: Initialise the project

mkdir kognita-mcp && cd kognita-mcp
npm init -y
npm install @modelcontextprotocol/sdk

Step 2: Define the search tool

import { Server } from "@modelcontextprotocol/sdk/server/index.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import {
  ListToolsRequestSchema,
  CallToolRequestSchema,
} from "@modelcontextprotocol/sdk/types.js"

const server = new Server(
  { name: "kognita-mcp", version: "1.0.0" },
  { capabilities: { tools: {} } }
)

server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: "search_knowledge_base",
      description: "Search the knowledge base using hybrid BM25 + vector search",
      inputSchema: {
        type: "object",
        properties: {
          query: { type: "string", description: "The search query" },
          knowledge_base_id: { type: "string" },
          top_k: { type: "number", default: 5 },
        },
        required: ["query", "knowledge_base_id"],
      },
    },
  ],
}))

Step 3: Handle tool calls

server.setRequestHandler(CallToolRequestSchema, async (req) => {
  const { query, knowledge_base_id, top_k = 5 } = req.params.arguments

  const res = await fetch(
    `https://api.kognita.io/api/knowledge-bases/${knowledge_base_id}/search`,
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Api-Key": process.env.KOGNITA_API_KEY!,
        "X-Org-Id": process.env.KOGNITA_ORG_ID!,
      },
      body: JSON.stringify({ query, top_k, search_type: "hybrid" }),
    }
  )

  const { results } = await res.json()
  return {
    content: results.map((r: any) => ({
      type: "text",
      text: `[${r.score.toFixed(3)}] ${r.content}`,
    })),
  }
})

Step 4: Run the server

const transport = new StdioServerTransport()
await server.connect(transport)

Step 5: Connect to Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "kognita": {
      "command": "node",
      "args": ["/path/to/kognita-mcp/index.js"],
      "env": {
        "KOGNITA_API_KEY": "your_api_key",
        "KOGNITA_ORG_ID": "your_org_id"
      }
    }
  }
}

Restart Claude Desktop. The search_knowledge_base tool is now available.