Skip to content

feat: bind knowledge MCP services to workflow nodes and chat sessions - #1434

Open
alberthaolihai wants to merge 60 commits into
Tencent:mainfrom
alberthaolihai:feat/knowledge-connector
Open

alberthaolihai wants to merge 60 commits into
Tencent:mainfrom
alberthaolihai:feat/knowledge-connector

Conversation

@alberthaolihai

Copy link
Copy Markdown
Collaborator

What changed

Describe the user problem and the resulting behavior.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

List affected hosts and any migration or backward-compatibility impact.

Validation

List commands that were actually run and mark anything blocked or not run.

go test -p=2 ./... -count=1 -timeout=180s
go vet ./...
python3 scripts/check-public.py
bash local/scripts/validate.sh
bash local/scripts/smoke-install.sh
bash local/scripts/e2e.sh
bash scripts/scan-secrets.sh

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

alberthaolihai and others added 30 commits November 19, 2026 11:36
… tests

- checkReferences: surface underlying probe errors and distinguish
  'no read-only tools' instead of the misleading identity-related message
- UI: align knowledge picker (chat + SOP node) and dialog footer buttons
  with existing design system; fix message-references class collision
- tests: add validate/redaction/token/check-reference edge cases and fix
  pre-existing struct-comparability compile error in query_performance_test
- deploy: isolate compose project name for parallel fork instance
- dual-timeout clients (60s json / 10m stream) sharing one transport
- outbound URL validation and cross-origin redirect refusal
- UpstreamError with three-envelope parsing and Structured flag (1MiB cap)
- io.Pipe streaming multipart upload safe on early upstream errors
- streaming preview/download with active MIME downgrade and log path truncation
- capability/document/chunk domain models for the management surface
…(step 3)

- resolve exactly the named connection and reject non-canonical scoped ids
- gate document operations before the parent knowledge-base lookup
- invalidate cached capabilities only for changed connections
- inherit the top-level provider for connection checks
Add 11 DOM-driven cases for web/app/knowledge.js: connection capability badges and re-probe, 503 capability_unavailable degradation gating, explicit connectionId KB create/update/delete, three-mode document import, document list paging/reparse/delete confirm, document detail drawer (inert/focus restore, chunk paging, safe text preview, legacy chunk fallback, manual edit PUT), admin:* audit badges, search, distill review, and not-ready/LightCloud/read-only fallbacks.

load-app: default capabilities route returns an empty safe payload so existing knowledge stubs stay backward compatible.
P1-1: preview stub now carries <b>/<img onerror> markup and asserts tags stay as text, never become elements. P1-2: project scope starts empty, asserts unchecked, checks via DOM click, then asserts PUT writes {projectId:[source]}. P1-3: assert legacy capability probe happens once despite re-renders, assert scoped connID::rawID prefix wins over the active connection filter, and add a single-connection addressing case covering bare source/doc ids.
… (step 4)

- check accepts connectionId and returns capability snapshot; new
  GET /connections/:id/capabilities
- source detail (GET /sources/:id) and PATCH with field presence, so a
  partial update no longer clears the description; PUT keeps full replace
- document detail/chunks and verbatim preview/download streaming with
  sanitized MIME, nosniff and no-store; gzip skips these paths so the
  exact Content-Length survives
- upload streams multipart.File through UploadDocumentReader, rejects
  bodies past the 50MiB file + 1MiB envelope limit with 413
- every management write emits a structured audit line and an
  admin:* activity entry, with parent target fallback on failure
- sources?connectionId= filters by explicit connection and rejects
  unknown/default under multi-connection settings
- TestKnowledgeManagement covers capability gates, 503 mapping,
  streaming headers, project scope 403, audit entries and read-only
  isolation when probes fail

Verified: gofmt, go vet ./internal/httpapi ./internal/knowledge,
go test -race ./internal/httpapi -run TestKnowledgeManagement,
full ./internal/httpapi ./internal/knowledge, go build ./...
…p 5)

- probe preview and download independently, deriving the aggregate
  preview_download so one denied action no longer disables the other
- reject query/fragment credentials in the WeKnora base URL and redact
  connection URLs using the inherited provider in Public()
- accept legacy connectionId=default, allow PATCH in CORS preflight and
  require platform admin for forced capability refresh
- invalidate stale probes on demotion after a concurrent invalidate and
  make the singleflight probe panic-safe
- track which capability keys the backend actually returned so legacy
  payloads stay optimistic while explicit unknown verdicts are enforced
- gate preview and download separately and recompute the aggregate
  badge state after a live 503 demotion
- add webtest coverage for endpoint asymmetry and legacy 404 + 503
alberthaolihai and others added 21 commits November 23, 2026 18:59
# Conflicts:
#	chatbot/src/knowledge-citations.js
#	internal/domain/knowledge_ref.go
#	internal/httpapi/knowledge_reference.go
#	internal/httpapi/knowledge_reference_edges_test.go
#	internal/knowledge/rules.go
- three-segment OAuth card (none/auto/preset) in connector drawer with
  preset gallery, public-app notice and read-only redirect URI
- vendor gallery cards with unauthorized grayscale / authorized states
  and one-click authorization
- OAuth session lifecycle (begin/end/timeout reaping) closed by
  BroadcastChannel completion signal, with auto probe after grant
- sync i18n entries and add acceptance tests
…dings

P0:
- compose.yaml: restore project name loopforge (volume/network compatibility)
- openapi.yaml: cover GET /api/knowledge/connectors contract
- gin_helpers/auth_tokens: drop global DisallowUnknownFields and stale
  weknora console-sso redeem auth/CORS exemption
- connector_feishu: fix getTAT mutex self-deadlock; release tatMu before
  network I/O (redactWithTAT)
