Skip to content

Fix [FromServices]/[FromContext] parameters leaking into MCP tool schemas#13

Merged
carldebilly merged 2 commits intomainfrom
dev/cdb/fix-doc-schema-leak
Mar 29, 2026
Merged

Fix [FromServices]/[FromContext] parameters leaking into MCP tool schemas#13
carldebilly merged 2 commits intomainfrom
dev/cdb/fix-doc-schema-leak

Conversation

@carldebilly
Copy link
Copy Markdown
Member

@carldebilly carldebilly commented Mar 29, 2026

Summary

  • The documentation model builder (CoreReplApp.Documentation.cs) did not filter [FromServices] or [FromContext] parameters, causing them to appear as user-facing properties in MCP tool JSON schemas. The OptionSchemaBuilder already excluded them correctly, so runtime binding was unaffected — but LLM agents saw spurious parameters (e.g. service type names like manager, viewers) in tool definitions.
  • Add MCP end-to-end tests covering nested context patterns (session → {id} → screenshot/info) with service injection, including a schema assertion that [FromServices] params are excluded.
  • Add configureServices support to McpTestFixture for DI-enabled test scenarios.

Test plan

  • New test When_HandlerHasFromServicesParams_Then_SchemaExcludesThem verifies service params are absent from schema
  • New tests When_ContextToolCallWithOptionalParams_Then_Succeeds / WithoutOptionalParams cover multi-command context dispatch
  • Full suite: 743 tests, 0 failures

Open with Devin

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();
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Address code-quality review: use ! after FluentAssertions NotBeNull()
so the compiler knows the variable is non-null for subsequent calls.
@carldebilly carldebilly merged commit ab897dd into main Mar 29, 2026
12 checks passed
@carldebilly carldebilly deleted the dev/cdb/fix-doc-schema-leak branch March 29, 2026 17:19
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.

1 participant