Model Context Protocol (MCP)
Let your AI agents parse, search, and inspect Knowhere documents by using the Knowhere MCP server.
The Knowhere Model Context Protocol (MCP) server is a thin local stdio wrapper around the Node.js SDK. Agents can start async parse jobs for URLs or local files, list published documents, read outlines and chunks, grep parsed content, and search published documents through retrieval.
Prerequisites
- Node.js 20.19+ and npm 10+
- An MCP host that can run local stdio servers
- A Knowhere dashboard login or a
KNOWHERE_API_KEY
Connect to Knowhere's MCP server
The MCP package runs as a local stdio server. Log in once, then add the server command to your MCP host.
npx -y @ontos-ai/knowhere-mcp login
The login opens the Knowhere dashboard and stores a local MCP login at ~/.knowhere-node-sdk/mcp/auth.json. During login, choose one of two permissions:
- Read only: query Knowhere and read existing parsed documents. Parse and delete tools are not exposed.
- Full access: query, read, start async URL/file parse jobs, cache completed parse jobs, and archive documents.
The host configuration does not need a KNOWHERE_API_KEY when dashboard login is used.
- Cursor
- Codex
- Claude Code
- Claude Desktop
- VS Code
- Other
To open Cursor and automatically add the Knowhere MCP server, click install. Alternatively, add the following to ~/.cursor/mcp.json:
{
"mcpServers": {
"knowhere": {
"command": "npx",
"args": ["-y", "@ontos-ai/knowhere-mcp"]
}
}
}
Restart Cursor and open its MCP settings to confirm that the Knowhere server is connected.
Add the server with the Codex CLI:
codex mcp add knowhere -- npx -y @ontos-ai/knowhere-mcp
Or edit ~/.codex/config.toml:
[mcp_servers.knowhere]
command = "npx"
args = ["-y", "@ontos-ai/knowhere-mcp"]
startup_timeout_sec = 20
tool_timeout_sec = 120
Restart Codex or run /mcp in the Codex TUI to inspect connected MCP servers.
For project-scoped config with a non-default API endpoint, forward only the endpoint variable instead of committing secrets:
[mcp_servers.knowhere]
command = "npx"
args = ["-y", "@ontos-ai/knowhere-mcp"]
env_vars = ["KNOWHERE_BASE_URL"]
Add the server with the Claude Code CLI:
claude mcp add \
--transport stdio \
knowhere \
-- npx -y @ontos-ai/knowhere-mcp
Use /mcp inside Claude Code to verify the server, or run:
claude mcp list
Open Claude Desktop settings, go to developer settings, and edit claude_desktop_config.json.
Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add the Knowhere server:
{
"mcpServers": {
"knowhere": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@ontos-ai/knowhere-mcp"]
}
}
}
Save the file and fully restart Claude Desktop. If the server does not appear, check Claude's MCP logs and verify that node, npm, and npx are available from the desktop app's environment.
To open VS Code and automatically add the Knowhere MCP server, click install. Alternatively, add the following to .vscode/mcp.json in your workspace:
{
"servers": {
"knowhere": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@ontos-ai/knowhere-mcp"]
}
}
}
Reload VS Code and open the MCP server list from Copilot Chat to confirm the server is running.
Use the same local stdio process configuration in any MCP host that manages server processes for you:
{
"command": "npx",
"args": ["-y", "@ontos-ai/knowhere-mcp"]
}
Some MCP clients only support remote HTTP servers. The current Knowhere MCP package is a local stdio server, so use a local MCP host or build directly with the Node.js SDK or REST API for remote hosted agents.
API-key authentication
Dashboard login is recommended for local MCP clients because it supports scoped permissions and session revocation. For non-interactive agents, set KNOWHERE_API_KEY before starting the MCP server:
export KNOWHERE_API_KEY="sk_..."
npx -y @ontos-ai/knowhere-mcp
Or pass the key through the host config:
{
"mcpServers": {
"knowhere": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@ontos-ai/knowhere-mcp"],
"env": {
"KNOWHERE_API_KEY": "sk_..."
}
}
}
}
Do not commit API keys to shared MCP configuration files. API-key authentication runs with full access, so provide keys through a secrets manager or local environment variable whenever possible.
Manage MCP sessions
Use the MCP package commands to inspect or remove the local login:
npx -y @ontos-ai/knowhere-mcp status
npx -y @ontos-ai/knowhere-mcp logout
status shows whether the server is using KNOWHERE_API_KEY or a stored dashboard login, the auth file path, the base URL, and the stored permission.
Set KNOWHERE_BASE_URL when using a non-default Knowhere environment:
export KNOWHERE_BASE_URL="https://staging.knowhereto.ai"
npx -y @ontos-ai/knowhere-mcp login
The default site base URL is https://knowhereto.ai. The MCP package derives API and login routes from this base URL.
Local files and remote agents
The published MCP package is local stdio MCP. It runs on the same machine as the MCP host process and speaks MCP over standard input and output.
Local file tools read paths from that machine:
knowhere_async_parse_filecan only read files available to the MCP server process.- A file path from a remote chat UI, browser sandbox, or hosted agent is not automatically visible to the local stdio process.
- For remote or server-side agents, prefer
knowhere_async_parse_urlfor public or signed URLs, or build an upload flow with the Node.js SDK or REST API.
A server-side MCP deployment, if you build one, should still speak MCP over an HTTP transport such as Streamable HTTP. It is not the same thing as calling arbitrary REST endpoints directly.
Building autonomous agents
MCP tools can read and mutate your Knowhere account depending on the permission you choose. When building autonomous workflows:
- Prefer read-only permission when the agent only needs document search or inspection.
- Enable human confirmation for parse and delete tools in your MCP host.
- Scope API keys to the agent's task and keep them in a vault or local environment variables.
- Avoid connecting untrusted MCP servers in the same agent session as Knowhere, because prompt injection can cause unsafe tool calls.
- For large PDFs or OCR-heavy files, use async parse tools and poll status with backoff:
5s,10s,20s,40s,80s, then cap at120s.
Tools
The server exposes the following MCP tools.
| Resource | Tool | Access | Description |
|---|---|---|---|
| Parse | knowhere_async_parse_url | Full access | Start parsing a remote URL and return the job immediately. Poll status with exponential backoff. |
| Parse | knowhere_async_parse_file | Full access | Start parsing a local file path available to the MCP process, upload it if needed, and return the job immediately. Poll status with exponential backoff. |
| Jobs | knowhere_async_get_job_status | Read only, Full access | Check parse job status and load completed job results into the local cache when available. |
| Documents | knowhere_list_documents | Read only, Full access | List published Knowhere documents from the remote API, optionally filtered by namespace. Returned documentId values can be passed to outline, read, and grep tools. |
| Documents | knowhere_delete_document | Full access | Archive, or soft-delete, a published Knowhere document. |
| Documents | knowhere_get_document_outline | Read only, Full access | Return the outline for a parsed document by localDocumentId, published documentId, or completed jobId. |
| Documents | knowhere_read_chunks | Read only, Full access | Read exact chunks from a parsed document by page, section path, chunk ID, chunk type, or chunk range. Page screenshots are returned as tagged page assets before preview text. |
| Documents | knowhere_grep_chunks | Read only, Full access | Run literal or regex search over one parsed document. Broad search belongs to knowhere_search. |
| Retrieval | knowhere_search | Read only, Full access | Search published documents through the Knowhere retrieval API. Page results are marked when a follow-up read call can return readable page asset URLs. |
When logged in with Read only permission, the MCP server exposes only knowhere_search, knowhere_list_documents, knowhere_get_document_outline, knowhere_read_chunks, knowhere_grep_chunks, and knowhere_async_get_job_status.
Response contract
All tools return a single MCP text content item:
{
"content": [{ "type": "text", "text": "<knowhere operation=\"...\">..." }]
}
The MCP package does not expose structuredContent or tool outputSchema fields. Each response is tagged text rooted at <knowhere operation="...">, using SDK-native camelCase field names such as documentId, jobId, localDocumentId, chunkId, assetUrl, chunkPath, filePath, and storageRoot.
Document tags include storageRoot when the SDK response has document.resultDirectoryPath. Local cache roots are local directory paths. Remote fallback roots use marker values such as remote:<documentId>, and configured parsed-storage roots use marker values such as parsed-storage:<documentId>.
Chunk tags include chunkPath from the source chunk path and a display-only storageLocation when one can be derived. Media and table chunks prefer filePath and include assetUrl when available. Text and page chunks use chunkPath, so marker roots render as logical paths such as parsed-storage:doc_x/chunks/page-1.
For page chunks, <pageAssets primary="true"> appears immediately before <previewText>. Each <pageAsset> carries pageNum, artifactRef, assetUrl, contentType, width, and height when Knowhere provides them. The following <instruction> tells the agent to open or fetch the listed assetUrl before relying on preview text. If a page asset exists without an assetUrl, the response says that the asset is not directly readable.
Search responses mark page results and references with hasPageAssets="true" when the agent should call knowhere_read_chunks next to inspect readable page asset URLs and chunk storage locations.
Async parse responses return the job identifier and source metadata immediately. Use knowhere_async_get_job_status to poll the job until it completes, then pass the returned localDocumentId, documentId, or jobId to outline, read, or grep tools.