Skip to content

[BUG] build_context tool fails when agents pass depth parameter as string instead of integer #250

@jacob-morrison-22

Description

@jacob-morrison-22

[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

  1. Have an AI agent attempt to call the build_context tool
  2. Agent passes depth parameter as a string (e.g., "2" instead of 2)
  3. Tool call fails with parameter type validation error
  4. 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
Image

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions