Wrap each request in a service scope (#276)
* Wrap each request in a service scope * Change request/notification delegates to return ValueTask * Address feedback
This commit is contained in:
parent
f1cc2d81de
commit
f4c87f5e2f
1 changed files with 477 additions and 306 deletions
|
|
@ -120,7 +120,7 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
|||
{
|
||||
ExcludeFromSchema = true,
|
||||
BindParameter = (pi, args) =>
|
||||
GetRequestContext(args)?.Server?.Services?.GetService(pi.ParameterType) ??
|
||||
GetRequestContext(args)?.Services?.GetService(pi.ParameterType) ??
|
||||
(pi.HasDefaultValue ? null :
|
||||
throw new ArgumentException("No service of the requested type was found.")),
|
||||
};
|
||||
|
|
@ -132,7 +132,7 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
|||
{
|
||||
ExcludeFromSchema = true,
|
||||
BindParameter = (pi, args) =>
|
||||
(GetRequestContext(args)?.Server?.Services as IKeyedServiceProvider)?.GetKeyedService(pi.ParameterType, keyedAttr.Key) ??
|
||||
(GetRequestContext(args)?.Services as IKeyedServiceProvider)?.GetKeyedService(pi.ParameterType, keyedAttr.Key) ??
|
||||
(pi.HasDefaultValue ? null :
|
||||
throw new ArgumentException("No service of the requested type was found.")),
|
||||
};
|
||||
|
|
@ -237,7 +237,7 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
|||
public override Tool ProtocolTool { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<CallToolResponse> InvokeAsync(
|
||||
public override async ValueTask<CallToolResponse> InvokeAsync(
|
||||
RequestContext<CallToolRequestParams> request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Throw.IfNull(request);
|
||||
|
|
@ -245,7 +245,7 @@ internal sealed class AIFunctionMcpServerTool : McpServerTool
|
|||
|
||||
AIFunctionArguments arguments = new()
|
||||
{
|
||||
Services = request.Server?.Services,
|
||||
Services = request.Services,
|
||||
Context = new Dictionary<object, object?>() { [typeof(RequestContext<CallToolRequestParams>)] = request }
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue