Skip to content

Commit 6eabcbb

Browse files
committed
Refactor interceptor event handling to use new InterceptionEvents class
- Replaced all instances of InterceptorEvents with InterceptionEvents across the codebase. - Updated method calls and event checks in the InterceptingMcpClient, GatewayProxyConfigurator, and other related classes to reflect the new event naming. - Removed the old InterceptorEvents class to streamline the event handling process. - Adjusted tests to ensure compatibility with the new event structure.
1 parent 823ac31 commit 6eabcbb

20 files changed

Lines changed: 143 additions & 139 deletions

File tree

csharp/sdk/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ await app.RunAsync();
3232
public class MyInterceptors
3333
{
3434
[McpServerInterceptor(Name = "pii-validator", Type = InterceptorType.Validation,
35-
Events = [InterceptorEvents.ToolsCall], Phase = InterceptorPhase.Request)]
35+
Events = [InterceptionEvents.ToolsCall], Phase = InterceptorPhase.Request)]
3636
public static ValidationInterceptorResult ValidatePii(JsonNode payload)
3737
{
3838
// Check for PII patterns
3939
return ValidationInterceptorResult.Success();
4040
}
4141

4242
[McpServerInterceptor(Name = "email-redactor", Type = InterceptorType.Mutation,
43-
Events = [InterceptorEvents.ToolsCall], PriorityHint = -1000)]
43+
Events = [InterceptionEvents.ToolsCall], PriorityHint = -1000)]
4444
public static MutationInterceptorResult RedactEmails(JsonNode payload)
4545
{
4646
// Modify the payload
@@ -62,7 +62,7 @@ var interceptors = await interceptorClient.ListInterceptorsAsync();
6262
var result = await interceptorClient.InvokeInterceptorAsync(new InvokeInterceptorRequestParams
6363
{
6464
Name = "pii-validator",
65-
Event = InterceptorEvents.ToolsCall,
65+
Event = InterceptionEvents.ToolsCall,
6666
Phase = InterceptorPhase.Request,
6767
Payload = JsonNode.Parse("""{"name":"call-tool","arguments":{"query":"test"}}""")!,
6868
});
@@ -71,7 +71,7 @@ var result = await interceptorClient.InvokeInterceptorAsync(new InvokeIntercepto
7171
// then dispatches each applicable interceptor via `interceptor/invoke`)
7272
var chainResult = await interceptorClient.ExecuteChainAsync(new ExecuteChainRequestParams
7373
{
74-
Event = InterceptorEvents.ToolsCall,
74+
Event = InterceptionEvents.ToolsCall,
7575
Phase = InterceptorPhase.Request,
7676
Payload = myPayload,
7777
});
@@ -90,7 +90,7 @@ var mcpClient = await McpClient.CreateAsync(mcpTransport);
9090
var gateway = new InterceptingMcpClient(mcpClient, new InterceptingMcpClientOptions
9191
{
9292
InterceptorClient = interceptorClient,
93-
Events = [InterceptorEvents.ToolsCall],
93+
Events = [InterceptionEvents.ToolsCall],
9494
});
9595

9696
// All tool calls now flow through interceptors automatically
@@ -118,7 +118,7 @@ await using var gateway = new McpInterceptorGateway(new McpInterceptorGatewayOpt
118118
{
119119
BackendClient = backend,
120120
InterceptorClients = [interceptors],
121-
Events = [InterceptorEvents.ToolsCall], // null = intercept all events
121+
Events = [InterceptionEvents.ToolsCall], // null = intercept all events
122122
ExposeInterceptorProtocol = false,
123123
});
124124

@@ -165,7 +165,7 @@ await using var gateway = new McpInterceptorGateway(new McpInterceptorGatewayOpt
165165
InterceptorClients = [staticSecurityLayer], // optional: resolver-only mode is also supported
166166
InterceptorServerConnectionResolver = (context, @event, ct) =>
167167
{
168-
if (@event == InterceptorEvents.ToolsCall && context.User?.Identity?.Name == "alice")
168+
if (@event == InterceptionEvents.ToolsCall && context.User?.Identity?.Name == "alice")
169169
{
170170
return ValueTask.FromResult<IReadOnlyList<McpInterceptorServerConnectionOptions>>(
171171
[

csharp/sdk/samples/AvatarMoodInterceptorSample/AvatarInterceptors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public AvatarInterceptors(IChatClient haiku, string haikuModelId, AvatarState st
2929
Name = "avatar-mood",
3030
Description = "Classifies conversation mood via a secondary model and updates the avatar state.",
3131
Type = InterceptorType.Sink,
32-
Events = [InterceptorEvents.LlmCompletion],
32+
Events = [InterceptionEvents.LlmCompletion],
3333
Phase = InterceptorPhase.Response)]
3434
public SinkInterceptorResult OnLlmCompletion(
3535
JsonNode payload,

csharp/sdk/samples/AvatarMoodInterceptorSample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
var payload = BuildCompletionPayload(SonnetModelId, input, replyText, response);
111111
_ = interceptors.OnLlmCompletion(
112112
payload,
113-
InterceptorEvents.LlmCompletion,
113+
InterceptionEvents.LlmCompletion,
114114
InterceptorPhase.Response,
115115
new InvokeInterceptorContext { TraceId = Guid.NewGuid().ToString("N") },
116116
cancellationToken: default);

csharp/sdk/samples/ConfigDrivenGatewaySample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
ServerInfo = config.ServerInfo,
4545
InterceptorServerConnectionResolver = (context, @event, ct) =>
4646
{
47-
if (@event != InterceptorEvents.ToolsCall)
47+
if (@event != InterceptionEvents.ToolsCall)
4848
{
4949
return ValueTask.FromResult<IReadOnlyList<McpInterceptorServerConnectionOptions>>([]);
5050
}

csharp/sdk/samples/GatewayChainSample/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
var loggingGateway = new InterceptingMcpClient(everythingClient, new InterceptingMcpClientOptions
6464
{
6565
InterceptorClient = loggingInterceptorClient,
66-
Events = [InterceptorEvents.ToolsCall, InterceptorEvents.ToolsList],
66+
Events = [InterceptionEvents.ToolsCall, InterceptionEvents.ToolsList],
6767
});
6868

6969
// Outer layer: security interceptors → logging gateway
@@ -104,7 +104,7 @@
104104
// Security layer (request phase)
105105
var securityResult = await securityInterceptorClient.ExecuteChainAsync(new ExecuteChainRequestParams
106106
{
107-
Event = InterceptorEvents.ToolsCall,
107+
Event = InterceptionEvents.ToolsCall,
108108
Phase = InterceptorPhase.Request,
109109
Payload = payload,
110110
});
@@ -127,7 +127,7 @@
127127
// Security layer redacts the email
128128
var securityResult = await securityInterceptorClient.ExecuteChainAsync(new ExecuteChainRequestParams
129129
{
130-
Event = InterceptorEvents.ToolsCall,
130+
Event = InterceptionEvents.ToolsCall,
131131
Phase = InterceptorPhase.Request,
132132
Payload = payload,
133133
});
@@ -154,7 +154,7 @@
154154

155155
var securityResult = await securityInterceptorClient.ExecuteChainAsync(new ExecuteChainRequestParams
156156
{
157-
Event = InterceptorEvents.ToolsCall,
157+
Event = InterceptionEvents.ToolsCall,
158158
Phase = InterceptorPhase.Request,
159159
Payload = payload,
160160
});

csharp/sdk/samples/GatewaySample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
var gateway = new InterceptingMcpClient(everythingClient, new InterceptingMcpClientOptions
4444
{
4545
InterceptorClient = interceptorClient,
46-
Events = [InterceptorEvents.ToolsCall],
46+
Events = [InterceptionEvents.ToolsCall],
4747
});
4848

4949
// 4. List available interceptors

csharp/sdk/samples/InterceptorClientSample/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
var invokeResult = await client.InvokeInterceptorAsync(new InvokeInterceptorRequestParams
5454
{
5555
Name = "email-redactor",
56-
Event = InterceptorEvents.ToolsCall,
56+
Event = InterceptionEvents.ToolsCall,
5757
Phase = InterceptorPhase.Request,
5858
Payload = cleanPayload,
5959
});
@@ -72,7 +72,7 @@
7272
var validationResult = await client.InvokeInterceptorAsync(new InvokeInterceptorRequestParams
7373
{
7474
Name = "pii-validator",
75-
Event = InterceptorEvents.ToolsCall,
75+
Event = InterceptionEvents.ToolsCall,
7676
Phase = InterceptorPhase.Request,
7777
Payload = safePayload,
7878
});
@@ -90,7 +90,7 @@
9090
var piiResult = await client.InvokeInterceptorAsync(new InvokeInterceptorRequestParams
9191
{
9292
Name = "pii-validator",
93-
Event = InterceptorEvents.ToolsCall,
93+
Event = InterceptionEvents.ToolsCall,
9494
Phase = InterceptorPhase.Request,
9595
Payload = piiPayload,
9696
});
@@ -112,7 +112,7 @@
112112
var chainPayload = JsonNode.Parse("""{"name":"echo","arguments":{"message":"Email bob@corp.com about SSN"}}""")!;
113113
var chainResult = await client.ExecuteChainAsync(new ExecuteChainRequestParams
114114
{
115-
Event = InterceptorEvents.ToolsCall,
115+
Event = InterceptionEvents.ToolsCall,
116116
Phase = InterceptorPhase.Request,
117117
Payload = chainPayload,
118118
Context = new InvokeInterceptorContext
@@ -149,7 +149,7 @@
149149
var cleanChainPayload = JsonNode.Parse("""{"name":"echo","arguments":{"message":"Contact bob@corp.com please"}}""")!;
150150
var cleanChainResult = await client.ExecuteChainAsync(new ExecuteChainRequestParams
151151
{
152-
Event = InterceptorEvents.ToolsCall,
152+
Event = InterceptionEvents.ToolsCall,
153153
Phase = InterceptorPhase.Request,
154154
Payload = cleanChainPayload,
155155
});

csharp/sdk/samples/InterceptorServerSample/SampleInterceptors.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SampleInterceptors
1515
Name = "pii-validator",
1616
Description = "Checks tool call arguments for PII patterns",
1717
Type = InterceptorType.Validation,
18-
Events = [InterceptorEvents.ToolsCall],
18+
Events = [InterceptionEvents.ToolsCall],
1919
Phase = InterceptorPhase.Request)]
2020
public static ValidationInterceptorResult ValidatePii(JsonNode payload)
2121
{
@@ -44,7 +44,7 @@ public static ValidationInterceptorResult ValidatePii(JsonNode payload)
4444
Name = "email-redactor",
4545
Description = "Redacts email addresses from payloads",
4646
Type = InterceptorType.Mutation,
47-
Events = [InterceptorEvents.ToolsCall],
47+
Events = [InterceptionEvents.ToolsCall],
4848
Phase = InterceptorPhase.Request,
4949
PriorityHint = -1000)]
5050
public static MutationInterceptorResult RedactEmails(JsonNode payload)
@@ -74,7 +74,7 @@ public static MutationInterceptorResult RedactEmails(JsonNode payload)
7474
Name = "request-logger",
7575
Description = "Logs all requests",
7676
Type = InterceptorType.Sink,
77-
Events = [InterceptorEvents.All])]
77+
Events = [InterceptionEvents.All])]
7878
public static SinkInterceptorResult LogRequest(
7979
JsonNode payload,
8080
string @event,

csharp/sdk/samples/TransparentProxySample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
{
5252
BackendClient = backendClient,
5353
InterceptorClients = [interceptorClient],
54-
Events = [InterceptorEvents.ToolsCall], // Only intercept tools/call
54+
Events = [InterceptionEvents.ToolsCall], // Only intercept tools/call
5555
});
5656

5757
// 4. Configure server options and create the proxy server on stdio

0 commit comments

Comments
 (0)