-
Notifications
You must be signed in to change notification settings - Fork 77
feat(MCP): [4/5] add RedisVL MCP CLI #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vishal-bala
merged 35 commits into
feat/RAAE-1395-redisvl-mcp
from
feat/RAAE-1399-mcp-cli
Apr 8, 2026
Merged
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ef28ac0
RAAE-1396: Create MCP framework for RedisVL
vishal-bala e267c8f
Ensure server shutdown disconnects
vishal-bala 91709b2
Exclude MCP module from import sanity-check
vishal-bala 41eb2fb
Ensure startup failures clean up server resources
vishal-bala 24fec66
Clear index state after MCP server shutdown
vishal-bala f197652
Fix MCP vectorizer cleanup on shutdown failure
vishal-bala 3040ef6
Merge branch 'main' into feat/RAAE-1396/mcp-framework
vishal-bala 1242d7a
Update implementation based on plan
vishal-bala cb3c543
Add filter type-hints; allow float values in `Num`
vishal-bala 7529d61
Implement MCP search-records tool
vishal-bala 9bdbee3
Add Codex config files to .gitignore
vishal-bala 708d284
Merge branch 'feat/RAAE-1395-redisvl-mcp' into feat/RAAE-1397/search-…
vishal-bala 473614a
Adapt type-hints for Python 3.9
vishal-bala 9db4c13
Configure search in config, tool just takes query
vishal-bala aa93dd2
Python 3.9 compat
vishal-bala d8f5e3d
Merge branch 'feat/RAAE-1396/mcp-framework' into feat/RAAE-1397/searc…
vishal-bala 08ca214
Merge branch 'feat/RAAE-1395-redisvl-mcp' into feat/RAAE-1396/mcp-fra…
vishal-bala 962427e
Implement upsert-records tool for RedisVL MCP
vishal-bala ac3cc90
Cache hybrid support checks and validate fallback search params
vishal-bala c748db2
Python 3.9 compat
vishal-bala 32f4a07
Classify malformed search results as internal errors
vishal-bala f475a1f
fix(mcp): validate hash vectors before serialization
vishal-bala 11f5d07
fix(mcp): validate records before embedding
vishal-bala c7b2154
Fix native hybrid linear defaults for RRF
vishal-bala e32ad64
feat: add task-oriented MCP CLI command
vishal-bala 9441c1d
fix: remove eager MCP imports for Python 3.9
vishal-bala 20e6dd2
fix: preserve MCP read-only env defaults
vishal-bala d29d307
feat(mcp): gate requests on server lifecycle
vishal-bala b16f33c
Merge remote-tracking branch 'origin/feat/RAAE-1396/mcp-framework' in…
vishal-bala 384e528
Merge remote-tracking branch 'origin/feat/RAAE-1397/search-tool' into…
vishal-bala 352406b
fix(mcp): deep copy upsert records before load
vishal-bala e705fbb
Merge remote-tracking branch 'origin/feat/RAAE-1398/upsert-tool' into…
vishal-bala 8aef518
Merge branch 'feat/RAAE-1395-redisvl-mcp' into feat/RAAE-1398/upsert-…
vishal-bala 8ca8a62
Merge branch 'feat/RAAE-1398/upsert-tool' into feat/RAAE-1399-mcp-cli
vishal-bala 9433eec
fix(cli): avoid double startup in MCP serve path
vishal-bala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,5 +23,6 @@ reranker | |
| cache | ||
| message_history | ||
| router | ||
| cli | ||
| ``` | ||
|
|
||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """CLI entrypoint for the RedisVL MCP server.""" | ||
|
|
||
| import argparse | ||
| import asyncio | ||
| import inspect | ||
| import sys | ||
|
|
||
|
|
||
| class _MCPArgumentParser(argparse.ArgumentParser): | ||
| """ArgumentParser variant that reports usage errors with exit code 1.""" | ||
|
|
||
| def error(self, message): | ||
| self.print_usage(sys.stderr) | ||
| self.exit(1, "%s: error: %s\n" % (self.prog, message)) | ||
|
|
||
|
|
||
| class MCP: | ||
| """Command handler for `rvl mcp`.""" | ||
|
|
||
| description = "Expose a configured Redis index to MCP clients for search and optional upsert operations." | ||
| epilog = ( | ||
| "Use this command when wiring RedisVL into an MCP client.\n\n" | ||
| "Example:\n" | ||
| " uvx --from redisvl[mcp] rvl mcp --config /path/to/mcp_config.yaml" | ||
| ) | ||
| usage = "\n".join( | ||
| [ | ||
| "rvl mcp --config <path> [--read-only]\n", | ||
| "\n", | ||
| ] | ||
| ) | ||
|
|
||
| def __init__(self): | ||
| """Parse CLI arguments and run the MCP server command.""" | ||
| parser = _MCPArgumentParser( | ||
| usage=self.usage, | ||
| description=self.description, | ||
| epilog=self.epilog, | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| ) | ||
| parser.add_argument("--config", help="Path to MCP config file", required=True) | ||
| parser.add_argument( | ||
| "--read-only", | ||
| help="Disable the upsert tool", | ||
| action="store_true", | ||
| dest="read_only", | ||
| ) | ||
|
|
||
| args = parser.parse_args(sys.argv[2:]) | ||
| self._run(args) | ||
| raise SystemExit(0) | ||
|
|
||
| def _run(self, args): | ||
| """Validate the environment, build the server, and serve stdio requests.""" | ||
| try: | ||
| self._ensure_supported_python() | ||
| settings_cls, server_cls = self._load_mcp_components() | ||
| settings = settings_cls.from_env( | ||
| config=args.config, | ||
| read_only=args.read_only, | ||
| ) | ||
| server = server_cls(settings) | ||
| self._run_awaitable(self._serve(server)) | ||
| except KeyboardInterrupt: | ||
| raise SystemExit(0) | ||
| except Exception as exc: | ||
| self._print_error(str(exc)) | ||
| raise SystemExit(1) | ||
|
|
||
| @staticmethod | ||
| def _ensure_supported_python(): | ||
| """Fail fast when the current interpreter cannot support MCP extras.""" | ||
| if sys.version_info < (3, 10): | ||
| version = "%s.%s.%s" % ( | ||
| sys.version_info.major, | ||
| sys.version_info.minor, | ||
| sys.version_info.micro, | ||
| ) | ||
| raise RuntimeError( | ||
| "RedisVL MCP CLI requires Python 3.10 or newer. " | ||
| "Current runtime is Python %s." % version | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _load_mcp_components(): | ||
| """Import optional MCP dependencies only on the `rvl mcp` code path.""" | ||
| try: | ||
| from redisvl.mcp import MCPSettings, RedisVLMCPServer | ||
| except (ImportError, ModuleNotFoundError) as exc: | ||
| raise RuntimeError( | ||
| "RedisVL MCP support requires optional dependencies. " | ||
| "Install them with `pip install redisvl[mcp]`.\n" | ||
| "Original error: %s" % exc | ||
| ) | ||
|
|
||
| return MCPSettings, RedisVLMCPServer | ||
|
|
||
| @staticmethod | ||
| def _run_awaitable(awaitable): | ||
| """Bridge the synchronous CLI entrypoint to async server lifecycle code.""" | ||
| return asyncio.run(awaitable) | ||
|
|
||
| async def _serve(self, server): | ||
| """Run startup, stdio serving, and shutdown on one event loop.""" | ||
| started = False | ||
|
|
||
| try: | ||
| await server.startup() | ||
| started = True | ||
|
|
||
| # Prefer FastMCP's async transport path so startup, serving, and | ||
| # shutdown all share the same event loop. | ||
| run_async = getattr(server, "run_async", None) | ||
| if callable(run_async): | ||
| await run_async(transport="stdio") | ||
| else: | ||
| result = server.run(transport="stdio") | ||
| if inspect.isawaitable(result): | ||
| await result | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| finally: | ||
| if started: | ||
| try: | ||
| result = server.shutdown() | ||
| if inspect.isawaitable(result): | ||
| await result | ||
| except RuntimeError as exc: | ||
| # KeyboardInterrupt during stdio shutdown can leave FastMCP | ||
| # tearing down after the loop is already closing. | ||
| if "Event loop is closed" not in str(exc): | ||
| raise | ||
|
|
||
| @staticmethod | ||
| def _print_error(message): | ||
| """Emit user-facing command errors to stderr.""" | ||
| print(message, file=sys.stderr) | ||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from redisvl.mcp.config import MCPConfig, load_mcp_config | ||
| from redisvl.mcp.errors import MCPErrorCode, RedisVLMCPError, map_exception | ||
| from redisvl.mcp.server import RedisVLMCPServer | ||
| from redisvl.mcp.settings import MCPSettings | ||
|
|
||
| __all__ = [ | ||
| "MCPConfig", | ||
| "MCPErrorCode", | ||
| "MCPSettings", | ||
| "RedisVLMCPError", | ||
| "RedisVLMCPServer", | ||
| "load_mcp_config", | ||
| "map_exception", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.