-
Notifications
You must be signed in to change notification settings - Fork 91
feat(mcp): add list-indexes discovery tool (RAAE-1605) #630
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
Open
vishal-bala
wants to merge
2
commits into
feature/raae-1604-config-runtime-model
Choose a base branch
from
feature/raae-1605-list-indexes
base: feature/raae-1604-config-runtime-model
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from redisvl.mcp.auth import ensure_tool_scope | ||
| from redisvl.mcp.runtime import BindingRuntime | ||
|
|
||
| if TYPE_CHECKING: | ||
| from redisvl.mcp.server import RedisVLMCPServer | ||
|
|
||
| DEFAULT_LIST_INDEXES_DESCRIPTION = ( | ||
| "List the logical indexes configured on this server. Each entry reports the " | ||
| "index id, an optional description, whether upsert is available, the " | ||
| "filterable fields discovered from the index, and any explicitly configured " | ||
| "limits. Call this first on a multi-index server to choose the correct " | ||
| "index for search-records or upsert-records." | ||
| ) | ||
|
|
||
| # Runtime limits surfaced to clients, included only when explicitly configured. | ||
| _LIMIT_FIELDS = ("max_limit", "max_upsert_records") | ||
|
|
||
|
|
||
| def _binding_fields(binding_runtime: BindingRuntime) -> list[dict[str, str]]: | ||
| """Return a binding's shared filterable fields from its inspected schema. | ||
|
|
||
| The vector field and the configured default embed-source text field are | ||
| omitted: they are implementation inputs, not fields a client filters on. | ||
| """ | ||
| embed_source = binding_runtime.binding.runtime.default_embed_text_field | ||
| fields: list[dict[str, str]] = [] | ||
| for field in binding_runtime.schema.fields.values(): | ||
| field_type = str(getattr(field.type, "value", field.type)) | ||
| if field_type.lower() == "vector": | ||
| continue | ||
| if field.name == embed_source: | ||
| continue | ||
| fields.append({"name": field.name, "type": field_type}) | ||
| return fields | ||
|
|
||
|
|
||
| def _binding_limits(binding_runtime: BindingRuntime) -> dict[str, int]: | ||
| """Return runtime limits that were explicitly configured for the binding. | ||
|
|
||
| Defaults are intentionally excluded so the output reflects deliberate | ||
| overrides rather than implementation defaults. | ||
| """ | ||
| runtime = binding_runtime.binding.runtime | ||
| configured = runtime.model_fields_set | ||
| return { | ||
| name: getattr(runtime, name) for name in _LIMIT_FIELDS if name in configured | ||
| } | ||
|
|
||
|
|
||
| def _describe_binding(binding_runtime: BindingRuntime) -> dict[str, Any]: | ||
| """Build the deterministic discovery payload for a single binding.""" | ||
| entry: dict[str, Any] = {"id": binding_runtime.binding_id} | ||
| if binding_runtime.binding.description is not None: | ||
| entry["description"] = binding_runtime.binding.description | ||
| # Reflects both global read-only and the per-index read_only policy. | ||
| entry["upsert_available"] = not binding_runtime.effective_read_only | ||
| entry["fields"] = _binding_fields(binding_runtime) | ||
| limits = _binding_limits(binding_runtime) | ||
| if limits: | ||
| entry["limits"] = limits | ||
| return entry | ||
|
|
||
|
|
||
| def list_indexes(server: "RedisVLMCPServer") -> dict[str, Any]: | ||
| """Return the discovery payload for every configured binding. | ||
|
|
||
| The Redis index name (``redis_name``) is intentionally never exposed. | ||
| """ | ||
| return { | ||
| "indexes": [ | ||
| _describe_binding(binding_runtime) | ||
| for binding_runtime in server._bindings.values() | ||
| ], | ||
| } | ||
|
|
||
|
|
||
| def register_list_indexes_tool(server: "RedisVLMCPServer") -> None: | ||
| """Register the always-available, read-only `list-indexes` MCP tool.""" | ||
| description = ( | ||
| getattr(server.mcp_settings, "tool_list_indexes_description", None) | ||
| or DEFAULT_LIST_INDEXES_DESCRIPTION | ||
| ) | ||
|
|
||
| async def list_indexes_tool(): | ||
| """FastMCP wrapper for the `list-indexes` tool.""" | ||
| read_scope = getattr(getattr(server, "auth_config", None), "read_scope", None) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might need a rethink: The double
Claude tells me this also happens in |
||
| ensure_tool_scope(server, read_scope) | ||
| return list_indexes(server) | ||
|
|
||
| server.tool(name="list-indexes", description=description)(list_indexes_tool) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code,
descriptionis not used.