// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Collections.Concurrent; namespace McpServer; public static class AskStatus { public const string Pending = "pending"; public const string Answered = "answered"; } public static class ApprovalStatus { public const string Pending = "pending"; public const string Approved = "approved"; public const string Rejected = "rejected"; } // Immutable so readers always see a consistent (Status, Reply) snapshot — no locks, // no Volatile, no torn state. Transitions go through ConcurrentDictionary.TryUpdate // in State.PendingAsks: build a new record, swap atomically against the old one. public sealed record PendingAsk(string UserId, string Status = AskStatus.Pending, string? Reply = null); /// /// In-memory state shared between the Teams bot handlers and the MCP tools. /// A server restart clears everything — pending asks and approvals in flight will be lost. /// public sealed class State { /// User AAD object id -> personal conversationId. Populated on first incoming 1:1 message. public ConcurrentDictionary Conversations { get; } = new(); /// requestId -> PendingAsk. public ConcurrentDictionary PendingAsks { get; } = new(); /// approvalId -> approval status. Values: "pending", "approved", "rejected". public ConcurrentDictionary Approvals { get; } = new(); /// /// requestId -> TCS completed when the user replies (or the ask is superseded). /// Lets wait_for_reply return sub-millisecond after the answer lands instead of polling. /// public ConcurrentDictionary> ReplyWaiters { get; } = new(); /// /// approvalId -> TCS completed with the final status when the user clicks Approve/Reject. /// Lets wait_for_approval return sub-millisecond after the decision lands instead of polling. /// public ConcurrentDictionary> ApprovalWaiters { get; } = new(); /// /// Service URL used by proactive sends and conversations.create. Updated from /// the first incoming activity; falls back to the default Teams endpoint until then. /// public Uri ServiceUrl { get; set; } = new Uri("https://smba.trafficmanager.net/teams/"); }