1
- using System . Text . Json . Nodes ;
2
- using McpDotNet . Logging ;
1
+ using McpDotNet . Logging ;
3
2
using McpDotNet . Protocol . Transport ;
4
3
using McpDotNet . Protocol . Types ;
5
4
using McpDotNet . Shared ;
6
5
using McpDotNet . Utils ;
6
+
7
7
using Microsoft . Extensions . Logging ;
8
8
using Microsoft . Extensions . Logging . Abstractions ;
9
9
10
+ using System . Text . Json . Nodes ;
11
+
10
12
namespace McpDotNet . Server ;
11
13
12
14
/// <inheritdoc />
@@ -107,14 +109,14 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
107
109
108
110
private void SetPingHandler ( )
109
111
{
110
- SetRequestHandler < JsonNode , PingResult > ( "ping" ,
111
- request => Task . FromResult ( new PingResult ( ) ) ) ;
112
+ SetRequestHandler < JsonNode , PingResult > ( "ping" ,
113
+ ( request , _ ) => Task . FromResult ( new PingResult ( ) ) ) ;
112
114
}
113
115
114
116
private void SetInitializeHandler ( McpServerOptions options )
115
117
{
116
118
SetRequestHandler < InitializeRequestParams , InitializeResult > ( "initialize" ,
117
- request =>
119
+ ( request , _ ) =>
118
120
{
119
121
ClientCapabilities = request ? . Capabilities ?? new ( ) ;
120
122
ClientInfo = request ? . ClientInfo ;
@@ -133,8 +135,8 @@ private void SetCompletionHandler(McpServerOptions options)
133
135
// This capability is not optional, so return an empty result if there is no handler.
134
136
SetRequestHandler < CompleteRequestParams , CompleteResult > ( "completion/complete" ,
135
137
options . GetCompletionHandler is { } handler ?
136
- request => handler ( new ( this , request ) , CancellationTokenSource ? . Token ?? default ) :
137
- request => Task . FromResult ( new CompleteResult ( ) { Completion = new ( ) { Values = [ ] , Total = 0 , HasMore = false } } ) ) ;
138
+ ( request , ct ) => handler ( new ( this , request ) , ct ) :
139
+ ( request , ct ) => Task . FromResult ( new CompleteResult ( ) { Completion = new ( ) { Values = [ ] , Total = 0 , HasMore = false } } ) ) ;
138
140
}
139
141
140
142
private void SetResourcesHandler ( McpServerOptions options )
@@ -150,9 +152,8 @@ private void SetResourcesHandler(McpServerOptions options)
150
152
throw new McpServerException ( "Resources capability was enabled, but ListResources and/or ReadResource handlers were not specified." ) ;
151
153
}
152
154
153
- CancellationToken cancellationToken = CancellationTokenSource ? . Token ?? default ;
154
- SetRequestHandler < ListResourcesRequestParams , ListResourcesResult > ( "resources/list" , request => listResourcesHandler ( new ( this , request ) , cancellationToken ) ) ;
155
- SetRequestHandler < ReadResourceRequestParams , ReadResourceResult > ( "resources/read" , request => readResourceHandler ( new ( this , request ) , cancellationToken ) ) ;
155
+ SetRequestHandler < ListResourcesRequestParams , ListResourcesResult > ( "resources/list" , ( request , ct ) => listResourcesHandler ( new ( this , request ) , ct ) ) ;
156
+ SetRequestHandler < ReadResourceRequestParams , ReadResourceResult > ( "resources/read" , ( request , ct ) => readResourceHandler ( new ( this , request ) , ct ) ) ;
156
157
157
158
if ( resourcesCapability . Subscribe is not true )
158
159
{
@@ -166,8 +167,8 @@ private void SetResourcesHandler(McpServerOptions options)
166
167
throw new McpServerException ( "Resources capability was enabled with subscribe support, but SubscribeToResources and/or UnsubscribeFromResources handlers were not specified." ) ;
167
168
}
168
169
169
- SetRequestHandler < SubscribeRequestParams , EmptyResult > ( "resources/subscribe" , request => subscribeHandler ( new ( this , request ) , cancellationToken ) ) ;
170
- SetRequestHandler < UnsubscribeRequestParams , EmptyResult > ( "resources/unsubscribe" , request => unsubscribeHandler ( new ( this , request ) , cancellationToken ) ) ;
170
+ SetRequestHandler < SubscribeRequestParams , EmptyResult > ( "resources/subscribe" , ( request , ct ) => subscribeHandler ( new ( this , request ) , ct ) ) ;
171
+ SetRequestHandler < UnsubscribeRequestParams , EmptyResult > ( "resources/unsubscribe" , ( request , ct ) => unsubscribeHandler ( new ( this , request ) , ct ) ) ;
171
172
}
172
173
173
174
private void SetPromptsHandler ( McpServerOptions options )
@@ -183,9 +184,8 @@ private void SetPromptsHandler(McpServerOptions options)
183
184
throw new McpServerException ( "Prompts capability was enabled, but ListPrompts and/or GetPrompt handlers were not specified." ) ;
184
185
}
185
186
186
- CancellationToken cancellationToken = CancellationTokenSource ? . Token ?? default ;
187
- SetRequestHandler < ListPromptsRequestParams , ListPromptsResult > ( "prompts/list" , request => listPromptsHandler ( new ( this , request ) , cancellationToken ) ) ;
188
- SetRequestHandler < GetPromptRequestParams , GetPromptResult > ( "prompts/get" , request => getPromptHandler ( new ( this , request ) , cancellationToken ) ) ;
187
+ SetRequestHandler < ListPromptsRequestParams , ListPromptsResult > ( "prompts/list" , ( request , ct ) => listPromptsHandler ( new ( this , request ) , ct ) ) ;
188
+ SetRequestHandler < GetPromptRequestParams , GetPromptResult > ( "prompts/get" , ( request , ct ) => getPromptHandler ( new ( this , request ) , ct ) ) ;
189
189
}
190
190
191
191
private void SetToolsHandler ( McpServerOptions options )
@@ -201,8 +201,7 @@ private void SetToolsHandler(McpServerOptions options)
201
201
throw new McpServerException ( "ListTools and/or CallTool handlers were specified but the Tools capability was not enabled." ) ;
202
202
}
203
203
204
- CancellationToken cancellationToken = CancellationTokenSource ? . Token ?? default ;
205
- SetRequestHandler < ListToolsRequestParams , ListToolsResult > ( "tools/list" , request => listToolsHandler ( new ( this , request ) , cancellationToken ) ) ;
206
- SetRequestHandler < CallToolRequestParams , CallToolResponse > ( "tools/call" , request => callToolHandler ( new ( this , request ) , cancellationToken ) ) ;
204
+ SetRequestHandler < ListToolsRequestParams , ListToolsResult > ( "tools/list" , ( request , ct ) => listToolsHandler ( new ( this , request ) , ct ) ) ;
205
+ SetRequestHandler < CallToolRequestParams , CallToolResponse > ( "tools/call" , ( request , ct ) => callToolHandler ( new ( this , request ) , ct ) ) ;
207
206
}
208
207
}
0 commit comments