e7136a4a20
New MCP server (mcp/) exposes kb operations as native MCP tools over
Streamable HTTP with Bearer token auth. Supports collections via tag
conventions, chunked file uploads, and agent-side search patterns.
Engine gains PATCH /api/v1/notes/{id} for in-place note updates with
transactional re-chunk/re-embed, and updated_at column on documents.
Go client adds updatenote command and Patch HTTP method.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5.6 KiB
5.6 KiB
1. Engine: Schema Migration & updated_at
- 1.1 Add
updated_at TEXTcolumn migration toinit_schema()inkb/database.py(same pattern as existingALTER TABLEmigrations) - 1.2 Update
insert_document()to includeupdated_atin returned/stored fields - 1.3 Update document list endpoint (
GET /api/v1/documents) to includeupdated_atin response and useCOALESCE(updated_at, created_at)for date sorting - 1.4 Update document detail endpoint (
GET /api/v1/documents/{id}) to includeupdated_atin response - 1.5 Update tag management endpoint (
PUT /api/v1/documents/{id}/tags) to setupdated_at = current_timestampon tag changes
2. Engine: Note Mutation Endpoint
- 2.1 Create
kb/routes/notes.pywithPATCH /api/v1/notes/{id}endpoint - 2.2 Implement validation: document must exist and have
doc_type = 'note'(404 / 422 on failure) - 2.3 Implement note update logic: delete old chunks/embeddings, run note chunking pipeline, re-embed, insert new chunks, update
content_hashandupdated_at— all in a single transaction - 2.4 Register the notes router in
engine/main.py - 2.5 Test: update a note and verify chunks, embeddings, FTS index, and
updated_atare all correctly updated - 2.6 Test: verify rollback on embedding failure preserves original note
3. Engine: Version Bump
- 3.1 Update
engine/VERSIONto3.0.0
4. Go Client: Update Note Command
- 4.1 Add
PATCH /api/v1/notes/{id}method tointernal/api/client.go - 4.2 Create
cmd/updatenote.go— takes document ID and text as positional args, calls PATCH endpoint, formats output (human/json) - 4.3 Handle error cases: 404 (not found), 422 (not a note), missing arguments
- 4.4 Update
cmd/examples.goto includeupdatenoteusage
5. Go Client: Version Bump
- 5.1 Update
client/VERSIONto3.0.0 - 5.2 Update
client/MIN_ENGINE_VERSIONto3.0.0
6. MCP Server: Project Setup
- 6.1 Create
mcp/directory at repo root with Python package structure - 6.2 Add
mcpSDK andhttpxas dependencies (requirements.txt or pyproject.toml) - 6.3 Implement config: read
KB_ENGINE_URL,KB_API_KEY,KB_MCP_API_KEYfrom environment - 6.4 Implement Streamable HTTP transport setup using
mcpSDK - 6.5 Implement Bearer token authentication for incoming agent connections (
KB_MCP_API_KEY)
7. MCP Server: Core Tools
- 7.1 Implement
kb_searchtool — proxy to engine search API, translatecollectionparam tocollection:*tag filter, stripcollection:*tags from results and addcollectionfield - 7.2 Implement
kb_addnotetool — proxy to engine jobs API, applycollection:<name>tag (defaultcollection:documents) - 7.3 Implement
kb_update_notetool — proxy to enginePATCH /api/v1/notes/{id} - 7.4 Implement
kb_gettool — proxy to engine documents API, support lookup by ID or source_path, strip collection tags from response - 7.5 Implement
kb_statustool — proxy to engine status API - 7.6 Implement
kb_jobstool — proxy to engine jobs API with optional status filter
8. MCP Server: Chunked File Upload
- 8.1 Implement
kb_upload_starttool — generate UUID, create temp staging directory, store upload metadata (filename, tags, collection) in memory - 8.2 Implement
kb_upload_chunktool — validate upload_id exists, decode base64, write chunk to staging directory by chunk_index - 8.3 Implement
kb_upload_finishtool — reassemble chunks in order, forward as multipart upload to enginePOST /api/v1/jobswith tags (includingcollection:*), return job ID, clean up staging - 8.4 Implement abandoned upload cleanup — background task that removes uploads older than 10 minutes
- 8.5 Test: upload a multi-chunk file and verify it arrives at the engine correctly
9. MCP Server: Collection Management
- 9.1 Implement exclusive collection enforcement — on addnote/addfile, query document tags, remove any existing
collection:*tags via engine tag API before applying new one - 9.2 Implement collection tag stripping in all tool responses (search results, document details)
10. MCP Server: Tool Descriptions
- 10.1 Write
kb_searchtool description including query expansion and reranking guidance - 10.2 Write descriptions for all other tools with parameter documentation and usage examples
- 10.3 Include chunked upload usage example in
kb_upload_startdescription
11. MCP Server: Docker & Compose
- 11.1 Create
mcp/Dockerfile— Python base image, install dependencies, run MCP server - 11.2 Add MCP server service to Docker Compose file(s) — connect to engine via Docker network, expose Streamable HTTP port
- 11.3 Document environment variables (
KB_ENGINE_URL,KB_API_KEY,KB_MCP_API_KEY) in compose file
12. Integration Testing
- 12.1 Test: MCP search with collection filter returns only matching documents
- 12.2 Test: MCP addnote with collection applies correct tag and enforces exclusivity
- 12.3 Test: MCP update note preserves document ID and tags, updates content and
updated_at - 12.4 Test: chunked file upload end-to-end (start → chunk × N → finish → verify job created)
- 12.5 Test: MCP server rejects unauthenticated connections when
KB_MCP_API_KEYis set
13. Release
- 13.1 Build and tag engine Docker images (
engine-v3.0.0-*) - 13.2 Build and tag MCP server Docker image
- 13.3 Build Go client binaries for all platforms
- 13.4 Create git tags:
engine-v3.0.0,client-v3.0.0 - 13.5 Update SKILL.md to reference MCP server as primary agent integration path