Skip to content

Commit a755a54

Browse files
halter73Copilot
andcommitted
Split MrtrContext.cs into one class per file
Move MrtrExchange and MrtrContinuation into their own files to follow the convention of one top-level class per file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5db2419 commit a755a54

3 files changed

Lines changed: 64 additions & 59 deletions

File tree

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Text.Json.Nodes;
21
using ModelContextProtocol.Protocol;
32

43
namespace ModelContextProtocol.Server;
@@ -55,61 +54,3 @@ public void ResetForNextExchange()
5554
_exchangeTcs = new TaskCompletionSource<MrtrExchange>(TaskCreationOptions.RunContinuationsAsynchronously);
5655
}
5756
}
58-
59-
/// <summary>
60-
/// Represents a single exchange between the handler and the pipeline during an MRTR flow.
61-
/// The handler creates the exchange and awaits the response TCS. The pipeline reads the exchange,
62-
/// sends the <see cref="InputRequest"/> to the client, and completes the TCS when the response arrives.
63-
/// </summary>
64-
internal sealed class MrtrExchange
65-
{
66-
public MrtrExchange(string key, InputRequest inputRequest)
67-
{
68-
Key = key;
69-
InputRequest = inputRequest;
70-
ResponseTcs = new TaskCompletionSource<InputResponse>(TaskCreationOptions.RunContinuationsAsynchronously);
71-
}
72-
73-
/// <summary>
74-
/// The unique key identifying this exchange within the MRTR round trip.
75-
/// </summary>
76-
public string Key { get; }
77-
78-
/// <summary>
79-
/// The input request that needs to be fulfilled by the client.
80-
/// </summary>
81-
public InputRequest InputRequest { get; }
82-
83-
/// <summary>
84-
/// The TCS that will be completed with the client's response.
85-
/// </summary>
86-
public TaskCompletionSource<InputResponse> ResponseTcs { get; }
87-
}
88-
89-
/// <summary>
90-
/// Represents a continuation for a suspended MRTR handler, stored between round trips.
91-
/// </summary>
92-
internal sealed class MrtrContinuation
93-
{
94-
public MrtrContinuation(Task<JsonNode?> handlerTask, MrtrContext mrtrContext, MrtrExchange pendingExchange)
95-
{
96-
HandlerTask = handlerTask;
97-
MrtrContext = mrtrContext;
98-
PendingExchange = pendingExchange;
99-
}
100-
101-
/// <summary>
102-
/// The handler task that is suspended awaiting input.
103-
/// </summary>
104-
public Task<JsonNode?> HandlerTask { get; }
105-
106-
/// <summary>
107-
/// The MRTR context for the handler's async flow.
108-
/// </summary>
109-
public MrtrContext MrtrContext { get; }
110-
111-
/// <summary>
112-
/// The exchange that is awaiting a response from the client.
113-
/// </summary>
114-
public MrtrExchange PendingExchange { get; }
115-
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Text.Json.Nodes;
2+
3+
namespace ModelContextProtocol.Server;
4+
5+
/// <summary>
6+
/// Represents a continuation for a suspended MRTR handler, stored between round trips.
7+
/// </summary>
8+
internal sealed class MrtrContinuation
9+
{
10+
public MrtrContinuation(Task<JsonNode?> handlerTask, MrtrContext mrtrContext, MrtrExchange pendingExchange)
11+
{
12+
HandlerTask = handlerTask;
13+
MrtrContext = mrtrContext;
14+
PendingExchange = pendingExchange;
15+
}
16+
17+
/// <summary>
18+
/// The handler task that is suspended awaiting input.
19+
/// </summary>
20+
public Task<JsonNode?> HandlerTask { get; }
21+
22+
/// <summary>
23+
/// The MRTR context for the handler's async flow.
24+
/// </summary>
25+
public MrtrContext MrtrContext { get; }
26+
27+
/// <summary>
28+
/// The exchange that is awaiting a response from the client.
29+
/// </summary>
30+
public MrtrExchange PendingExchange { get; }
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ModelContextProtocol.Protocol;
2+
3+
namespace ModelContextProtocol.Server;
4+
5+
/// <summary>
6+
/// Represents a single exchange between the handler and the pipeline during an MRTR flow.
7+
/// The handler creates the exchange and awaits the response TCS. The pipeline reads the exchange,
8+
/// sends the <see cref="InputRequest"/> to the client, and completes the TCS when the response arrives.
9+
/// </summary>
10+
internal sealed class MrtrExchange
11+
{
12+
public MrtrExchange(string key, InputRequest inputRequest)
13+
{
14+
Key = key;
15+
InputRequest = inputRequest;
16+
ResponseTcs = new TaskCompletionSource<InputResponse>(TaskCreationOptions.RunContinuationsAsynchronously);
17+
}
18+
19+
/// <summary>
20+
/// The unique key identifying this exchange within the MRTR round trip.
21+
/// </summary>
22+
public string Key { get; }
23+
24+
/// <summary>
25+
/// The input request that needs to be fulfilled by the client.
26+
/// </summary>
27+
public InputRequest InputRequest { get; }
28+
29+
/// <summary>
30+
/// The TCS that will be completed with the client's response.
31+
/// </summary>
32+
public TaskCompletionSource<InputResponse> ResponseTcs { get; }
33+
}

0 commit comments

Comments
 (0)