You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using build_context search results contain datetimes specified as a "date-time" type in the output schema.
These data does not adhere to the "ISO 8601 / RFC 3339 style date-time strings (with timezone)".
Steps To Reproduce
Steps to reproduce the behavior:
Install version 0.14.2
Run command 'npx @modelcontextprotocol/inspector uvx basic-memory --project [WHATEVER] mcp'
Use tool/feature 'build_context'
See error
Expected Behavior
created_at: "2025-08-12T13:44:45.344889" should be 2025-08-12T13:44:45.344889Z with a "Z" appended if no time zone information is available.
Actual Behavior
Validation Error: data.results[0].primary_result.created_at should match format "date-time"
created_at: "2025-08-12T13:44:45.344889"
Environment
OS: [Windows 11]
Python version: [e.g. 3.12.9]
Basic Memory version: [e.g. 0.14.2]
Installation method: uv
Additional Context
Possible Solution
Introduce a utility function like this:
defto_rfc3339(dt: Union[datetime,str])->datetime:
"""Converts a datetime object or ISO 8601 string to a timezone-aware UTC datetime, suitable for RFC 3339."""ifisinstance(dt,str):
dt=datetime.fromisoformat(dt)ifdt.tzinfois None:
# AssumeUTCifnotimezoneinforeturndt.replace(tzinfo=timezone.utc)returndt.astimezone(timezone.utc)
and use in search_repository.py and context_service.py
Test build_context functionality to verify datetime issue
Implement fix for datetime timezone serialization
Run tests and linting
Issue Analysis
The bug was still present after PR #266. While the codebase correctly uses timezone-aware datetime objects (UTC), Pydantic's default JSON serialization wasn't including timezone information in the serialized strings, causing MCP validation to fail.
Root Cause: Datetime fields were being serialized as "2025-08-12T13:44:45.344889" instead of the required RFC 3339 format "2025-08-12T13:44:45.344889+00:00" or "2025-08-12T13:44:45.344889Z".
Solution Implemented
Added proper datetime serialization to ensure RFC 3339 compliance:
Created utility functionensure_timezone_aware() that converts naive datetimes to UTC
Added @field_serializer decorators to all datetime fields in:
EntitySummary.created_at
RelationSummary.created_at
ObservationSummary.created_at
MemoryMetadata.generated_at
All datetime fields now serialize with proper timezone information (+00:00 suffix)
The fix ensures that all datetime responses from build_context and other MCP tools will pass validation by including proper timezone information as required by the RFC 3339 specification.
Activity
jope-bm commentedon Aug 22, 2025
@claude Can you take a look at this and see if it is still an issue? It may have been fixed by this pull request: #266
claude commentedon Aug 22, 2025
Claude finished @jope-bm's task —— View job •
claude/issue-253-20250822-1537• Create PR ➔Datetime validation issue investigation completed ✅
I investigated and fixed the datetime validation issue reported in this bug.
Todo List:
Issue Analysis
The bug was still present after PR #266. While the codebase correctly uses timezone-aware datetime objects (UTC), Pydantic's default JSON serialization wasn't including timezone information in the serialized strings, causing MCP validation to fail.
Root Cause: Datetime fields were being serialized as
"2025-08-12T13:44:45.344889"instead of the required RFC 3339 format"2025-08-12T13:44:45.344889+00:00"or"2025-08-12T13:44:45.344889Z".Solution Implemented
Added proper datetime serialization to ensure RFC 3339 compliance:
Created utility function
ensure_timezone_aware()that converts naive datetimes to UTCAdded
@field_serializerdecorators to all datetime fields in:EntitySummary.created_atRelationSummary.created_atObservationSummary.created_atMemoryMetadata.generated_atAll datetime fields now serialize with proper timezone information (
+00:00suffix)Files Modified
src/basic_memory/schemas/memory.py- Added timezone-aware datetime serializationThe fix ensures that all datetime responses from
build_contextand other MCP tools will pass validation by including proper timezone information as required by the RFC 3339 specification.fix: Ensure datetime serialization includes timezone info for RFC 333…
fix: Ensure all datetime operations return timezone-aware objects