Merge pull request #1167 from arnoldwender/fix/kg-date-validation
fix(kg): validate ISO-8601 date formats at MCP boundary
This commit is contained in:
@@ -55,6 +55,7 @@ from .config import ( # noqa: E402
|
||||
sanitize_kg_value,
|
||||
sanitize_name,
|
||||
sanitize_content,
|
||||
sanitize_iso_date,
|
||||
)
|
||||
from .version import __version__ # noqa: E402
|
||||
from chromadb.errors import NotFoundError as _ChromaNotFoundError # noqa: E402
|
||||
@@ -1059,6 +1060,7 @@ def tool_kg_query(entity: str, as_of: str = None, direction: str = "both"):
|
||||
"""Query the knowledge graph for an entity's relationships."""
|
||||
try:
|
||||
entity = sanitize_kg_value(entity, "entity")
|
||||
as_of = sanitize_iso_date(as_of, "as_of")
|
||||
except ValueError as e:
|
||||
return {"error": str(e)}
|
||||
if direction not in ("outgoing", "incoming", "both"):
|
||||
@@ -1092,6 +1094,7 @@ def tool_kg_add(
|
||||
subject = sanitize_kg_value(subject, "subject")
|
||||
predicate = sanitize_name(predicate, "predicate")
|
||||
object = sanitize_kg_value(object, "object")
|
||||
valid_from = sanitize_iso_date(valid_from, "valid_from")
|
||||
except ValueError as e:
|
||||
return {"success": False, "error": str(e)}
|
||||
|
||||
@@ -1135,6 +1138,7 @@ def tool_kg_invalidate(subject: str, predicate: str, object: str, ended: str = N
|
||||
subject = sanitize_kg_value(subject, "subject")
|
||||
predicate = sanitize_name(predicate, "predicate")
|
||||
object = sanitize_kg_value(object, "object")
|
||||
ended = sanitize_iso_date(ended, "ended")
|
||||
except ValueError as e:
|
||||
return {"success": False, "error": str(e)}
|
||||
resolved_ended = ended or date.today().isoformat()
|
||||
|
||||
Reference in New Issue
Block a user