Skip to content

Commit bed9a46

Browse files
committed
fix(knowledge): fix metadata column name, add path field, surface item_path in results
- Bug fix: rename metadata_ → metadata in schema DDL and INSERT SQL The Python ORM attribute name metadata_ was leaking into SQL column names. Add migration v2 to idempotently rename the column on existing databases. - Bug fix: remove phantom knowledge_items rows when no path is provided store_knowledge with source but no path no longer creates spurious knowledge_sources/knowledge_items rows. Instead, item_id=NULL is used and the source name is recorded in the proposition's metadata field. - Feature: add optional path parameter to store_knowledge When both source and path are provided, creates/upserts knowledge_sources and knowledge_items rows for full provenance tracking, using ON CONFLICT (source_id, path) for idempotent repeated stores. - Feature: surface item_path in search and recall results build_vector_search_query, build_fts_search_query, and _op_recall now LEFT JOIN knowledge_items and SELECT ki.path AS item_path so callers can see where a proposition came from. - Schema: add unique index idx_ki_source_path on knowledge_items(source_id, path) Required for the ON CONFLICT upsert in _op_store.
1 parent 0e7bafc commit bed9a46

15 files changed

Lines changed: 1304 additions & 683 deletions

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ Set connection details once using environment variables in your MCP server confi
570570
"KNOWLEDGE_DB_PORT": "5432",
571571
"KNOWLEDGE_DB_NAME": "knowledge_db",
572572
"KNOWLEDGE_DB_USER": "postgres",
573-
"KNOWLEDGE_DB_PASSWORD": "your_password",
574-
"KNOWLEDGE_ORG_ID": "your-org-uuid"
573+
"KNOWLEDGE_DB_PASSWORD": "your_password"
575574
}
576575
}
577576
}
@@ -873,7 +872,6 @@ Configure the server behavior with these environment variables:
873872
| `KNOWLEDGE_DB_NAME` | Knowledge DB database name | `knowledge_db` | Valid DB name |
874873
| `KNOWLEDGE_DB_USER` | Knowledge DB username | *(none)* | Any string |
875874
| `KNOWLEDGE_DB_PASSWORD` | Knowledge DB password | *(none)* | Any string |
876-
| `KNOWLEDGE_ORG_ID` | Organization ID for knowledge scoping | *(none)* | UUID string |
877875

878876
### Example Configuration
879877

docs/llm/block-reference.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,6 @@ Without this, execution fails with configuration error.
692692
- **`database`** (string): PostgreSQL database name (env: KNOWLEDGE_DB_NAME)
693693
- **`username`** (any): PostgreSQL username (env: KNOWLEDGE_DB_USER)
694694
- **`password`** (any): PostgreSQL password (env: KNOWLEDGE_DB_PASSWORD)
695-
- **`org_id`** (any): Organization ID for scoping queries (env: KNOWLEDGE_ORG_ID)
696695
- **`query`** (any): Search query text (required for search/context)
697696
- **`source`** (any): Filter by source name (exact or prefix with *)
698697
- **`categories`** (any): Filter by category UUIDs

