feat(valkey-mcp-server): V2 — GLIDE migration, 12 focused tools#7
feat(valkey-mcp-server): V2 — GLIDE migration, 12 focused tools#7Jonathan-Improving wants to merge 21 commits into
Conversation
jbrinkman
left a comment
There was a problem hiding this comment.
Code Review: Valkey MCP Server V2 — GLIDE Migration + 9 Focused Tools
Summary
This is a well-structured major rewrite that replaces ~40 generic data-type tools with 9 purpose-built tools for AI Search and JSON operations, migrating from valkey-py to valkey-glide. The architecture is significantly cleaner, the tool surface is more focused, and the pre-validation pattern to prevent GLIDE native crashes is a smart defensive measure.
🟢 What's Good
- Pre-validation pattern — Checking
index_exists()and_require_array()before GLIDE calls prevents native crashes. This is well-tested intest_error_cases_live.py. - Structured JSON input — The aggregate pipeline builder eliminates DSL syntax errors from AI agents. The LOAD field auto-detection is particularly well done.
- Multi-provider embeddings — Clean factory pattern with Bedrock/OpenAI/Ollama/Hash providers. Good separation of concerns.
- Test coverage — 110 unit tests + 35 live integration tests. Error case tests specifically targeting previously-discovered crash scenarios is excellent.
- README rewrite — Troubleshooting table, quickstart, and configuration tables are much more useful than before.
decode_valueutility — Recursive bytes decoding handles GLIDE's raw responses cleanly.
🔴 Issues to Address
-
connection.py— Global singleton race condition (see inline comment)get_client()has no locking. Concurrent coroutines can create duplicate GLIDE clients.
-
main.py—atexithandler will crash (see inline comment)asyncio.run(close_client())fails when an event loop is already running at shutdown.
🟡 Issues to Consider
-
providers.py—OllamaEmbeddingshttpx client never closed — Resource leak over time. -
providers.py—BedrockEmbeddings.__init__makes synchronous STS call — Blocks event loop at startup. -
search_aggregate.py— Wildcard*query rejected — This is a valid FT.AGGREGATE pattern. The restriction limits usability. -
search_query.py—_find_similarpagination bug —limit + 1propagated to offset causes off-by-one when paginating. -
json.py—JSON.SET+EXPIREnot atomic — TTL race condition if process crashes between the two calls. -
json.py— BareExceptioncatching — Swallows programming errors. Consider catchingRequestErrorspecifically. -
providers.py—HashEmbeddingscycles 32 bytes for dimensions > 32 — Produces repeated patterns in test vectors. -
connection.py— Synchronous file read for CA cert — Minor, but blocks event loop if cert is on network storage.
📝 Minor Notes
- The
docs/AEA-355-plan.mdis a great internal document but probably shouldn't ship in the published package. Consider adding it to.gitignoreor adocs/internal/directory. pyproject.tomladdsboto3,openai, andhttpxas hard dependencies. Users who only need JSON tools or text search will pull in AWS SDK and OpenAI SDK unnecessarily. Consider making these optional extras:pip install awslabs.valkey-mcp-server[bedrock],[openai],[ollama].- The
hybrid_weightparameter insearch()is documented as "advisory — reserved for future weighted scoring" but it's used for mode auto-detection (!= 0.5triggers hybrid). This is confusing — either implement weighted scoring or remove the auto-detection behavior.
Verdict
The architecture and tool design are solid. The two 🔴 issues (singleton race condition and atexit crash) should be fixed before merge. The 🟡 items are worth addressing but aren't blockers.
5ba8694 to
b57e4e3
Compare
9107f21 to
78127b8
Compare
…n`) and their respective unit tests. Update AEA-355 plan and main imports to reflect phase completion.
…hared `client` fixture to `conftest.py`
…-RPC transport corruption. Add inline documentation explaining the issue and pre-validation adjustments.
… checks in MCP server and tests. Simplify error handling paths.
…ough environment variables. Refactor JSON operations to utilize `glide_json` for consistency and improved maintainability.
… and embeddings logic
fc380fb to
7464928
Compare
Co-authored-by: Animesh Barua <animebar@amazon.com>
…` injection in search queries.
edlng
left a comment
There was a problem hiding this comment.
Once the note is added to the docstring for hybrid search, lgtm!
…ine default dimension logic, and refactor AWS credential validation.
|
Closing, superceded by duplicated PR on AWS Labs. |
Valkey MCP Server V2 — Focused Search + JSON + Command Runner Tools
Major rewrite of the Valkey MCP server: migrates from
valkey-pyto Valkey-GLIDE, replaces ~40+ generic data-type tools with 12 purpose-built tools (4 AI Search + 5 JSON Intelligence + 3 Command Runners), and adds a multi-provider embeddings layer.What Changed
Architecture:
valkey-pytovalkey-glide(async-native GLIDE client)VALKEY_GLIDE_LOG_LEVELenv varNew Tools:
manage_indexadd_documentssearchaggregatejson_getjson_setjson_arrappendjson_arrpopjson_arrtrimvalkey_readvalkey_writevalkey_adminVALKEY_ADMIN_ENABLED3-Tier Command Safety:
valkey_read— always available, read-only commandsvalkey_write— available unless readonly mode is activevalkey_admin— disabled by default, requiresVALKEY_ADMIN_ENABLED=trueRemoved: All generic data-type tools (Strings, Lists, Sets, Sorted Sets, Hashes, Streams, Bitmaps, HyperLogLog, misc, server_management) — these performed worse than raw CLI in benchmarks.
Safety & Reliability
@tool_errorsdecorator catchesRequestErroronly — programming errors propagate for debugging@readonly_guarddecorator enforces readonly mode on mutating toolsasyncio.Lockon GLIDE client singleton (double-check pattern)threading.Lockon embeddings provider singletonatexitshutdown handler for GLIDE client + Ollama httpx clientTesting
tests/(unit) andtests/integration/(live)pytest-timeoutto prevent hanging testsDocumentation
Related
docs/AEA-355-plan.mdBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.