MCP Knowledge Assistant
MCP Knowledge Assistant
Ein schreibgeschützter Server für das Model Context Protocol (MCP), der einem KI-Client die Suche in einer Wissensbasis und das Abrufen vollständiger Quelldokumente ermöglicht. Das Projekt beginnt mit einem kleinen lokalen Prototypen und überträgt denselben Tool-Vertrag auf das semantische Retrieval aus einem OpenAI-Vector-Store.
Was hier demonstriert wird
MCP-Tool-Design mit eng begrenzten Zuständigkeiten für
searchundfetchStrukturierte Ein- und Ausgaben mit FastMCP und Pydantic
Semantisches Retrieval über hochgeladene Dokumente in einem OpenAI-Vector-Store
Deduplizierung auf Dokumentebene, wenn die Vektorsuche mehrere passende Chunks zurückgibt
Streamable-HTTP- und
stdio-MCP-TransporteEnd-to-End-Tool-Nutzung über die OpenAI Responses API und einen sicheren MCP-Tunnel
Konfiguration über Umgebungsvariablen, ohne Credentials im Quellcode
Unit- und Protokollebenen-Tests, die keine kostenpflichtigen API-Aufrufe ausführen
Related MCP server: File AI
Architektur
OpenAI Responses API
|
| MCP tool calls through an outbound secure tunnel
v
Local FastMCP server (Streamable HTTP)
|
| vector-store search and file retrieval
v
OpenAI vector store -> uploaded documentsDas Repository enthält außerdem einen vollständig lokalen Lernpfad:
Local demo client -> FastMCP server (stdio) -> data/documents.jsonBeide Server bieten denselben öffentlichen Tool-Vertrag an:
Tool | Eingabe | Zweck |
|
| Kompakte, relevante Dokumentverweise zurückgeben. |
|
| Ein vollständiges, über die Suche ausgewähltes Dokument abrufen. |
Die Trennung von Suche und Abruf verhindert, dass vollständige Dokumente übertragen werden, bevor sie benötigt werden, und gibt dem Modell stabile Dokument-IDs für spätere Aufrufe.
Projektstruktur
.
├── data/documents.json # Sample local knowledge base
├── sample_data/cats.pdf # Public-domain vector-store sample
├── src/mcp_knowledge_assistant/
│ ├── knowledge_base.py # Local keyword retrieval
│ ├── models.py # Shared response schemas
│ ├── server.py # Local stdio MCP server
│ └── vector_store_server.py # OpenAI vector-store MCP server
├── tests/ # Offline unit and MCP tests
├── demo_client.py # Local stdio demonstration
├── vector_store_demo_client.py # Direct HTTP MCP demonstration
└── api_client.py # Responses API + secure tunnel demonstrationAnforderungen
Python 3.11 oder neuer
Ein OpenAI-API-Projekt mit aktivierter Abrechnung für den Vector-Store-Pfad
Das enthaltene Beispiel-PDF oder ein eigenes Dokument, hochgeladen in einen OpenAI-Vector-Store
Der OpenAI-Tunnel-Client nur für die Demonstration des sicheren Tunnels
Der lokale JSON-Server und die vollständige Testsuite benötigen keinen API-Schlüssel.
Quellenangabe zum Beispieldokument
Die Vector-Store-Demonstration verwendet Cats: Their Points and Characteristics von W. Gordon Stables, Project Gutenberg eBook #43429. Das Beispiel-PDF wird von OpenAI gehostet und wurde aus der Project-Gutenberg-Ausgabe erstellt. Die Project-Gutenberg-Lizenz und die anwendbaren Wiederverwendungsbedingungen entnehmen Sie bitte dem PDF.
Einrichtung
Das Repository klonieren, eine virtuelle Umgebung anlegen und das Projekt installieren:
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"Kopieren Sie für die OpenAI-gestützten Beispiele die Umgebungsvorlage:
cp .env.example .env.localTragen Sie anschließend Ihre eigenen Werte in .env.local ein:
OPENAI_API_KEY=your_project_api_key
VECTOR_STORE_ID=vs_your_vector_store_id.env.local, PyCharm-Einstellungen, virtuelle Umgebungen und lokale Tunnel-Profile sind von Git ausgeschlossen.
1. Den lokalen Prototypen ausführen
Der erste Server verwendet stdio; der MCP-Client startet ihn deshalb als untergeordneten Prozess und kommuniziert über Standardeingabe und -ausgabe:
python demo_client.pyDie Demo entdeckt beide Tools, durchsucht die lokale JSON-Wissensbasis und ruft das ausgewählte Dokument ab.
Sie können den Server auch über seinen installierten Befehl starten:
mcp-knowledge-assistantEin stiller, wartender Prozess ist für einen stdio-Server normal, bei dem kein Client verbunden ist.
2. Den Vector-Store-Server ausführen
Laden Sie sample_data/cats.pdf in einen OpenAI-Vector-Store hoch und setzen Sie dann OPENAI_API_KEY und VECTOR_STORE_ID in .env.local. Wenn Sie möchten, können Sie ein eigenes Dokument und eine eigene Abfrage verwenden. Starten Sie den Streamable-HTTP-Server:
mcp-vector-store-assistantSein MCP-Endpunkt lautet standardmäßig:
http://127.0.0.1:8000/mcpTesten Sie den Endpunkt in einem zweiten Terminal direkt:
python vector_store_demo_client.pyDie Vektorsuche arbeitet auf Chunk-Ebene, sodass ein langes Dokument mehrere Treffer mit derselben Datei-ID erzeugen kann. Das MCP-Tool search führt diese Treffer bewusst zu einem einzigen Dokumentergebnis zusammen. Das Tool fetch ruft dann den geparsten Inhalt dieses Dokuments ab und kombiniert ihn für das Modell.
3. Aufruf über die Responses API
Folgen Sie dem Leitfaden für sichere MCP-Tunnels von OpenAI, um einen Tunnel einzurichten. Konfigurieren Sie das zugehörige ignorierte lokale Profil so, dass es auf http://127.0.0.1:8000/mcp zeigt, und starten Sie den Tunnel-Client. Fügen Sie die resultierende ID in .env.local hinzu:
MCP_TUNNEL_ID=tunnel_your_tunnel_idDer Tunnel-Client liest seine eigenen Laufzeit-Zugangsdaten aus CONTROL_PLANE_API_KEY. Bewahren Sie auch diesen Wert ausschließlich lokal auf. Mit laufendem Vector-Server und laufendem Tunnel-Client führen Sie Folgedes aus:
python api_client.pyDie Requests-API-Anfrage deklariert nur die schreibgeschützten MCP-Tools search und fetch. Das Modell kann suchen, eine ausgewählte Quelle abrufen und eine Antwort aus den abgerufenen Inhalten erstellen.
Tests
Führen Sie alle Tests aus mit:
pytestDie Tests decken lokales Ranking und Abrufen, die MCP-Tool-Erkennung, die Deduplizierung von Vektortreffern, die Inhaltszusammenstellungen und die Eingabevalidierung ab. OpenAI-Aufrufe werden gedumt, sodass die Suite wiederholbar ist und keine API-Guthaben verbraucht.
Designentscheidungen und Umfang
Read-only zuerst: Keines der MCP-Tools verändert Dateien oder den externen Zustand.
Stabiler Kompatibilitätsvertrag:
search(query)liefert Dokumentverweise;fetch(id)liefert den vollständigen Inhalt und die Metadaten.Dokumentergebnisse statt Chunk-Ergebnisse: Chunks dienen im Vector-Store als Nachweis bei der Abfrage, während der MCP-Client stabile Datei-IDs erhält.
MCP is eine Abstraktionsschicht: Für einen einzelnen OpenAI-gehosteter Vector Store ist das in die Responses API integrierte File-Search-Tool auch sorgfältig not waiting. MCP wird dann nützlich, wenn dieselbe Abrufnnung mehrere Clients bedienen soll, Backend-Details verbergen soll oder später um Autorisierung und Fachlogik erweitert robotic.
Verifizierte Integrationsgrenze: Die lokalen Server, die direkten MCP-Clients sowie der Pfad über die Responses API durch den sicheren Tunnel wurden während der Entwicklung erprobt. Dieses Repository erhebt nicht, dass ich sie eingesetzde deployed public Server or a published ChatGPT app.
Sicherheitshinweise
Committen Sie niemals
.env.local, API-Schlüssel, Tunnel-Laufzeitschlüssel oder Organisations-IDs.Verwenden Sie projektspezifische Zugangsdaten und erteilen Sie nur die tatsächlich erforderlichen Berechtigungen.
Halten sich den lokalen MCP-Server hinter dem sicheren ausgehenden Tunnel an, anstatt einen eigehenden Firewall-Port zu öffnen.
Prüfen Sie die Tool-Berechtigungen, bevor Sie eine Schreib- oder eine Aktion mit Folgen hinzufügen.
Referenzen
Available Tools
2 toolsfetchA
Retrieve one complete document using an ID returned by search.
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| id | Yes | |
| url | Yes | |
| text | Yes | |
| title | Yes | |
| metadata | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full behavioral disclosure burden. It reveals that this returns a complete document (not a summary) and that it depends on search-generated IDs, but doesn't mention error handling, permissions, or potential side effects. For a simple read operation this is adequate but has gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
One sentence, no redundant details, and the key information (retrieve by ID) is front-loaded. Perfect conciseness.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given that an output schema is present and there is only one parameter, the description sufficiently covers the essential context and its relationship to the sibling search tool. It could be improved by mentioning error cases or what happens if the ID is invalid, but for this simplicity it is complete enough.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The single parameter 'id' has no schema description, so the description's phrase 'returned by search' provides crucial semantic context, explaining where the ID comes from and how it should be used to retrieve the document.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses the specific verb 'Retrieve' with the resource 'one complete document' and the qualifier 'using an ID returned by search', which clearly defines the tool's scope and distinguishes it from the sibling tool 'search'.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
It explicitly states that the ID must come from search, establishing a clear workflow (search first, then fetch). It doesn't explicitly mention alternatives, but the context is clear enough for an agent to know when to use this tool versus search.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
searchC
Find documents relevant to a natural-language query.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| results | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It reveals that the tool does semantic matching over a natural-language query, but says nothing about how results are ranked, paginated, limited, scoped, or whether interactions are read-only or have side effects. It is not misleading, but it adds very little beyond what the name and schema already imply.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single front-loaded sentence with zero wasted words. It is appropriately brief for a minimal tool definition, though one could argue it is slightly under-specified—but the economy of expression is commendable.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with 1 parameter, no annotations, 0% schema coverage, and an unaddressed sibling 'fetch', one sentence is insufficient context. The description would be more complete by mentioning result limits, sort order, or any behavioral differences from fetch. The presence of an output schema helps explain return values, but the in/out behavior is still too thin for an agent to fully understand the tool's scope.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate, and it does add value by clarifying that 'query' accepts natural-language text rather than structured filters or keywords. However, it provides no examples, formatting hints, length limits, or syntax conventions—the description does the bare minimum to make the parameter actionable.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
'Find documents relevant to a natural-language query' uses a clear verb ('find'), a resource ('documents'), and a scope qualifier ('natural-language query'). It is clear and specific, but it does not explicitly distinguish itself from its sibling 'fetch', so it earns a 4 rather than a 5.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no guidance on when to use search versus its sibling 'fetch', no exclusions, and no when-to-use context. The description implies usage through the term 'search', but a sibling tool with zero differentiator guidance means the agent is left without decision support. This is 'no guidance' and scores a 2.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
v0.1.0- First observed
fetch - First observed
search
TDQS
Scored across 2 tools
search and fetch have clearly distinct purposes: one finds documents by query, the other retrieves a specific document by ID. There is no overlap or ambiguity.
Both tools use simple, consistent single-verb names ('search' and 'fetch') that clearly indicate their actions. The pattern is uniform.
With only 2 tools, the server is minimal but functionally complete for a simple search-and-retrieve pattern. It feels thin but is reasonable for a narrow purpose.
The two tools cover the core workflow of searching and retrieving documents. Minor gaps could include listing all documents or getting metadata, but the essential lifecycle is covered.
Maintenance
Related MCP Connectors
Read-only MCP server exposing a user ORANO library to their own AI agent.
Knowledge base MCP for AI agents on iknow.dev. Search, read, and maintain via OAuth.
Knowledge base for AI agents: search, read, tasks; write, correct, report outcomes via /mcp/write.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceAn MCP server that provides tools for retrieving and processing documentation through vector search, enabling AI assistants to augment their responses with relevant documentation context.24 npmMIT
- AlicenseBqualityDmaintenanceA read-only MCP server that provides document awareness for agents by parsing local files into structured profiles, blocks, chunks, and search results, enabling agents to understand and cite document content without dealing with raw file formats.543 npm3Apache 2.0
- FlicenseNot gradedqualityBmaintenanceAn MCP server that connects the Casio Plus knowledge base (playbooks, architecture, learning resources) to AI clients, offering read-only search and validation tools along with controlled feedback intake and review workflows.-
- AlicenseNot gradedqualityAmaintenanceMCP server that enables AI agents to search, fetch, and analyze a self-maintaining markdown knowledge base with provenance, drift detection, and canonical definitions.1MIT