Merged
Conversation
When a tool call arrived via RunWithServicesAsync, ExecuteCoreAsync would re-parse global options (finding none in the tool tokens) and then call SetSessionBaseline() which overwrote the baseline with empty explicit keys, losing the original --lock-app / --policy values. Skip SetSessionBaseline for sub-invocations so the top-level baseline from the initial mcp serve invocation persists across tool calls.
RunWithServicesAsync is called both by ReplApp (top-level) and by McpToolAdapter (nested tool calls). The previous fix blindly marked all RunWithServicesAsync calls as sub-invocations, which prevented SetSessionBaseline() from ever being called — the baseline stayed empty and MCP tool calls lost the global options. Add RunSubInvocationAsync for the MCP path (skips SetSessionBaseline), keeping RunWithServicesAsync as a normal invocation (sets baseline).
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
RunSubInvocationAsynctoCoreReplAppfor nested command execution (MCP tool calls) that preserves the session baseline established by the top-levelRun()SetSessionBaseline(), and wipe the global options set at startup (e.g.--lock-app,--policy)McpToolAdapternow usesRunSubInvocationAsyncinstead ofRunWithServicesAsyncProblem
When a Repl app uses
UseGlobalOptions<T>()and runs as an MCP server (mcp serve), global options like--lock-app cmd.exeare parsed and baselined on the initialRun(). But each MCP tool call went throughRunWithServicesAsync→ExecuteCoreAsync, which re-parsed the sub-invocation tokens (no global options present), then calledSetSessionBaseline()— overwriting the baseline with an empty set. Any DI-resolved typed options class would see default/null values.Fix
ExecuteCoreAsyncwith anisSubInvocationflag: when true,Update()merges with the existing baseline butSetSessionBaseline()is skippedRunWithServicesAsync(top-level) remains unchangedRunSubInvocationAsync(nested) passesisSubInvocation: trueMcpToolAdaptercallsRunSubInvocationAsyncTests
When_SubInvocationAfterRun_Then_BaselineGlobalOptionsArePreserved— verifies baseline survives a sub-invocationWhen_MultipleSubInvocations_Then_BaselineRemainsStable— verifies baseline survives consecutive sub-invocations