Method Shutdown
Shutdown(CancellationToken)
Synchronously shuts down the MCP client, clearing all cached state and preparing for potential reuse.
public void Shutdown(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA cancellation token to cancel the shutdown operation.
Remarks
This method blocks the calling thread. In asynchronous code paths, prefer using ShutdownAsync(CancellationToken) to avoid blocking.
Shutdown performs the following cleanup operations:
- Cancels all pending HTTP requests
- Closes the SSE connection (if active)
- Clears cached tools, resources, prompts, and session state
- Recreates the internal HTTP client (if owned) with fresh connection pools
After shutdown, the client can be reused by calling any operation method, which will trigger automatic re-initialization. This is useful when you need to:
- Reset the connection after a prolonged period of inactivity
- Force a fresh handshake with the server
- Clear all cached data and start over
It's safe to call this method multiple times. If you're done with the client permanently, use Dispose() instead.
Exceptions
- OperationCanceledException
Thrown if the operation is canceled via
cancellationToken.
- See Also