Skip to content

feat(server): support external description sources on McpServerTool attribute#1532

Open
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
MukundaKatta:feat/external-tool-description
Open

feat(server): support external description sources on McpServerTool attribute#1532
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
MukundaKatta:feat/external-tool-description

Conversation

@MukundaKatta
Copy link
Copy Markdown

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, mirroring System.ComponentModel.DataAnnotations.DisplayAttribute:

  • DescriptionResourceType (Type)
  • DescriptionResourceName (string)

When both are set, AIFunctionMcpServerTool.DeriveOptions resolves the description by reflecting against the resource type, in this order:

  1. public static property named <Name> returning string
  2. public static field named <Name> of type string
  3. public static parameterless method named <Name> returning string
  4. public static ResourceManager property named ResourceManager (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.

[McpServerTool(
    DescriptionResourceType = typeof(ToolDescriptions),
    DescriptionResourceName = nameof(ToolDescriptions.WeatherSummary))]
public string GetWeather(string city) => ...;

ToolDescriptions.WeatherSummary can be a static property backed by config, a .resx accessor, or any string source the host owns.

Tested

Added tests/ModelContextProtocol.Tests/Server/McpServerToolExternalDescriptionTests.cs with 7 cases covering:

  • static property / field / method / ResourceManager resolution
  • precedence over [Description]
  • fallback to [Description] when the resource is missing
  • no-op when only DescriptionResourceName is set without a type

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

MCP Tool description from external source

1 participant