Skip to content

Annotate vMCP optimizer discovery tool - #6373

Merged
ChrisJBurns merged 5 commits into
stacklok:mainfrom
Whxuan0701:pr/vmcp-find-tool-annotations
Nov 26, 2026
Merged

ChrisJBurns merged 5 commits into
stacklok:mainfrom
Whxuan0701:pr/vmcp-find-tool-annotations

Conversation

@Whxuan0701

@Whxuan0701 Whxuan0701 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The vMCP optimizer exposes find_tool as a local tool-discovery operation, but its MCP definition currently carries no behavioral hints. Clients cannot distinguish this safe discovery step from a tool that may mutate external state, which limits safe retry and tool-selection behavior in Agent workflows.

  • Add MCP annotations to find_tool: read-only, non-destructive, idempotent, and closed-world.
  • Leave call_tool unannotated because it can proxy arbitrary backend side effects.

Part of #4357

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task -t Taskfile.focused.yml test, using the repository's -race and linker settings for ./pkg/vmcp/session/optimizerdec and ./pkg/vmcp/conversion)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

API Compatibility

  • This PR does not break the v1beta1 API.

Changes

File Change
pkg/vmcp/session/optimizerdec/decorator.go Add behavioral annotations to find_tool.
pkg/vmcp/session/optimizerdec/decorator_test.go Assert the discovery tool annotations and preserve the unannotated call_tool contract.

Does this introduce a user-facing change?

Yes. MCP clients that consume tool annotations can now identify find_tool as a safe, retryable local discovery operation.

Special notes for reviewers

The annotation is deliberately limited to find_tool. call_tool dispatches arbitrary backend tools, so asserting read-only or non-destructive behavior there would be incorrect.

Mark find_tool as a read-only, idempotent local discovery operation so MCP clients can make safer retry and tool-selection decisions. Keep call_tool unannotated because it proxies arbitrary backend side effects.

Signed-off-by: XD <[email protected]>
ChrisJBurns
ChrisJBurns previously approved these changes Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.44%. Comparing base (eb40663) to head (be714ed).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6373      +/-   ##
==========================================
+ Coverage   82.40%   82.44%   +0.04%     
==========================================
  Files         937      937              
  Lines       95821    95832      +11     
==========================================
+ Hits        78958    79013      +55     
+ Misses      16858    16814      -44     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ChrisJBurns and others added 2 commits November 26, 2026 15:13
The Serve-path optimizer rebuilt find_tool and call_tool as mcp.Tool
values with only name, description, and schema, dropping the
annotations declared in OptimizerTools. Clients therefore never saw
find_tool's read-only/idempotent hints when the optimizer was enabled.
Convert the definition's annotations the same way the regular tool
path does, and cover the wire output with a tools/list test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ChrisJBurns
ChrisJBurns previously approved these changes Nov 26, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The hints themselves look right to me. find_tool only searches the session's own index, so read-only, non-destructive, idempotent and closed-world all hold. Leaving call_tool unannotated is correct: clients fall back to the spec defaults (destructive, open-world). I ran the optimizer, server, sessionmanager, conversion and authz packages with -race and they pass. A raw tools/list on the Serve path shows the four hints on find_tool, and the cross-pod re-injection path goes through the same builder. The Modern path is gated off for the optimizer, so there is nothing to wire there yet.

One interaction with the authz middleware needs addressing before merge (inline).

The authz annotation cache is keyed by bare tool name, and call_tool
authorizes its inner tool_name through that cache. Filling it from
pass-through meta-tools meant a backend tool sharing a meta-tool's
name was evaluated with the meta-tool's hints. Now that find_tool is
advertised as read-only, that made hint-based Cedar policies more
permissive for such a backend tool. Fill the cache from the regular
tools only; the meta-tools are never authorized through it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix verified. The new test fails without be714ed03 (200 instead of 403) and passes with it, and the authz, optimizer and vMCP server packages pass with -race. Agreed that the shared, bare-name annotation cache is a pre-existing issue and should go in a follow-up issue, not this PR.

@ChrisJBurns
ChrisJBurns merged commit 94af07e into stacklok:main Nov 26, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants