-
Notifications
You must be signed in to change notification settings - Fork 674
Expand file tree
/
Copy pathDelegatingMcpServerTool.cs
More file actions
40 lines (32 loc) · 1.66 KB
/
DelegatingMcpServerTool.cs
File metadata and controls
40 lines (32 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using ModelContextProtocol.Protocol;
namespace ModelContextProtocol.Server;
/// <summary>Provides an <see cref="McpServerTool"/> that delegates all operations to an inner <see cref="McpServerTool"/>.</summary>
/// <remarks>
/// This is recommended as a base type when building tools that can be chained around an underlying <see cref="McpServerTool"/>.
/// The default implementation simply passes each call to the inner tool instance.
/// </remarks>
public abstract class DelegatingMcpServerTool : McpServerTool
{
private readonly McpServerTool _innerTool;
/// <summary>Initializes a new instance of the <see cref="DelegatingMcpServerTool"/> class around the specified <paramref name="innerTool"/>.</summary>
/// <param name="innerTool">The inner tool wrapped by this delegating tool.</param>
/// <exception cref="ArgumentNullException"><paramref name="innerTool"/> is <see langword="null"/>.</exception>
protected DelegatingMcpServerTool(McpServerTool innerTool)
{
Throw.IfNull(innerTool);
_innerTool = innerTool;
}
/// <inheritdoc />
public override Tool ProtocolTool => _innerTool.ProtocolTool;
/// <inheritdoc />
internal override bool ReturnsMcpTask => _innerTool.ReturnsMcpTask;
/// <inheritdoc />
public override IReadOnlyList<object> Metadata => _innerTool.Metadata;
/// <inheritdoc />
public override ValueTask<CallToolResult> InvokeAsync(
RequestContext<CallToolRequestParams> request,
CancellationToken cancellationToken = default) =>
_innerTool.InvokeAsync(request, cancellationToken);
/// <inheritdoc />
public override string ToString() => _innerTool.ToString();
}