- connector_mcp: prefix mcpClients/mcpToolsCache/mcpSemaphores keys with
  OwnerUserID; never cache probe connectors; refresh lastToken on retry;
  split consecutive-uppercase acronyms and extend write verbs
- connector_common/connector_weknora/mcpclient: unified SSRF DialContext
  guard, no ProxyFromEnvironment, exclude link-local/CGNAT/metadata IPs,
  same-origin redirects, 16MB response cap, scanner.Err, separate initMu
- oauth/service_oauth/knowledge_oauth/server: browser-binding cookie
  (loopforge_kb_oauth_nonce) + VerifyOAuthStateNonce against Login-CSRF;
  POST-only /authorize; ignore unverified X-Forwarded-Host; SHA-256
  domain-separated state secret; verifyStateAt uses injected clock

P1:
- assistant/assistant_session/assistant_workbench: isolate personal KB
  refs by owner in project sessions
- service: require fresh credentials when endpoint changes (check/update)
- knowledge handler: server-generated kbconn_* IDs only
- connector_feishu: validate obj_token belongs to allowed space node tree
- connector_obsidian: block hidden path segments, require .md suffix
- engine/node_execute: persist cited_count on success and all
  waiting_approval paths
- docs: rewrite 4 knowledge guides for the 6-connector architecture

P2/P3:
- connector_common: rune-based case-insensitive snippet matching (no panic)
- connector_weknora: mode-based allowlist check, bounded error drain
- executor/connector_mcp: context.WithoutCancel + timeout for singleflight
- engine/assets: XML-escape fallback SOP knowledge catalog
- agent_tool_mcp: fail-closed write-tool approval gate
- knowledge_proxy: require RunID/NodeID and run-node liveness
- migrations/036: idempotent MySQL cited_count via information_schema
- repo: composite usage index alignment, row lock on connector upsert,
  config JSON fallback + AllowedTools normalization, dedup/sorted usage
  deltas, throttled prune out of hot tx, LIKE escaping
- web: iframe postMessage navigation to knowledge view, escaped error
  rendering, usage-events request sequencing, i18n sync, css cleanup
- chatbot: citation scroll after expand via useEffect, ArtifactPanel
  fallback prefers selected.runId

Tests updated for the new security rules (OAuth cookie/POST-only,
proxy run identity, endpoint-change credential reset). go vet ./... clean;
knowledge/mcpclient/repo/domain/engine/httpapi/web/docs/api/mcpserver,
chatbot Vitest 384/384 and webtest 197/197 all green.
…-ups

Covers cross-run ArtifactPanel knowledge read isolation, per-nonce OAuth browser cookies, Obsidian hidden-entry filtering, strict connector endpoint credential reuse checks, MCP semaphore ref-counted cleanup, and guarded mcpclient transport with hermetic regression tests.
…ector

# Conflicts:
#	chatbot/src/ActivityTrace.jsx
#	chatbot/src/App.jsx
#	chatbot/src/RichContent.jsx
#	chatbot/src/useChat.js
#	internal/domain/run.go
#	internal/engine/artifacts.go
#	internal/engine/node_execute.go
#	internal/httpapi/agent_tool_catalog.go
#	internal/httpapi/assistant.go
#	internal/httpapi/assistant_fork.go
#	internal/httpapi/assistant_native_approval.go
#	internal/httpapi/assistant_session.go
#	internal/httpapi/assistant_workbench.go
#	internal/httpapi/gin_helpers.go
#	internal/httpapi/runs.go
#	internal/httpapi/server.go
#	internal/knowledge/service.go
#	internal/knowledge/service_test.go
#	internal/mcpclient/client.go
#	internal/repo/automigrate.go
#	internal/repo/models.go
#	internal/repo/run_knowledge.go
#	internal/runtime/protocol.go
#	web/app.js
#	web/app/flows.js
#	web/app/runners.js
#	web/app/runs.js
#	web/embed.go
#	web/index.html
#	webtest/lib/load-app.mjs
#	webtest/tests/views.test.mjs
@Robert0622

Copy link
Copy Markdown
Collaborator

Code Review: ISSUES FOUND ❌

Reviewed changes: Binds knowledge MCP services to workflow nodes and chat sessions.

P2 — Cross-user personal KB exposure:
A project writer can dispatch a run assigned to user A, mounting all of A's personal connectors in all mode, with output readable by the dispatcher. Personal knowledge bases should not be accessible to other users via dispatched runs.

P2 — Broken connector causes permanent 400:
Deleting or disabling a bound connector breaks all subsequent session PUTs (400) until manually rebound. Forks inherit and propagate the broken refs.

P2 — SSRF via MCP connectors:
All connector types unconditionally allow loopback and RFC1918 targets. MCP connectors accept arbitrary custom headers, enabling SSRF to internal services by any authenticated user.

P2 — Silent backwards-compat break:
KnowledgeBase=true roles lose platform KB access with no migration. Legacy settings route still accepts writes no run uses.

P2 — Migration number collision:
Migration numbers 047–049 collide directly with PR #1338. These need to be renumbered.

P3s:

  • Hard-coded fallback AES/HMAC key (loopforge-local-dev-knowledge-secret) when no secret env var is set.
  • A single @mention permanently hides the session from all project members via KnowledgeRestricted with no reset path.
  • describeBoundRef emits unescaped XML with raw upstream error text.
  • Stale output bug on retry when prior output had citation markers.

The P2 issues (cross-user data exposure, SSRF, migration collision) need to be resolved before this PR is ready to merge.

loopforge-pr-review:e8ee72d544cd0741a2ad7b66e362bcd6456ce533

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.

2 participants