Skip to content

feat(mcp-server): add create_knowledge_from_text tool - #2532

Merged
lyingbug merged 2 commits into
Tencent:mainfrom
01luyicheng:feat/mcp-create-knowledge-from-text
Aug 5, 2026
Merged

feat(mcp-server): add create_knowledge_from_text tool#2532
lyingbug merged 2 commits into
Tencent:mainfrom
01luyicheng:feat/mcp-create-knowledge-from-text

Conversation

@01luyicheng

Copy link
Copy Markdown
Contributor

Description

Adds a create_knowledge_from_text 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 #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 /manual endpoint already powers the web UI's "paste text" knowledge-creation flow and uses the same OwnedKBOrAdmin + KBAccessWrite middleware as /file and /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_id may be a UUID or a knowledge-base name (resolved automatically, like create_session / hybrid_search). Note: the sibling create_knowledge_from_file / create_knowledge_from_url tools 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_file tool, which was missing from the README tool list.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

Fixes #323

Testing

From mcp-server/ (CI runs the suite via python -m unittest discover -s . -p "test_*.py" -v):

  • python -m unittest discover -s . -p "test_*.py" -v → 23 tests pass, including the 5 new test_create_knowledge_from_text tests and the updated test_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):

  • The client method POSTs to /knowledge-bases/{kb_id}/knowledge/manual with the expected body {title, content, status, tag_ids?}.
  • status defaults to "publish" and can be overridden to "draft".
  • tag_ids is omitted when not provided.
  • The @mcp.tool() function resolves kb_id via resolve_kb_id and forwards status.

The request shape was verified against internal/types/knowledge.go (ManualKnowledgePayload), the route internal/router/routes_knowledge.go:75, and that status="publish" triggers indexing in internal/application/service/knowledge_create.go (CreateManualKnowledge).

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...; N/A here — no Go changes, ruff check passes on the changed Python files)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, docs/, Swagger annotations, etc.) — updated README.md, EXAMPLES.md, CHANGELOG.md
  • Breaking changes are clearly called out in the description above (N/A — purely additive)

Screenshots / Recordings

N/A — no user-visible UI changes (MCP tool addition only).

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.
Copilot AI lite review requested due to automatic review settings August 4, 2026 17:44
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lyingbug
lyingbug merged commit 1737221 into Tencent:main Aug 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 能否为MCP添加通过本地文件或文本添加知识的工具

3 participants