feat(server): support external description sources on McpServerTool attribute#1532
Open
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…ttribute Adds opt-in DescriptionResourceType + DescriptionResourceName properties on [McpServerTool] (mirroring DisplayAttribute from System.ComponentModel.DataAnnotations) so tool descriptions can be resolved at discovery time from a static property/field/method or a ResourceManager instead of a compiled string literal. When set, the resolved value takes precedence over [Description]; when the lookup fails the existing [Description] fallback still applies. Closes modelcontextprotocol#1516.
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.
Closes #1516.
Why
[McpServerTool(Description = "...")]only accepts a compiled string literal today, so updating tool guidance for an LLM requires rebuilding and redeploying the server. The issue asks for a way to load tool descriptions from an external source (resx, config, accessor) so they can change without a code release.What
Adds two opt-in properties to
McpServerToolAttribute, mirroringSystem.ComponentModel.DataAnnotations.DisplayAttribute:DescriptionResourceType(Type)DescriptionResourceName(string)When both are set,
AIFunctionMcpServerTool.DeriveOptionsresolves the description by reflecting against the resource type, in this order:<Name>returningstring<Name>of typestring<Name>returningstringResourceManagerproperty namedResourceManager(looked up by<Name>)Resolved value wins over
[Description]; if the lookup fails (e.g. missing resource), the existing[Description]fallback still applies. No behavior change when the new properties are unset.ToolDescriptions.WeatherSummarycan be a static property backed by config, a.resxaccessor, or any string source the host owns.Tested
Added
tests/ModelContextProtocol.Tests/Server/McpServerToolExternalDescriptionTests.cswith 7 cases covering:ResourceManagerresolution[Description][Description]when the resource is missingDescriptionResourceNameis set without a type