@@ -7,11 +7,10 @@ use rmcp::model::{
7
7
use rmcp:: service:: { NotificationContext , RequestContext } ;
8
8
use rmcp:: { Error as McpError , Peer , RoleClient , RoleServer , ServerHandler } ;
9
9
use std:: sync:: Arc ;
10
- use tokio:: sync:: Mutex ;
11
10
use tracing:: { debug, error, info} ;
12
11
13
12
pub struct ProxyServer {
14
- client : Arc < Mutex < Peer < RoleClient > > > ,
13
+ client : Arc < Peer < RoleClient > > ,
15
14
server_info : Arc < ServerInfo > ,
16
15
}
17
16
@@ -34,7 +33,7 @@ impl ProxyServer {
34
33
debug ! ( "[Proxy]server info: {:?}" , server_info) ;
35
34
36
35
Self {
37
- client : Arc :: new ( Mutex :: new ( client_peer) ) ,
36
+ client : Arc :: new ( client_peer) ,
38
37
server_info : Arc :: new ( server_info) ,
39
38
}
40
39
}
@@ -60,10 +59,7 @@ impl ServerHandler for ProxyServer {
60
59
request : rmcp:: model:: CompleteRequestParam ,
61
60
_context : RequestContext < RoleServer > ,
62
61
) -> Result < rmcp:: model:: CompleteResult , McpError > {
63
- let client = self . client . clone ( ) ;
64
- let guard = client. lock ( ) . await ;
65
-
66
- match guard. complete ( request) . await {
62
+ match self . client . complete ( request) . await {
67
63
Ok ( result) => {
68
64
debug ! ( "[Proxy] Proxying complete response" ) ;
69
65
Ok ( result)
@@ -91,10 +87,7 @@ impl ServerHandler for ProxyServer {
91
87
) ) ;
92
88
}
93
89
94
- let client = self . client . clone ( ) ;
95
- let guard = client. lock ( ) . await ;
96
-
97
- match guard. get_prompt ( request) . await {
90
+ match self . client . get_prompt ( request) . await {
98
91
Ok ( result) => {
99
92
debug ! ( "[Proxy] Proxying get_prompt response" ) ;
100
93
Ok ( result)
@@ -122,10 +115,7 @@ impl ServerHandler for ProxyServer {
122
115
) ) ;
123
116
}
124
117
125
- let client = self . client . clone ( ) ;
126
- let guard = client. lock ( ) . await ;
127
-
128
- match guard. list_prompts ( request) . await {
118
+ match self . client . list_prompts ( request) . await {
129
119
Ok ( result) => {
130
120
debug ! ( "[Proxy] Proxying list_prompts response" ) ;
131
121
Ok ( result)
@@ -150,9 +140,7 @@ impl ServerHandler for ProxyServer {
150
140
) ) ;
151
141
}
152
142
153
- let client_guard = self . client . lock ( ) . await ;
154
-
155
- match client_guard. list_resources ( request) . await {
143
+ match self . client . list_resources ( request) . await {
156
144
Ok ( list_resources_result) => {
157
145
debug ! (
158
146
"Proxying list_resources response: {:?}" ,
@@ -180,11 +168,7 @@ impl ServerHandler for ProxyServer {
180
168
) ) ;
181
169
}
182
170
183
- let client = self . client . clone ( ) ;
184
- let guard = client. lock ( ) . await ;
185
-
186
- // TODO: Check if the server has resources capability and forward the request
187
- match guard. list_resource_templates ( request) . await {
171
+ match self . client . list_resource_templates ( request) . await {
188
172
Ok ( list_resource_templates_result) => {
189
173
debug ! (
190
174
"Proxying list_resource_templates response: {:?}" ,
@@ -212,11 +196,8 @@ impl ServerHandler for ProxyServer {
212
196
) ) ;
213
197
}
214
198
215
- let client = self . client . clone ( ) ;
216
- let guard = client. lock ( ) . await ;
217
-
218
- // TODO: Check if the server has resources capability and forward the request
219
- match guard
199
+ match self
200
+ . client
220
201
. read_resource ( ReadResourceRequestParam {
221
202
uri : request. uri . clone ( ) ,
222
203
} )
@@ -252,10 +233,7 @@ impl ServerHandler for ProxyServer {
252
233
) ) ;
253
234
}
254
235
255
- let client = self . client . clone ( ) ;
256
- let guard = client. lock ( ) . await ;
257
-
258
- match guard. call_tool ( request. clone ( ) ) . await {
236
+ match self . client . call_tool ( request. clone ( ) ) . await {
259
237
Ok ( result) => {
260
238
debug ! ( "[Proxy] Tool call succeeded: {:?}" , result) ;
261
239
Ok ( result)
@@ -282,10 +260,7 @@ impl ServerHandler for ProxyServer {
282
260
) ) ;
283
261
}
284
262
285
- let client = self . client . clone ( ) ;
286
- let guard = client. lock ( ) . await ;
287
-
288
- match guard. list_tools ( request) . await {
263
+ match self . client . list_tools ( request) . await {
289
264
Ok ( result) => {
290
265
debug ! (
291
266
"Proxying list_tools response with {} tools: {:?}" ,
@@ -306,9 +281,7 @@ impl ServerHandler for ProxyServer {
306
281
notification : rmcp:: model:: CancelledNotificationParam ,
307
282
_context : NotificationContext < RoleServer > ,
308
283
) {
309
- let client = self . client . clone ( ) ;
310
- let guard = client. lock ( ) . await ;
311
- match guard. notify_cancelled ( notification) . await {
284
+ match self . client . notify_cancelled ( notification) . await {
312
285
Ok ( _) => {
313
286
debug ! ( "[Proxy] Proxying cancelled notification" ) ;
314
287
}
@@ -323,9 +296,7 @@ impl ServerHandler for ProxyServer {
323
296
notification : rmcp:: model:: ProgressNotificationParam ,
324
297
_context : NotificationContext < RoleServer > ,
325
298
) {
326
- let client = self . client . clone ( ) ;
327
- let guard = client. lock ( ) . await ;
328
- match guard. notify_progress ( notification) . await {
299
+ match self . client . notify_progress ( notification) . await {
329
300
Ok ( _) => {
330
301
debug ! ( "[Proxy] Proxying progress notification" ) ;
331
302
}
0 commit comments