Skip to content

Commit 5b3a188

Browse files
removed rendundant code in server
1 parent ba73412 commit 5b3a188

2 files changed

Lines changed: 4 additions & 52 deletions

File tree

src/ModelContextProtocol/ClientTokenProgress.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33

44
namespace ModelContextProtocol;
55

6-
internal sealed class ClientTokenProgress(IMcpClient client, ProgressToken? progressToken)
6+
internal sealed class ClientTokenProgress(IMcpClient client, ProgressToken progressToken)
77
: IProgress<ProgressNotificationValue>
88
{
99
/// <inheritdoc />
1010
public void Report(ProgressNotificationValue value)
1111
{
12-
if (progressToken is null) return;
1312
_ = client.SendMessageAsync(new JsonRpcNotification()
1413
{
1514
Method = NotificationMethods.ProgressNotification,
1615
Params = new ProgressNotification()
1716
{
18-
ProgressToken = progressToken.Value,
17+
ProgressToken = progressToken,
1918
Progress = new()
2019
{
2120
Progress = value.Progress,

src/ModelContextProtocol/Server/McpServer.cs

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -303,68 +303,21 @@ private void SetToolsHandler(McpServerOptions options)
303303
var originalCallToolHandler = callToolHandler;
304304
var hasOriginalTools = originalListToolsHandler is not null;
305305

306-
// Synthesize the handlers, making sure a ToolsCapability is specified.
307-
var originalListToolsHandler = listToolsHandler;
308306
listToolsHandler = async (request, cancellationToken) =>
309307
{
310-
var progressToken = request.Params?.Meta?.ProgressToken;
311308
int? totalProgress = hasOriginalTools ? null : tools.Count;
312309
ListToolsResult result = originalListToolsHandler is not null
313310
? await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
314-
: [];
315-
var resultTools = result.Tools;
316-
317-
async Task TryNotifyProgressAsync(int previousCount)
318-
{
319-
var currentCount = resultTools.Count;
320-
if (progressToken is not null
321-
&& currentCount > 0
322-
&& currentCount != previousCount)
323-
{
324-
await this.NotifyProgressAsync(new()
325-
{
326-
ProgressToken = progressToken.Value,
327-
Progress = new()
328-
{
329-
Progress = currentCount,
330-
},
331-
}, cancellationToken).ConfigureAwait(false);
332-
}
333-
}
311+
: new();
334312

335313
if (request.Params?.Cursor is null)
336314
{
337-
resultTools.AddRange(tools.Select(t => t.ProtocolTool));
338-
}
339-
340-
if (originalListToolsHandler is not null)
341-
{
342-
string? nextCursor = null;
343-
var initialCount = resultTools.Count;
344-
int lastReportedCount = 0;
345-
do
346-
{
347-
if (progressToken is not null && resultTools.Count > lastReportedCount)
348-
{
349-
await TryNotifyProgressAsync(lastReportedCount).ConfigureAwait(false);
350-
lastReportedCount = resultTools.Count;
351-
}
352-
var extraResults = await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false);
353-
resultTools.AddRange(extraResults.Tools);
354-
355-
nextCursor = extraResults.NextCursor;
356-
if (nextCursor is not null)
357-
{
358-
request = request with { Params = new() { Cursor = nextCursor } };
359-
}
360-
}
361-
while (nextCursor is not null);
315+
result.Tools.AddRange(tools.Select(t => t.ProtocolTool));
362316
}
363317

364318
return result;
365319
};
366320

367-
var originalCallToolHandler = callToolHandler;
368321
callToolHandler = (request, cancellationToken) =>
369322
{
370323
if (request.Params is null ||

0 commit comments

Comments
 (0)