fix(mcp): preserve Snowflake ID precision across MCP tool boundary - #1100
Merged
wayyoungboy merged 1 commit intoJun 29, 2026
Merged
Conversation
Snowflake IDs are 64-bit integers that exceed JavaScript's
Number.MAX_SAFE_INTEGER (2^53 - 1). When the MCP layer declared
memory_id as int and serialized id fields as JSON numbers, V8-based
clients (including Claude Code) silently rounded them, breaking
subsequent update/delete round-trips.
- Change memory_id parameter type from int to str in get_memory_by_id,
update_memory, delete_memory, delete_memory_with_profile; coerce to
int inside the function body so the Python SDK contract is unchanged.
- Add _stringify_ids helper that recursively stringifies id/memory_id
int fields in MCP responses, skipping metadata sub-dicts so
user-provided numeric fields are preserved.
- Return {"success": False, "error": "..."} on non-numeric memory_id
instead of raising, mirroring add_memory's error style.
Closes oceanbase#1098
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1098.
Snowflake IDs (64-bit integers, e.g.
725653563933458432) exceed JavaScript'sNumber.MAX_SAFE_INTEGER(2^53 − 1 =9007199254740991). The MCP tool layer declaredmemory_idasintand serializedidfields as JSON numbers, so V8-based clients (including Claude Code) silently rounded them — e.g.725653563933458432→725653563933458400— causingupdate_memory/delete_memory/get_memory_by_id/delete_memory_with_profileto 404 on any memory added in the same MCP session.The REST API layer already handles this via
@field_serializeronmemory_id; this PR brings the MCP layer to parity.Changes
memory_id: int→memory_id: strin the 4 affected tool signatures. FastMCP now emits"type": "string"in the JSON schema, so clients treat the ID as an opaque string. The function body coerces toint(memory_id)before calling the Python SDK, so the SDK contract is unchanged._stringify_idshelper recursively convertsid/memory_idint fields to strings in MCP responses, applied in_fmt.metadatasub-dicts are passed through unchanged so user-provided numeric fields are not silently rewritten.memory_id(e.g."abc") returns{"success": False, "error": "memory_id must be a numeric string"}instead of raising — mirrorsadd_memory's error style.Test plan
New
tests/unit/test_mcp_snowflake_id.py(23 tests) covers:memory_idas"type": "string"(notinteger/anyOf);limitstaysinteger,delete_profilestaysboolean.int(memory_id)to the underlying SDK with exact precision (mock assertion)."abc"returns{"success": False, ...}and does not call the SDK.id, nestedresults[].id,memory_idkey all stringified; non-ID ints (count,limit,threshold) and string IDs (user_id,agent_id) untouched; bool not stringified (it is a subclass of int).{"id": 725..., "metadata": {"id": 42}}→ top-levelidstringified,metadata.idpreserved as int.add_memoryreturns string id; passing it back toupdate_memorycallsmemory.update(memory_id=725653563933458432)(mock assertion).delete_memory_with_profileresponse:memory_idkey stringified.Existing MCP tests (
tests/unit/server/test_main_mcp_optional.py,tests/unit/test_optional_dependency_imports.py) continue to pass — no regression in import / FastMCP registration paths.