microsoft / microsoft/Agent365-dotnet

McpToolRegistrationService: The CancellationTokenSource has been disposed

Open
#223 0 comments 0 reactions 1 assignee View on GitHub

@gwharris7 is already working on this.

Since Jun 11, 2026.

Dominant language
C#
Stars
29
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Description

I'm running the sample https://github.com/microsoft/Agent365-Samples/tree/main/dotnet/agent-framework/sample-agent and could not get the Mcp tools to work.

I got the error below, seems like the method https://github.com/microsoft/Agent365-dotnet/blob/9d2f7e2c4921b51a18c86f48f64e05b31d8c4713/src/Tooling/Extensions/AgentFramework/Services/McpToolRegistrationService.cs#L114-L119 is missing the cancellationToken

Microsoft.Agents.A365.Tooling.Extensions.AgentFramework.Services.IMcpToolRegistrationService[0]
      Failed to load tools from MCP server 'mcp_MailTools': Failed to get tools from MCP server 'mcp_MailTools' at 'https://agent365.svc.cloud.microsoft/agents/servers/mcp_MailTools': Failed to create MCP client for endpoint 'https://agent365.svc.cloud.microsoft/agents/servers/mcp_MailTools': The CancellationTokenSource has been disposed.
      Object name: 'System.Threading.CancellationTokenSource'.
      System.InvalidOperationException: Failed to get tools from MCP server 'mcp_MailTools' at 'https://agent365.svc.cloud.microsoft/agents/servers/mcp_MailTools': Failed to create MCP client for endpoint 'https://agent365.svc.cloud.microsoft/agents/servers/mcp_MailTools': The CancellationTokenSource has been disposed.
      Object name: 'System.Threading.CancellationTokenSource'.
       ---> System.InvalidOperationException: Failed to create MCP client for endpoint 'https://agent365.svc.cloud.microsoft/agents/servers/mcp_MailTools': The CancellationTokenSource has been disposed.
      Object name: 'System.Threading.CancellationTokenSource'.
       ---> System.ObjectDisposedException: The CancellationTokenSource has been disposed.
      Object name: 'System.Threading.CancellationTokenSource'.
         at ModelContextProtocol.Client.StreamableHttpClientSessionTransport.DisposeAsync()
         at ModelContextProtocol.Client.AutoDetectingClientSessionTransport.InitializeAsync(JsonRpcMessage message, CancellationToken cancellationToken)
         at ModelContextProtocol.McpSession.SendRequestAsync(JsonRpcRequest request, CancellationToken cancellationToken)
         at ModelContextProtocol.McpEndpointExtensions.SendRequestAsync[TParameters,TResult](IMcpEndpoint endpoint, String method, TParameters parameters, JsonTypeInfo`1 parametersTypeInfo, JsonTypeInfo`1 resultTypeInfo, RequestId requestId, CancellationToken cancellationToken)
         at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken)
         at ModelContextProtocol.Client.McpClient.ConnectAsync(CancellationToken cancellationToken)
         at ModelContextProtocol.Client.McpClientFactory.CreateAsync(IClientTransport clientTransport, McpClientOptions clientOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
         at ModelContextProtocol.Client.McpClientFactory.CreateAsync(IClientTransport clientTransport, McpClientOptions clientOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
         at Microsoft.Agents.A365.Tooling.Services.McpToolServerConfigurationService.CreateMcpClientWithAuthHandlers(ITurnContext turnContext, Uri endpoint, String clientName, String authToken) in C:\__w\1\s\Agent365-dotnet\src\Tooling\Core\Services\McpToolServerConfigurationService.cs:line 432
         --- End of inner exception stack trace ---
         at Microsoft.Agents.A365.Tooling.Services.McpToolServerConfigurationService.CreateMcpClientWithAuthHandlers(ITurnContext turnContext, Uri endpoint, String clientName, String authToken) in C:\__w\1\s\Agent365-dotnet\src\Tooling\Core\Services\McpToolServerConfigurationService.cs:line 436
         at Microsoft.Agents.A365.Tooling.Services.McpToolServerConfigurationService.GetMcpClientToolsAsync(ITurnContext turnContext, MCPServerConfig mCPServerConfig, String authToken) in C:\__w\1\s\Agent365-dotnet\src\Tooling\Core\Services\McpToolServerConfigurationService.cs:line 74
         --- End of inner exception stack trace ---
         at Microsoft.Agents.A365.Tooling.Services.McpToolServerConfigurationService.GetMcpClientToolsAsync(ITurnContext turnContext, MCPServerConfig mCPServerConfig, String authToken) in C:\__w\1\s\Agent365-dotnet\src\Tooling\Core\Services\McpToolServerConfigurationService.cs:line 91
         at Microsoft.Agents.A365.Tooling.Extensions.AgentFramework.Services.McpToolRegistrationService.GetMcpToolsAsync(String agentUserId, UserAuthorization userAuthorization, String authHandlerName, ITurnContext turnContext, String authToken) in C:\__w\1\s\Agent365-dotnet\src\Tooling\Extensions\AgentFramework\Services\McpToolRegistrationService.cs:line 142
Expected behavior

The async methods should accept a cancellation token that is passed along the async call chain

SDK Version

0.1.72-beta

.NET Version

.net8.0

OS

Windows 11

How to Reproduce

run the sample

Output

No response

Screenshots

No response

Code of Conduct

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.