Skip to content

Commit 0d3b47f

Browse files
Copilotstephentoub
andcommitted
Simplify MethodInfo resolution to use function.UnderlyingMethod directly
Co-authored-by: stephentoub <[email protected]>
1 parent 11dfada commit 0d3b47f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerPrompt.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
140140
};
141141

142142
// Populate Meta from options and/or McpMetaAttribute instances if a MethodInfo is available
143-
MethodInfo? method = options?.Metadata?.FirstOrDefault(m => m is MethodInfo) as MethodInfo ?? function.UnderlyingMethod;
144-
if (method is not null)
143+
if (function.UnderlyingMethod is not null)
145144
{
146-
prompt.Meta = AIFunctionMcpServerTool.CreateMetaFromAttributes(method, options?.Meta, options?.SerializerOptions);
145+
prompt.Meta = AIFunctionMcpServerTool.CreateMetaFromAttributes(function.UnderlyingMethod, options?.Meta, options?.SerializerOptions);
147146
}
148147
else if (options?.Meta is not null)
149148
{

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
213213
string name = options?.Name ?? function.Name;
214214

215215
// Populate Meta from options and/or McpMetaAttribute instances if a MethodInfo is available
216-
MethodInfo? method = options?.Metadata?.FirstOrDefault(m => m is MethodInfo) as MethodInfo ?? function.UnderlyingMethod;
217216
JsonObject? meta = null;
218-
if (method is not null)
217+
if (function.UnderlyingMethod is not null)
219218
{
220-
meta = AIFunctionMcpServerTool.CreateMetaFromAttributes(method, options?.Meta, options?.SerializerOptions);
219+
meta = AIFunctionMcpServerTool.CreateMetaFromAttributes(function.UnderlyingMethod, options?.Meta, options?.SerializerOptions);
221220
}
222221
else if (options?.Meta is not null)
223222
{

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ options.OpenWorld is not null ||
145145
}
146146

147147
// Populate Meta from options and/or McpMetaAttribute instances if a MethodInfo is available
148-
MethodInfo? method = options.Metadata?.FirstOrDefault(m => m is MethodInfo) as MethodInfo ?? function.UnderlyingMethod;
149-
if (method is not null)
148+
if (function.UnderlyingMethod is not null)
150149
{
151-
tool.Meta = CreateMetaFromAttributes(method, options.Meta, options.SerializerOptions);
150+
tool.Meta = CreateMetaFromAttributes(function.UnderlyingMethod, options.Meta, options.SerializerOptions);
152151
}
153152
else if (options.Meta is not null)
154153
{

0 commit comments

Comments
 (0)