Repository navigation
Forward backend instructions in vMCP - #7047
Viphava280444 wants to merge 3 commits into
Conversation
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]>
|
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 ( In our tests with Claude Code, server 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 Design question: select backends instead of one global switch As far as we can read the diff, Would you consider a per-backend selection? For example a list next to aggregation:
instructions:
forward: true
backends: ["skills"] # optional; empty = all backends, as in the PR today
maxLength: 16384Or a per-workload setting under 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. |
Summary
instructionstext (from itsinitializeorserver/discoverresult) never reaches vMCP's clients, so the guidance a backend author wrote for the model is lost behind the gateway (vMCP drops theinstructionsof backend servers #7020).aggregation.instructionssetting. Withforward: true, vMCP's owninitializeandserver/discoverresults 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'sinstructionsfrom the Legacy initialize result and the Modern discover result inCapabilityList.pkg/vmcp/aggregator: collect them per backend (AggregatedCapabilities.BackendInstructions).pkg/vmcp/core:Discoverreturns the instructions of the backends that keep at least one admitted capability, so the text follows the same admission and health filters astools/list.pkg/vmcp/config:InstructionsConfig{Forward, MaxLength}with validation; CRD, deepcopy and docs regenerated.pkg/vmcp/server: merge and cap the blocks; serve them throughserver.WithInstructionsFuncon the Legacy path and in the Modernserver/discoverresult. A block that does not fitmaxLength(default 16384) is skipped whole and logged.Fixes #7020
Type of change
Test plan
task test):go test -race ./pkg/vmcp/..., 43 packagestask test-e2e): not added, see belowtask lint-fix):golangci-lint run ./pkg/vmcp/..., 0 issuesManual:
thv vmcp servein front of two FastMCP backends, one with an instructions text and one without. Withforward: true,initializeandserver/discoverreturn"instructions": "[demo]\nStart with hello. Never call it twice."; the backend without text adds no block. Withforward: 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
v1beta1API, OR theapi-break-allowedlabel 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
pkg/vmcp/server/instructions.gopkg/vmcp/core/core_vmcp.gopkg/vmcp/client/client.gopkg/vmcp/config/config.go,validator.goInstructionsConfig, default, validationpkg/vmcp/server/serve.go,modern_dispatch.gozz_generated.deepcopy.go, CRD YAML,crd-api.md*_test.goDoes this introduce a user-facing change?
Yes: a new optional
aggregation.instructionssetting (forward,maxLength) in the vMCP config and the VirtualMCPServer CRD. Off by default.Special notes for reviewers
server.WithInstructionsFunc). Until that is released, the commit "Pin toolhive-core to the fork" pointsgo.modat 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.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.[other]inside its own text. Backends are trusted in the aggregation model; the per-caller filter only decides whose text is included.