Skip to content

Fix optional 'content' parameter being marked required in MCP schema#6

Open
strela070 wants to merge 1 commit into
HYMMA:masterfrom
strela070:fix/optional-content-param
Open

Fix optional 'content' parameter being marked required in MCP schema#6
strela070 wants to merge 1 commit into
HYMMA:masterfrom
strela070:fix/optional-content-param

Conversation

@strela070

Copy link
Copy Markdown

Summary

Fixes #5.

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 File.ReadAllTextAsync when it is null:

content ??= await File.ReadAllTextAsync(filePath, ct);

However, the parameters were declared as string? content without a default value, and the MCP SDK (AIFunctionFactory) marks parameters without defaults as required in 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

  • Added = null defaults to all string? content tool parameters
  • Added = default to the trailing CancellationToken parameters where required by C# optional-parameter ordering rules

No 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/list schema after the change — content no longer in required for any tool:

csharp_set_workspace      required=['path']
csharp_definition         required=['filePath', 'line', 'character']
csharp_completions        required=['filePath', 'line', 'character']
csharp_code_actions       required=['filePath', 'startLine', 'startCharacter', 'endLine', 'endCharacter']
csharp_references         required=['filePath', 'line', 'character']
csharp_diagnostics        required=['filePath']
csharp_rename             required=['filePath', 'line', 'character', 'newName']
csharp_hover              required=['filePath', 'line', 'character']
csharp_symbols            required=['filePath']

Functional test on a real multi-project solution (macOS arm64): csharp_set_workspace + csharp_symbols without content correctly reads the file from disk and returns document symbols.

🤖 Generated with Claude Code

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>
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.

Optional 'content' parameter incorrectly marked as required in MCP schema for csharp_diagnostics, csharp_symbols, and csharp_code_actions

1 participant