mcp-knowledge-server
An MCP server that enforces access control on internal knowledge, ensuring agents only retrieve and cite documents the caller is permitted to see, and refuses answers when permissions are insufficient.
README
mcp-knowledge-server
Connect an agent to your internal knowledge without leaking across permission boundaries. A Model Context Protocol server that filters every retrieval by the caller's identity before anything reaches the model, answers only with grounded citations to documents the caller may actually see, and refuses when the answer lives behind a permission they lack. Fully offline, keyless, and leak-gated in CI.
"Connect our AI to our internal docs" is the request every enterprise makes, and the naive version, dumping a folder into a vector database, quietly ignores who is asking. An engineer must not retrieve compensation bands; a member of the public must not see the revenue forecast. This server makes that structurally impossible: the access filter runs before ranking, so an inaccessible document can never enter a result, be cited, or shape an answer. Built from my RAG and evaluation work.
What this demonstrates
| Enterprise concern | Where |
|---|---|
Identity and role model, public implicit for everyone |
config.py |
| Per-document access control lists | corpus.py |
| Access filter applied before ranking | acl.py · retriever.py |
| Grounded, cited answers with an explicit refusal path | answerer.py |
| Staleness signal on old sources | corpus.py |
| ACL enforced at the MCP resource layer too | server.py |
| Leak-proof and grounding CI gate | evals.py |
Architecture
flowchart LR
Q[agent query + caller identity] --> ACL{{access filter}}
D[(documents + ACLs)] --> ACL
ACL -->|accessible only| R[rank by relevance]
R -->|clears the bar| G[grounded, cited answer]
R -->|nothing relevant| X[refuse]
Quickstart
make dev # venv + install -e ".[dev]"
kb demo # answers and refusals across roles
kb ask "how do I roll back a deployment" --roles engineering
kb ask "what are the salary bands" --roles engineering # refused: HR-only
kb eval # the leak-proof gate
kb serve --roles engineering # live MCP server over stdio
No keys, no network. Embeddings are a deterministic hashing vectorizer; set
KB_EMBEDDER=openai in production to swap in dense embeddings behind the same
interface, with the access-control logic unchanged.
The gate that matters
kb eval runs labeled queries across roles (report):
| metric | value | gate |
|---|---|---|
| permission_leaks | 0 | = 0 |
| ungrounded_citations | 0 | = 0 |
| recall_at_k | 1.000 | >= 0.80 |
| refusal_rate | 1.000 | >= 0.90 |
The two zeros are the contract. permission_leaks counts any answer that cites or
contains a document the caller cannot access, and any case where an inaccessible
gold document is even retrieved. ungrounded_citations counts any answer whose
cited snippet is not a verbatim span of its source. Both must be zero or CI fails.
Recall and refusal_rate confirm the server is still useful: it finds the right
document when the caller is entitled to it, and refuses cleanly when they are not.
What it does
- Answers within a permission. An engineer asking how to roll back a deployment gets the runbook snippet with a citation.
- Refuses across a permission. The same engineer asking for salary bands is refused, and the HR content never appears, not even partially.
- Grounds every claim. Each answer carries a document id and a snippet copied verbatim from that document, so a reviewer can verify it.
- Flags stale sources. An answer sourced from a document over a year old is marked, so nobody acts on outdated terms.
- Enforces at the resource layer. Reading
kb://doc/{id}directly is also access-checked, so the boundary holds no matter how the client reaches for data.
Design decisions
- Filter before rank, always. Access control is not a post-filter on results; an inaccessible document is removed from consideration before scoring, so it can never influence what the model sees.
- Refuse over guess. When nothing accessible clears the relevance floor, the server says so. A wrong-but-confident answer and a leak are the two failure modes that matter, and refusal avoids both.
- Citations are verbatim. The snippet is a real substring of the source, not a paraphrase, which is what makes grounding checkable rather than aspirational.
- Identity is explicit. Roles come from the caller (
KB_ROLES), andpublicis always included, so default access is the least-privilege set.
Layout
src/mcp_knowledge/ config · corpus · embed · acl · retriever · answerer · server · evals · cli
data/ documents.jsonl · eval_queries.jsonl
reports/ kb_report_example.md
Related repositories
Part of a portfolio on production ML and LLM engineering:
- hybrid-graph-rag: hybrid and graph retrieval benchmark
- llm-eval-observability: RAG evaluation and observability
- mcp-guardrail-gateway: security gateway for MCP servers
- ai-harness: multi-stage agent harness
- mcp-knowledge-server: this repo.
License
MIT (c) 2026 Taha Siddiqui
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。