Skip to content

OBSINTA-1383: filter MCP tools by available UI extensions on client#2952

Open
tremes wants to merge 1 commit into
openshift:mainfrom
tremes:filter-available-ui-tools
Open

OBSINTA-1383: filter MCP tools by available UI extensions on client#2952
tremes wants to merge 1 commit into
openshift:mainfrom
tremes:filter-available-ui-tools

Conversation

@tremes

@tremes tremes commented Jun 11, 2026

Copy link
Copy Markdown

Add available_tool_ui_ids field to LLMRequest so clients can report which console UI extensions are installed. Tools declaring an olsUi.id in their metadata are excluded when the corresponding extension is not available, preventing the LLM from calling tools the client cannot render.

This depends on openshift/lightspeed-console#2058

Assisted-by: Claude Code:claude-opus-4-6

Description

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • New Features

    • Added an optional available_tool_ui_ids field to requests (including OpenAPI), allowing clients to specify which tool UIs are available.
    • Tool lists used during documentation summarization are now filtered based on the provided available UI IDs.
  • Bug Fixes

    • Improved consistency when available_tool_ui_ids is omitted (null) or provided as an empty list—behavior is preserved correctly.
    • Tools lacking UI metadata continue to be included as before.
  • Tests

    • Added unit coverage for the new request field and UI-based tool filtering behavior.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 11, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 11, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 11, 2026

Copy link
Copy Markdown

@tremes: This pull request references OBSINTA-1383 which is a valid jira issue.

Details

In response to this:

Add available_tool_ui_ids field to LLMRequest so clients can report which console UI extensions are installed. Tools declaring an olsUi.id in their metadata are excluded when the corresponding extension is not available, preventing the LLM from calling tools the client cannot render.

Assisted-by: Claude Code:claude-opus-4-6

Description

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds available_tool_ui_ids to LLMRequest, forwards it through generate_response into DocsSummarizer, and filters MCP tools by olsUi.id before summarization uses them.

Changes

Available Tool UI ID Filtering

Layer / File(s) Summary
Request schema and endpoint wiring
ols/app/models/models.py, ols/app/endpoints/ols.py, docs/openapi.json, tests/unit/app/models/test_models.py
LLMRequest and the OpenAPI schema add the optional available_tool_ui_ids field, generate_response passes it into DocsSummarizer, and the model test covers omitted, populated, and empty-list values.
DocsSummarizer filtering integration
ols/src/query_helpers/docs_summarizer.py
DocsSummarizer accepts, stores, and documents available_tool_ui_ids, imports the new MCP helper, and filters fetched tools with filter_tools_by_available_ui before downstream processing.
UI ID filter utility and tests
ols/utils/mcp_utils.py, tests/unit/utils/test_mcp_utils.py
filter_tools_by_available_ui filters StructuredTool entries by metadata._meta.olsUi.id, logs exclusions, and the unit tests cover allowed, excluded, and missing-metadata cases.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Endpoint as ols.py generate_response
    participant Summarizer as DocsSummarizer
    participant MCP as get_mcp_tools
    participant Utils as filter_tools_by_available_ui

    Client->>Endpoint: request with available_tool_ui_ids
    Endpoint->>Summarizer: construct(available_tool_ui_ids)
    Summarizer->>MCP: get_mcp_tools()
    MCP-->>Summarizer: tools
    Summarizer->>Utils: filter_tools_by_available_ui(tools, ids)
    Utils-->>Summarizer: filtered tools
    Summarizer-->>Endpoint: response generation continues
    Endpoint-->>Client: final response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: filtering MCP tools based on available client UI extensions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xrajesh for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tremes tremes marked this pull request as ready for review June 12, 2026 08:34
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 12, 2026
@tremes tremes force-pushed the filter-available-ui-tools branch from 09a39b3 to c979fc5 Compare July 2, 2026 07:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/utils/test_mcp_utils.py (1)

653-717: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test names omit the function under test.

Per repository guidelines, test naming should follow test_<function>_<scenario>, but these methods (e.g. test_none_available_ids_returns_all) drop filter_tools_by_available_ui from the name. The class name provides some context, but explicit naming would improve traceability in test-failure output.

