Fix [FromServices]/[FromContext] parameters leaking into MCP tool schemas#13
Merged
carldebilly merged 2 commits intomainfrom Mar 29, 2026
Merged
Fix [FromServices]/[FromContext] parameters leaking into MCP tool schemas#13carldebilly merged 2 commits intomainfrom
carldebilly merged 2 commits intomainfrom
Conversation
The documentation builder did not filter parameters decorated with
[FromServices] or [FromContext], causing them to leak into MCP tool
schemas as user-facing properties. The option schema builder already
excluded them, so the runtime binding was unaffected, but LLM agents
saw spurious parameters (e.g. service types) in the tool definitions.
Add context-binding and schema-exclusion MCP end-to-end tests with
multi-command context fixtures mirroring real-world nested-context
patterns (session → {id} → screenshot/info).
|
|
||
| result.IsError.Should().BeFalse("call with optional param should succeed"); | ||
| var text = result.Content.OfType<TextContentBlock>().FirstOrDefault()?.Text; | ||
| text.Should().NotBeNull(); |
|
|
||
| result.IsError.Should().BeFalse("omitting optional params should not cause a binding failure"); | ||
| var text = result.Content.OfType<TextContentBlock>().FirstOrDefault()?.Text; | ||
| text.Should().NotBeNull(); |
Address code-quality review: use ! after FluentAssertions NotBeNull() so the compiler knows the variable is non-null for subsequent calls.
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
CoreReplApp.Documentation.cs) did not filter[FromServices]or[FromContext]parameters, causing them to appear as user-facing properties in MCP tool JSON schemas. TheOptionSchemaBuilderalready excluded them correctly, so runtime binding was unaffected — but LLM agents saw spurious parameters (e.g. service type names likemanager,viewers) in tool definitions.session → {id} → screenshot/info) with service injection, including a schema assertion that[FromServices]params are excluded.configureServicessupport toMcpTestFixturefor DI-enabled test scenarios.Test plan
When_HandlerHasFromServicesParams_Then_SchemaExcludesThemverifies service params are absent from schemaWhen_ContextToolCallWithOptionalParams_Then_Succeeds/WithoutOptionalParamscover multi-command context dispatch