Skip to content

Forward backend instructions in vMCP - #7047

Draft
Viphava280444 wants to merge 3 commits into
stacklok:mainfrom
Viphava280444:feat/vmcp-forward-instructions
Draft

Viphava280444 wants to merge 3 commits into
stacklok:mainfrom
Viphava280444:feat/vmcp-forward-instructions

Conversation

@Viphava280444

@Viphava280444 Viphava280444 commented Nov 3, 2026 •

Copy link
Copy Markdown

Summary

  • Why: a backend's instructions text (from its initialize or server/discover result) never reaches vMCP's clients, so the guidance a backend author wrote for the model is lost behind the gateway (vMCP drops the instructions of backend servers #7020).
  • What: an opt-in aggregation.instructions setting. With forward: true, vMCP's own initialize and server/discover results carry one block per backend, labelled with the backend ID and sorted by it, for the backends the calling identity may use:
    • pkg/vmcp/client: keep the backend's instructions from the Legacy initialize result and the Modern discover result in CapabilityList.
    • pkg/vmcp/aggregator: collect them per backend (AggregatedCapabilities.BackendInstructions).
    • pkg/vmcp/core: Discover returns the instructions of the backends that keep at least one admitted capability, so the text follows the same admission and health filters as tools/list.
    • pkg/vmcp/config: InstructionsConfig{Forward, MaxLength} with validation; CRD, deepcopy and docs regenerated.
    • pkg/vmcp/server: merge and cap the blocks; serve them through server.WithInstructionsFunc on the Legacy path and in the Modern server/discover result. A block that does not fit maxLength (default 16384) is skipped whole and logged.
    • Backends that send no text add no block; when nothing remains the field is omitted. Default off, so existing deployments do not change.
aggregation:
  instructions:
    forward: true
    maxLength: 16384   # optional
[github]
Use the repository's full name in every call.

[jira]
Search for an existing issue before creating one.

Fixes #7020

Type of change

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

Test plan

  • Unit tests (task test): go test -race ./pkg/vmcp/..., 43 packages
  • E2E tests (task test-e2e): not added, see below
  • Linting (task lint-fix): golangci-lint run ./pkg/vmcp/..., 0 issues
  • Manual testing (describe below)

Manual: thv vmcp serve in front of two FastMCP backends, one with an instructions text and one without. With forward: true, initialize and server/discover return "instructions": "[demo]\nStart with hello. Never call it twice."; the backend without text adds no block. With forward: false, the key is absent.

E2E: the e2e backend image (yardstick) sends no instructions, so there is nothing to assert end to end. Happy to add one against a fixture that sends some.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Two optional fields are added under aggregation.instructions (forward, maxLength), both opt-in. No existing field changes.

Changes

File Change
pkg/vmcp/server/instructions.go merge, cap, per-caller lookup
pkg/vmcp/core/core_vmcp.go keep only admitted backends
pkg/vmcp/client/client.go capture the text, Legacy and Modern
pkg/vmcp/config/config.go, validator.go InstructionsConfig, default, validation
pkg/vmcp/server/serve.go, modern_dispatch.go wire both paths
zz_generated.deepcopy.go, CRD YAML, crd-api.md generated, 135 lines
12 *_test.go 625 lines

Does this introduce a user-facing change?

Yes: a new optional aggregation.instructions setting (forward, maxLength) in the vMCP config and the VirtualMCPServer CRD. Off by default.

Special notes for reviewers

  • Depends on Add server instructions options to mcpcompat toolhive-core#453 (server.WithInstructionsFunc). Until that is released, the commit "Pin toolhive-core to the fork" points go.mod at the Add server instructions options to mcpcompat toolhive-core#453 commit on my fork so CI can build. I will drop that commit, fold the test-only follow-up into the feature commit, and bump the version before taking this out of draft.
  • Size: 1,150 changed lines in 34 files. 135 are generated (deepcopy, CRD YAML, crd-api.md) and 625 are tests. The hand-written code is about 300 lines across the five layers above, each a small addition that follows the layer's existing pattern.
  • The label is a convention for the client, not a security boundary: a backend could write [other] inside its own text. Backends are trusted in the aggregation model; the per-caller filter only decides whose text is included.

A backend's `instructions` text (from its initialize or server/discover
result) never reached vMCP's clients: the backend client kept only the
capabilities, and the virtual server's own results had no such field.

