Fix optional 'content' parameter being marked required in MCP schema#6
Open
strela070 wants to merge 1 commit into
Open
Fix optional 'content' parameter being marked required in MCP schema#6strela070 wants to merge 1 commit into
strela070 wants to merge 1 commit into
Conversation
The 'content' parameter on csharp_diagnostics, csharp_hover, csharp_completions, csharp_definition, csharp_references, csharp_symbols, csharp_code_actions and csharp_rename is documented as optional, and EnsureDocumentOpenAsync already falls back to reading the file from disk when it is null. However, the parameters were declared as 'string? content' without a default value, and the MCP SDK marks parameters without defaults as required in the generated JSON schema. Clients (e.g. Claude Code) were therefore forced to send the full file content on every call. Add '= null' defaults (and '= default' on the trailing CancellationToken where required by C# syntax) so the schema matches the documented behavior. Fixes HYMMA#5 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Fixes #5.
The
contentparameter oncsharp_diagnostics,csharp_hover,csharp_completions,csharp_definition,csharp_references,csharp_symbols,csharp_code_actionsandcsharp_renameis documented as optional, andEnsureDocumentOpenAsyncalready falls back toFile.ReadAllTextAsyncwhen it isnull:However, the parameters were declared as
string? contentwithout a default value, and the MCP SDK (AIFunctionFactory) marks parameters without defaults asrequiredin the generated JSON schema — nullability alone is not enough. MCP clients (e.g. Claude Code) were therefore forced to send the full file content on every call, which is wasteful for large files.Change
= nulldefaults to allstring? contenttool parameters= defaultto the trailingCancellationTokenparameters where required by C# optional-parameter ordering rulesNo behavioral change for callers that pass
content; callers that omit it now get the documented read-from-disk behavior instead of a schema validation error.Verification
tools/listschema after the change —contentno longer inrequiredfor any tool:Functional test on a real multi-project solution (macOS arm64):
csharp_set_workspace+csharp_symbolswithoutcontentcorrectly reads the file from disk and returns document symbols.🤖 Generated with Claude Code