feat(mcp-server): add create_knowledge_from_text tool - #2532
Merged
lyingbug merged 2 commits intoAug 5, 2026
Conversation
Add an MCP tool that creates a knowledge entry from raw Markdown text by
calling the existing backend endpoint
POST /knowledge-bases/{id}/knowledge/manual (handler.CreateManualKnowledge).
This completes the "text" half of Tencent#323, whose "file" half was already
covered by create_knowledge_from_file.
The tool defaults to status="publish" so the created entry is chunked,
embedded and made searchable immediately — matching the API/MCP use case
where there is no UI to publish a draft. Callers may pass status="draft"
to save without indexing.
- New client method WeKnoraClient.create_knowledge_from_text.
- New @mcp.tool() create_knowledge_from_text, resolving kb_id by name or
UUID (consistent with create_session / hybrid_search).
- Add focused unittests verifying endpoint, request body shape, status
default/override, and kb_id resolution wiring.
- Bump the stdio tools-list count assertion in test_mcp_transports.py
from 29 to 30 for the newly registered tool.
List create_knowledge_from_file (previously missing from the README tool list) and the new create_knowledge_from_text in README.md and EXAMPLES.md, and add a CHANGELOG entry under Unreleased.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
create_knowledge_from_textMCP tool that creates a knowledge entry from raw Markdown text by calling the existing backend endpointPOST /knowledge-bases/{id}/knowledge/manual(handler.CreateManualKnowledge). This completes the "text" half of #323, which asks for MCP tools to add knowledge from "local file or text" — the file half (create_knowledge_from_file) already exists; this adds the missing text half.No Go/backend changes: the
/manualendpoint already powers the web UI's "paste text" knowledge-creation flow and uses the sameOwnedKBOrAdmin+KBAccessWritemiddleware as/fileand/url.The tool defaults to
status="publish"so the created entry is enqueued for chunking/embedding and becomes searchable (vs.status="draft", which saves without indexing) — matching the API/MCP use case where there is no UI to publish a draft.kb_idmay be a UUID or a knowledge-base name (resolved automatically, likecreate_session/hybrid_search). Note: the siblingcreate_knowledge_from_file/create_knowledge_from_urltools currently require a UUID; aligning them to also resolve names could be a follow-up.This PR also documents the pre-existing
create_knowledge_from_filetool, which was missing from the README tool list.Type of Change
Related Issue
Fixes #323
Testing
From
mcp-server/(CI runs the suite viapython -m unittest discover -s . -p "test_*.py" -v):python -m unittest discover -s . -p "test_*.py" -v→ 23 tests pass, including the 5 newtest_create_knowledge_from_texttests and the updatedtest_tools_list_returns_30_tools(tool count 29 → 30 for the newly registered tool).python -m black --check test_create_knowledge_from_text.py→ clean.python -m ruff check weknora_mcp_server.py test_create_knowledge_from_text.py test_mcp_transports.py→ all checks passed.The new tests verify (without a live WeKnora stack, by monkeypatching the HTTP layer):
/knowledge-bases/{kb_id}/knowledge/manualwith the expected body{title, content, status, tag_ids?}.statusdefaults to"publish"and can be overridden to"draft".tag_idsis omitted when not provided.@mcp.tool()function resolveskb_idviaresolve_kb_idand forwardsstatus.The request shape was verified against
internal/types/knowledge.go(ManualKnowledgePayload), the routeinternal/router/routes_knowledge.go:75, and thatstatus="publish"triggers indexing ininternal/application/service/knowledge_create.go(CreateManualKnowledge).Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...; N/A here — no Go changes,ruff checkpasses on the changed Python files)docs/, Swagger annotations, etc.) — updated README.md, EXAMPLES.md, CHANGELOG.mdScreenshots / Recordings
N/A — no user-visible UI changes (MCP tool addition only).