schema.json

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,18 +1990,6 @@
19901990
"description": "PostgreSQL password (env: KNOWLEDGE_DB_PASSWORD)",
19911991
"title": "Password"
19921992
},
1993-
"org_id": {
1994-
"anyOf": [
1995-
{
1996-
"type": "string"
1997-
},
1998-
{
1999-
"type": "null"
2000-
}
2001-
],
2002-
"description": "Organization ID for scoping queries (env: KNOWLEDGE_ORG_ID)",
2003-
"title": "Org Id"
2004-
},
20051993
"query": {
20061994
"anyOf": [
20071995
{
@@ -3943,7 +3931,7 @@
39433931
},
39443932
"KnowledgeInput": {
39453933
"additionalProperties": false,
3946-
"description": "Input schema for Knowledge block.\n\nSupports five operations: search, store, recall, forget, context.\n\nConnection config resolves with priority: YAML inputs > env vars > defaults.\nSet KNOWLEDGE_DB_* environment variables once in your MCP server config\nto avoid repeating connection details in every workflow.\n\nEnvironment variables:\n KNOWLEDGE_DB_HOST: PostgreSQL host (default: localhost)\n KNOWLEDGE_DB_PORT: PostgreSQL port (default: 5432)\n KNOWLEDGE_DB_NAME: Database name (default: knowledge_db)\n KNOWLEDGE_DB_USER: Username\n KNOWLEDGE_DB_PASSWORD: Password\n KNOWLEDGE_ORG_ID: Organization ID for multi-tenant scoping\n\nExamples:\n ```yaml\n - id: find_patterns\n type: Knowledge\n inputs:\n op: search\n query: \"deployment patterns for web services\"\n source: \"internal-docs\"\n limit: 10\n ```",
3934+
"description": "Input schema for Knowledge block.\n\nSupports five operations: search, store, recall, forget, context.\n\nConnection config resolves with priority: YAML inputs > env vars > defaults.\nSet KNOWLEDGE_DB_* environment variables once in your MCP server config\nto avoid repeating connection details in every workflow.\n\nEnvironment variables:\n KNOWLEDGE_DB_HOST: PostgreSQL host (default: localhost)\n KNOWLEDGE_DB_PORT: PostgreSQL port (default: 5432)\n KNOWLEDGE_DB_NAME: Database name (default: knowledge_db)\n KNOWLEDGE_DB_USER: Username\n KNOWLEDGE_DB_PASSWORD: Password\n\nExamples:\n ```yaml\n - id: find_patterns\n type: Knowledge\n inputs:\n op: search\n query: \"deployment patterns for web services\"\n source: \"internal-docs\"\n limit: 10\n ```",
39473935
"properties": {
39483936
"op": {
39493937
"description": "Operation to perform",
@@ -4003,18 +3991,6 @@
40033991
"description": "PostgreSQL password (env: KNOWLEDGE_DB_PASSWORD)",
40043992
"title": "Password"
40053993
},
4006-
"org_id": {
4007-
"anyOf": [
4008-
{
4009-
"type": "string"
4010-
},
4011-
{
4012-
"type": "null"
4013-
}
4014-
],
4015-
"description": "Organization ID for scoping queries (env: KNOWLEDGE_ORG_ID)",
4016-
"title": "Org Id"
4017-
},
40183994
"query": {
40193995
"anyOf": [
40203996
{

scripts/generate_block_reference.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
def extract_schemas() -> dict[str, dict[str, Any]]:
5959
"""Extract schemas and metadata from all registered executors."""
6060
registry = create_default_registry()
61+
62+
# Add KnowledgeExecutor — conditionally loaded at runtime but always in docs
63+
from workflows_mcp.engine.executors_knowledge import KnowledgeExecutor
64+
65+
registry.register(KnowledgeExecutor())
66+
6167
result = {}
6268

6369
for type_name in registry.list_types():

scripts/generate_schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def main() -> None:
2121
# Create registry with all built-in executors
2222
registry = create_default_registry()
2323

24+
# Add KnowledgeExecutor — conditionally loaded at runtime but always in schema
25+
from workflows_mcp.engine.executors_knowledge import KnowledgeExecutor
26+
27+
registry.register(KnowledgeExecutor())
28+
2429
# Generate complete schema
2530
schema = registry.generate_workflow_schema()
2631

src/workflows_mcp/engine/executor_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ def test_workflow():
635635
from .executors_http import HttpCallExecutor
636636
from .executors_image import ImageGenExecutor
637637
from .executors_interactive import PromptExecutor
638-
from .executors_knowledge import KnowledgeExecutor
639638
from .executors_llm import EmbeddingExecutor, LLMCallExecutor
640639
from .executors_sql import SqlExecutor
641640
from .executors_state import (
@@ -677,7 +676,7 @@ def test_workflow():
677676
# Register SQL executor
678677
registry.register(SqlExecutor())
679678

680-
# Register Knowledge executor
681-
registry.register(KnowledgeExecutor())
679+
# Note: KnowledgeExecutor is registered conditionally at server startup
680+
# only when a knowledge database is configured (KNOWLEDGE_DB_HOST)
682681

683682
return registry

0 commit comments

Comments
 (0)