Skip to content

Conversation

@PeterZZZ
Copy link
Contributor

@PeterZZZ PeterZZZ commented Nov 8, 2025

Purpose of the change

This PR adds support for string-formatted parameters to improve compatibility with Claude Code and other MCP clients that pass parameters as JSON strings rather than pre-parsed objects.

Description

This change enhances the add_memory and search_memory tools to accept parameters in multiple formats:

Nested object format (existing): {"param": {"user_id": "user", "content": "..."}}
Flat format (new): {"user_id": "user", "content": "..."}

Fixes/Closes

Fixes # 476
#476

Type of change

[Please delete options that are not relevant.]

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Set up the MemMachine MCP server with Claude Code
Test add_memory with string-formatted parameters
Test search_memory with string-formatted parameters
Verify backward compatibility with existing object-based parameters

[Please delete options that are not relevant.]

  • Unit Test
  • Manual verification (list step-by-step instructions)

Test Results: [Attach logs, screenshots, or relevant output]

✅ Successfully parses JSON string parameters
✅ Maintains backward compatibility with existing parameter formats
✅ Validation errors from Claude Code MCP integration resolved

[Please delete options that are not relevant.]

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • My changes generate no new warnings
  • I have checked my code and corrected any misspellings

Copy link
Contributor

@o-love o-love left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it would be better to choose just one approach, or a param model or flatten the options.

Having everything be optional can be confusing for the model and breaks the pydantic garentee.

I tried to have the Pydantic model flattened but fastmcp didn't like it.

On FastMcp's side, they seem to be against auto flattening.
See:

Maybe it could be easy to create our own decorator that flattens it?

cc @jealous

Copy link
Contributor

@jealous jealous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Peter, could you please add new test cases in test_mcp_stdio.py? The arguments should be the new format. Thanks.

@jealous
Copy link
Contributor

jealous commented Nov 10, 2025

I am not sure how we can implement an auto flatten. Maybe we can investigate.

@o-love
Copy link
Contributor

o-love commented Nov 10, 2025

It looks like this is a current issue with Claude code.
Since making that comment the following project referenced the same FastMCP issue and implemented a decorator.

https://github.com/dougborg/katana-openapi-client/blob/main/katana_mcp_server/src/katana_mcp/unpack.py

It can be a future work

@jealous
Copy link
Contributor

jealous commented Nov 12, 2025

@PeterZZZ , still has some format error and type error to fix. You can follow the logs in the action's output.

@jealous jealous merged commit ddbe76e into MemMachine:main Nov 12, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants