Skip to content

Commit b743889

Browse files
authored
Update System and M.E.AI dependencies (#374)
1 parent e913d80 commit b743889

File tree

4 files changed

+5
-61
lines changed

4 files changed

+5
-61
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<System10Version>10.0.0-preview.2.25163.2</System10Version>
5-
<MicrosoftExtensionsAIVersion>9.4.0-preview.1.25207.5</MicrosoftExtensionsAIVersion>
4+
<System10Version>10.0.0-preview.3.25171.5</System10Version>
5+
<MicrosoftExtensionsAIVersion>9.4.3-preview.1.25230.7</MicrosoftExtensionsAIVersion>
66
</PropertyGroup>
77

88
<!-- Product dependencies netstandard -->

src/ModelContextProtocol/Server/AIFunctionMcpServerPrompt.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
6868
Description = options?.Description,
6969
MarshalResult = static (result, _, cancellationToken) => new ValueTask<object?>(result),
7070
SerializerOptions = options?.SerializerOptions ?? McpJsonUtilities.DefaultOptions,
71+
Services = options?.Services,
7172
ConfigureParameterBinding = pi =>
7273
{
7374
if (pi.ParameterType == typeof(RequestContext<GetPromptRequestParams>))
@@ -88,35 +89,6 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
8889
};
8990
}
9091

91-
// We assume that if the services used to create the prompt support a particular type,
92-
// so too do the services associated with the server. This is the same basic assumption
93-
// made in ASP.NET.
94-
if (options?.Services is { } services &&
95-
services.GetService<IServiceProviderIsService>() is { } ispis &&
96-
ispis.IsService(pi.ParameterType))
97-
{
98-
return new()
99-
{
100-
ExcludeFromSchema = true,
101-
BindParameter = (pi, args) =>
102-
GetRequestContext(args)?.Services?.GetService(pi.ParameterType) ??
103-
(pi.HasDefaultValue ? null :
104-
throw new InvalidOperationException("No service of the requested type was found.")),
105-
};
106-
}
107-
108-
if (pi.GetCustomAttribute<FromKeyedServicesAttribute>() is { } keyedAttr)
109-
{
110-
return new()
111-
{
112-
ExcludeFromSchema = true,
113-
BindParameter = (pi, args) =>
114-
(GetRequestContext(args)?.Services as IKeyedServiceProvider)?.GetKeyedService(pi.ParameterType, keyedAttr.Key) ??
115-
(pi.HasDefaultValue ? null :
116-
throw new InvalidOperationException("No service of the requested type was found.")),
117-
};
118-
}
119-
12092
return default;
12193

12294
static RequestContext<GetPromptRequestParams>? GetRequestContext(AIFunctionArguments args)

src/ModelContextProtocol/Server/AIFunctionMcpServerTool.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
6868
Description = options?.Description,
6969
MarshalResult = static (result, _, cancellationToken) => new ValueTask<object?>(result),
7070
SerializerOptions = options?.SerializerOptions ?? McpJsonUtilities.DefaultOptions,
71+
Services = options?.Services,
7172
ConfigureParameterBinding = pi =>
7273
{
7374
if (pi.ParameterType == typeof(RequestContext<CallToolRequestParams>))
@@ -109,35 +110,6 @@ private static AIFunctionFactoryOptions CreateAIFunctionFactoryOptions(
109110
};
110111
}
111112

112-
// We assume that if the services used to create the tool support a particular type,
113-
// so too do the services associated with the server. This is the same basic assumption
114-
// made in ASP.NET.
115-
if (options?.Services is { } services &&
116-
services.GetService<IServiceProviderIsService>() is { } ispis &&
117-
ispis.IsService(pi.ParameterType))
118-
{
119-
return new()
120-
{
121-
ExcludeFromSchema = true,
122-
BindParameter = (pi, args) =>
123-
GetRequestContext(args)?.Services?.GetService(pi.ParameterType) ??
124-
(pi.HasDefaultValue ? null :
125-
throw new InvalidOperationException("No service of the requested type was found.")),
126-
};
127-
}
128-
129-
if (pi.GetCustomAttribute<FromKeyedServicesAttribute>() is { } keyedAttr)
130-
{
131-
return new()
132-
{
133-
ExcludeFromSchema = true,
134-
BindParameter = (pi, args) =>
135-
(GetRequestContext(args)?.Services as IKeyedServiceProvider)?.GetKeyedService(pi.ParameterType, keyedAttr.Key) ??
136-
(pi.HasDefaultValue ? null :
137-
throw new InvalidOperationException("No service of the requested type was found.")),
138-
};
139-
}
140-
141113
return default;
142114

143115
static RequestContext<CallToolRequestParams>? GetRequestContext(AIFunctionArguments args)

tests/ModelContextProtocol.Tests/Server/McpServerPromptTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task SupportsServiceFromDI()
6161
Assert.Contains("something", prompt.ProtocolPrompt.Arguments?.Select(a => a.Name) ?? []);
6262
Assert.DoesNotContain("actualMyService", prompt.ProtocolPrompt.Arguments?.Select(a => a.Name) ?? []);
6363

64-
await Assert.ThrowsAsync<InvalidOperationException>(async () => await prompt.GetAsync(
64+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await prompt.GetAsync(
6565
new RequestContext<GetPromptRequestParams>(new Mock<IMcpServer>().Object),
6666
TestContext.Current.CancellationToken));
6767

0 commit comments

Comments
 (0)