Skip to content

Apply default tool annotation hints from McpServerToolAttribute#1674

Open
goutamadwant wants to merge 1 commit into
modelcontextprotocol:mainfrom
goutamadwant:codex/csharp-sdk-1673-tool-annotation-defaults
Open

Apply default tool annotation hints from McpServerToolAttribute#1674
goutamadwant wants to merge 1 commit into
modelcontextprotocol:mainfrom
goutamadwant:codex/csharp-sdk-1673-tool-annotation-defaults

Conversation

@goutamadwant

Copy link
Copy Markdown

Summary

Apply the documented default values for tool annotation hints when tools are created from McpServerToolAttribute.

Motivation and Context

Fixes #1673.

McpServerToolAttribute exposes default values for Destructive, Idempotent, OpenWorld, and ReadOnly, but tool creation only copied values from the attribute's nullable backing fields. That meant default hint values were not included in the generated tool annotations unless the attribute explicitly set each property.

This change derives those hints from the attribute's public properties, while keeping explicit McpServerToolCreateOptions values as overrides.

How Has This Been Tested?

  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --filter FullyQualifiedName~McpServerBuilderExtensionsToolsTests.Create_ExtractsToolAnnotations_SomeSet
  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --filter FullyQualifiedName~McpClientTests.ListToolsAsync_AllToolsReturned
  • dotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj -f net10.0 --no-restore

The full net10.0 test project passed locally: 2219 passed, 5 skipped.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

No documentation update is included because this change aligns runtime behavior with the existing documented defaults. No new error handling is needed for this annotation derivation change.

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.

Tool annotation default values are not applied

1 participant