[BUG] build_context tool fails when agents pass depth parameter as string instead of integer
Description
The build_context MCP tool in Basic Memory fails when AI agents attempt to call it with the depth parameter as a string value instead of the expected integer type. This appears to be a common issue when agents are automatically generating tool calls.
Steps to Reproduce
- Have an AI agent attempt to call the
build_context tool
- Agent passes depth parameter as a string (e.g.,
"2" instead of 2)
- Tool call fails with parameter type validation error
- This is happening due to the
Optional[int] type for depth in build_context
(I have run into this when building my own MCP servers, it seems to be a limitation with the MCP spec)
Expected Behavior
The tool should either:
- Accept string values and convert them to integers internally
- Provide a more proscriptive schema
- Get rid of the
Optional type for the depth parameter
- Provide clearer error messaging about the expected parameter type
- Handle the type conversion gracefully
Actual Behavior
Tool call fails with error: Input validation error: '3' is not valid under any of the given schemas
Error Message
Environment
- OS: macOS 15.6
- Python version: 3.12.1
- Basic Memory version: 0.14.3
- Installation method: uv
- Claude Desktop version (if applicable): Claude 0.12.55 (d55c63) 2025-07-25T17:43:32.000Z
- Fails in the same way in cursor too
Additional Context
- Configuration files (if relevant)
- Logs or screenshots
- Any special configuration or environment variables
Possible Solution
If you have any ideas on what might be causing the issue or how to fix it, please share them here.
Get rid of the Optional type for the depth parameter
[BUG] build_context tool fails when agents pass depth parameter as string instead of integer
Description
The
build_contextMCP tool in Basic Memory fails when AI agents attempt to call it with thedepthparameter as a string value instead of the expected integer type. This appears to be a common issue when agents are automatically generating tool calls.Steps to Reproduce
build_contexttool"2"instead of2)Optional[int]type fordepthinbuild_context(I have run into this when building my own MCP servers, it seems to be a limitation with the MCP spec)
Expected Behavior
The tool should either:
Optionaltype for thedepthparameterActual Behavior
Tool call fails with error:
Input validation error: '3' is not valid under any of the given schemasError Message
Environment
Additional Context
Possible Solution
If you have any ideas on what might be causing the issue or how to fix it, please share them here.
Get rid of the
Optionaltype for thedepthparameter