fix: coerce MCP integer arguments to native Python int - #84
Merged
Conversation
ChromaDB requires native `int` for `n_results`, but the MCP JSON-RPC transport can deliver JSON integers as floats or strings depending on the client implementation. This causes `mempalace_search` (and any tool with integer params like `max_hops`, `last_n`) to fail with: "Expected requested number of results to be a int, got 3 in query." Fix: auto-coerce tool arguments based on the declared `input_schema` types before calling handlers. This covers all current and future tools generically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GoodOlClint
added a commit
to GoodOlClint/mempalace
that referenced
this pull request
Apr 7, 2026
MCP JSON transport delivers numbers as floats/strings. ChromaDB and Python slicing require native int. Inspects input_schema and coerces before dispatch. Upstream: MemPalace#84 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
GoodOlClint
added a commit
to GoodOlClint/mempalace
that referenced
this pull request
Apr 7, 2026
Adds _validate_tool_args() that checks required params and types against input_schema, returning JSON-RPC -32602 errors instead of Python tracebacks. Applied after type coercion from PR MemPalace#84. Upstream: MemPalace#91 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
igorls
pushed a commit
that referenced
this pull request
Aug 11, 2026
dialect.py: all 11 text-mode open() calls (6 read, 5 write) omitted encoding=, so on a non-UTF-8-locale process (e.g. German Windows / cp1252) UTF-8-written JSON and AAAK text is decoded via the OS codepage, corrupting umlauts. config.py: 4 text opens lacked encoding= (config.json + people_map read paths, two writes); the other json.dump write paths already pinned UTF-8. Audit findings #51 (dialect.py:360) and #84 (config.py:377). Regression: tests/test_encoding_hardening.py forces cp1252 default open and asserts umlaut round-trips through from_config / config.json read / raw-UTF-8 skip_name.
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
integer-typed arguments as floats (3.0) or strings ("3") depending on the clientcollection.query(n_results=...)requires a native Pythonint, causingmempalace_searchto fail with:"Expected requested number of results to be a int, got 3 in query."limit(search),max_hops(traverse),last_n(diary_read)Fix
Auto-coerce tool arguments in
handle_request()based on the declaredinput_schematypes before calling handlers. This is generic — covers all current and future tools without per-handler changes.Reproduction
Test plan
limit=3(int) — works before and afterlimit=3.0(float from JSON) — fails before, works afterlimit="3"(string) — fails before, works afterDiscovered while using MemPalace via Claude Code MCP integration.
🤖 Generated with Claude Code