As per coding guidelines, "Follow the test naming convention test_<function>_<scenario>."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/utils/test_mcp_utils.py` around lines 653 - 717, The test method
names in TestFilterToolsByAvailableUI do not follow the required
test_<function>_<scenario> pattern. Rename each test to include
filter_tools_by_available_ui in the method name, keeping the scenario-specific
suffixes, so failures are easier to trace back to the function under test.

Source: Coding guidelines

ols/src/query_helpers/docs_summarizer.py (1)

431-436: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a DocsSummarizer-level test for the new filtering wiring.

The provided cohort only includes unit tests for filter_tools_by_available_ui itself; there's no test verifying that DocsSummarizer.generate_response actually calls it with self.available_tool_ui_ids and applies the filtered tool list downstream. Given this sits on a critical tool-calling path, a focused test would guard against future regressions (e.g., accidental removal or reordering relative to the skill-support-tool append at Line 438).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ols/src/query_helpers/docs_summarizer.py` around lines 431 - 436, Add a
focused DocsSummarizer-level test around generate_response to verify the new
filtering wiring is exercised end-to-end. The test should confirm that after
get_mcp_tools returns tools, filter_tools_by_available_ui is called with
self.available_tool_ui_ids and that the filtered list is the one passed
downstream, including before any later skill-support-tool append logic in
generate_response. Use the DocsSummarizer.generate_response flow and the
filter_tools_by_available_ui call site as the key symbols to anchor the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ols/utils/mcp_utils.py`:
- Around line 204-218: The tool filtering logic in `mcp_utils` can crash when
`_meta["olsUi"]` is `None` or not a dict because `meta.get("olsUi",
{}).get("id")` assumes a mapping. Update the filtering code around
`meta`/`ols_ui_id` to defensively validate `olsUi` the same way `meta` is
checked, only reading `"id"` when `olsUi` is a dict and otherwise treating it as
missing before the `available_set` check.

---

Nitpick comments:
In `@ols/src/query_helpers/docs_summarizer.py`:
- Around line 431-436: Add a focused DocsSummarizer-level test around
generate_response to verify the new filtering wiring is exercised end-to-end.
The test should confirm that after get_mcp_tools returns tools,
filter_tools_by_available_ui is called with self.available_tool_ui_ids and that
the filtered list is the one passed downstream, including before any later
skill-support-tool append logic in generate_response. Use the
DocsSummarizer.generate_response flow and the filter_tools_by_available_ui call
site as the key symbols to anchor the test.

In `@tests/unit/utils/test_mcp_utils.py`:
- Around line 653-717: The test method names in TestFilterToolsByAvailableUI do
not follow the required test_<function>_<scenario> pattern. Rename each test to
include filter_tools_by_available_ui in the method name, keeping the
scenario-specific suffixes, so failures are easier to trace back to the function
under test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c4a5d65-c656-49fc-bf32-a6eae7451b3b

📥 Commits

Reviewing files that changed from the base of the PR and between ed8fdcd and c979fc5.

📒 Files selected for processing (6)
  • ols/app/endpoints/ols.py
  • ols/app/models/models.py
  • ols/src/query_helpers/docs_summarizer.py
  • ols/utils/mcp_utils.py
  • tests/unit/app/models/test_models.py
  • tests/unit/utils/test_mcp_utils.py

Comment thread ols/utils/mcp_utils.py
Add available_tool_ui_ids field to LLMRequest so clients can report
which console UI extensions are installed. Tools declaring an olsUi.id
in their metadata are excluded when the corresponding extension is not
available, preventing the LLM from calling tools the client cannot
render.

Signed-off-by: Tomáš Remeš <tremes@redhat.com>
Assisted-by: Claude Code:claude-opus-4-6
@tremes tremes force-pushed the filter-available-ui-tools branch from c979fc5 to 93221f4 Compare July 2, 2026 09:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/openapi.json (1)

1569-1584: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Schema field added correctly, but docstring/examples not updated.

The new available_tool_ui_ids property is correctly added to the schema, but the LLMRequest description (Line 1592) still only documents the previous attributes and omits available_tool_ui_ids; the examples block also has no sample value for it. Since this file is generated from the LLMRequest docstring in ols/app/models/models.py, update that docstring's Attributes list to keep the generated spec accurate.

Also applies to: 1592-1592

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/openapi.json` around lines 1569 - 1584, The new available_tool_ui_ids
schema field is present in openapi.json, but the source LLMRequest docstring in
models.py still omits it from the Attributes list and examples, so update that
docstring to include available_tool_ui_ids alongside the other request fields
and add a representative example value for it; this will regenerate the openapi
spec with matching documentation and samples.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/openapi.json`:
- Around line 1569-1584: The new available_tool_ui_ids schema field is present
in openapi.json, but the source LLMRequest docstring in models.py still omits it
from the Attributes list and examples, so update that docstring to include
available_tool_ui_ids alongside the other request fields and add a
representative example value for it; this will regenerate the openapi spec with
matching documentation and samples.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 643350ca-382c-4188-8064-0833c386f148

📥 Commits

Reviewing files that changed from the base of the PR and between c979fc5 and 93221f4.

📒 Files selected for processing (7)
  • docs/openapi.json
  • ols/app/endpoints/ols.py
  • ols/app/models/models.py
  • ols/src/query_helpers/docs_summarizer.py
  • ols/utils/mcp_utils.py
  • tests/unit/app/models/test_models.py
  • tests/unit/utils/test_mcp_utils.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • ols/app/models/models.py
  • ols/utils/mcp_utils.py
  • tests/unit/utils/test_mcp_utils.py
  • tests/unit/app/models/test_models.py
  • ols/src/query_helpers/docs_summarizer.py
  • ols/app/endpoints/ols.py

@openshift-ci

openshift-ci Bot commented Jul 2, 2026

Copy link
Copy Markdown

@tremes: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants