Skip to content

Commit 67bbe35

Browse files
committed
Catch already registered exception registering sampling service
1 parent c64b5d6 commit 67bbe35

File tree

1 file changed

+11
-5
lines changed
  • pkgs/dart_mcp_server/lib/src/mixins

1 file changed

+11
-5
lines changed

pkgs/dart_mcp_server/lib/src/mixins/dtd.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,17 @@ base mixin DartToolingDaemonSupport
290290
final dtd = _dtd!;
291291

292292
if (clientCapabilities.sampling != null) {
293-
await dtd.registerService(
294-
McpServiceConstants.serviceName,
295-
McpServiceConstants.samplingRequest,
296-
_handleSamplingRequest,
297-
);
293+
try {
294+
await dtd.registerService(
295+
McpServiceConstants.serviceName,
296+
McpServiceConstants.samplingRequest,
297+
_handleSamplingRequest,
298+
);
299+
} on RpcException catch (e) {
300+
// It is expected for there to be an exception if the sampling service
301+
// was already registered by another Dart MCP Server.
302+
if (e.code != RpcErrorCodes.kServiceAlreadyRegistered) rethrow;
303+
}
298304
}
299305
}
300306

0 commit comments

Comments
 (0)