Repository navigation
Add server instructions options to mcpcompat - #453
Open
Viphava280444 wants to merge 1 commit into
Open
Viphava280444 wants to merge 1 commit into
Viphava280444 wants to merge 1 commit into
Conversation
The shim had no way to set the `instructions` field of the initialize result, and go-sdk serves ServerOptions.Instructions verbatim to every session. An aggregator such as vMCP needs a different text per caller (only the backends the identity may use), so this adds two options: - WithInstructions(text): static text, mirrors mcp-go's option. - WithInstructionsFunc(func(ctx) string): computed per request from the request context (the one WithHTTPContextFunc fills). It is applied on the initialize and server/discover results in sessionDispatchMiddleware after go-sdk built them, like stripPublicCacheScope already rewrites results. When both are set the func wins. An empty result omits the field, so servers that set neither option are unchanged. HandleMessage fills the field too. The initialize POST must stay bridged (transports.go), since the func reads the identity there. First half of stacklok/toolhive#7020. Signed-off-by: Viphava280444 <[email protected]>
Viphava280444
added a commit
to Viphava280444/toolhive
that referenced
this pull request
Nov 3, 2026
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]>
This was referenced Nov 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
instructionsof backend servers toolhive#7020: vMCP drops theinstructionstext of its backend servers. To forward it, vMCP has to set theinstructionsfield of its owninitializeandserver/discoverresults, andmcpcompat/serverhas no option for that field. go-sdk copiesServerOptions.Instructionsinto every session as is, while vMCP needs a different text per caller: only the backends that identity may reach.WithInstructions(text)sets a static text, like mcp-go's option of the same name. It is passed through togosdk.ServerOptions.Instructions.WithInstructionsFunc(func(ctx) string)computes the text per request from the request context, the oneWithHTTPContextFuncfills.sessionDispatchMiddlewarewrites it onto theinitializeandserver/discoverresults after go-sdk built them, next tostripPublicCacheScope, which rewrites results for the same reason: go-sdk has no per-session hook for the field.HandleMessagefills the field on its own initialize path.The vMCP side is stacklok/toolhive#7047 (draft; its
go.modis pinned to this commit until this ships).Type of change
Test plan
golangci-lint run ./...andgo vet ./...: 0 issuesgo test -race -count=1 ./...passes (./mcpcompat/server/...run 3 times)mcpcompat/server/instructions_test.go: the default (no field), static text, per-request text (two callers get two texts), the stateless server,server/discover, andHandleMessage. They run in parallel like the rest of the package and post through a private transport, sincehttptest.Server.Closedropshttp.DefaultTransport's idle connections.initializeandserver/discover, per caller.