Add an opt-in setting, aggregation.instructions {forward, maxLength}.
With forward: true, the virtual server's initialize and server/discover
results carry one block per backend, in backend ID order, labelled with
the backend ID (the workload name), joined by a blank line. Only the
backends the calling identity may use are included: core.Discover
applies the same admission and health filters as tools/list. Backends
that send no text add no block; when nothing remains the field is
omitted. maxLength (bytes, default 16384) caps the merged text; a block
that does not fit is skipped whole and logged.

The backend client records the text on both handshake paths
(CapabilityList.Instructions); the aggregator carries it per backend
(AggregatedCapabilities.BackendInstructions); the core filters it per
identity (DiscoverCapabilities.BackendInstructions); the server renders
it, through the SDK shim's WithInstructionsFunc on the Legacy path and
on the discover result on the Modern path. The default is off, so
existing deployments do not change. The CRD gains two optional fields;
generated files, docs and the example config are updated.

Needs toolhive-core with server.WithInstructionsFunc.

Fixes stacklok#7020

Signed-off-by: Viphava280444 <[email protected]>
The vMCP change needs server.WithInstructionsFunc, which is in
stacklok/toolhive-core#453 and not released yet. This replace lets CI
build against that commit on my fork.

Drop this commit and bump the toolhive-core version once the release
is out.

Signed-off-by: Viphava280444 <[email protected]>
The paralleltest lint rule asks every test in the package to call
t.Parallel. These tests already post through a private transport, so
they stay out of the race that httptest.Server.Close causes on
http.DefaultTransport's idle connections.

Signed-off-by: Viphava280444 <[email protected]>
@nilsberberich

Copy link
Copy Markdown
Contributor

Thanks for picking up #7020. We run vMCP v0.58.0 in Kubernetes in front of several backends, and this PR covers a use case we have been looking for. Below is our use case and one design question.

Use case: distributing agent skills through vMCP

We would like to serve agent skills (SKILL.md folders) to MCP clients from one small backend behind vMCP, authorized per group with Cedar like our other backends. The backend exposes each skill file as a resource (skill://<skill>/<path>, the layout of the Skills extension, SEP-2640) and lists the skills in its instructions.

In our tests with Claude Code, server instructions end up verbatim in the model's context. Resources are listed but not shown to the model, so the model reads a skill resource only if the instructions point to it. Without the instructions it never does. The Skills extension methods (skills/list, skills/get) are not used by that client yet. So for us, forwarded instructions plus resources are the only way to make skills discoverable through vMCP today.

The per-identity filtering in this PR fits that well: a user who is not admitted to the skills backend does not see its block. We already checked that resources/list and resources/read go through Cedar per identity (read_resource on Resource::"<uri>"), so the list and the content follow the same rules.

Design question: select backends instead of one global switch

As far as we can read the diff, aggregation.instructions.forward applies to all backends. Several of our backends send instructions that were written for direct use and are not meant for every client session. With forward: true, all of them would be added. Because blocks are ordered by backend ID and a block that exceeds maxLength is skipped whole, a long block from an unrelated backend that sorts earlier can push out the one we actually need, and the client would not notice.

Would you consider a per-backend selection? For example a list next to forward:

aggregation:
  instructions:
    forward: true
    backends: ["skills"]   # optional; empty = all backends, as in the PR today
    maxLength: 16384

Or a per-workload setting under aggregation.tools[], wherever it fits the existing config better. Either would keep the default behaviour of this PR unchanged.

Testing

Once toolhive-core#453 is merged and this PR is out of draft, we are happy to build it and test it in our test cluster against Cedar with two users of different groups: the block is shown or hidden per identity, the cap behaves as described, and the size reaches the client unchanged. We would report the results here.

This branch has not been deployed

No deployments
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.

vMCP drops the instructions of backend servers

2 participants