Skip to content

Commit 326f036

Browse files
authored
Clean up MCP changes (#8442)
1 parent 35796f6 commit 326f036

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/io/flutter/dart/DtdRequest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2025 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.dart;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
/**
11+
* These are requests to DTD. More are listed here: <a href="https://github.com/dart-lang/sdk/blob/main/pkg/dtd/lib/src/constants.dart">...</a>
12+
*
13+
* Also see the protocol documentation: <a href="https://github.com/dart-lang/sdk/blob/main/pkg/dtd_impl/dtd_protocol.md">...</a>
14+
*/
15+
public enum DtdRequest {
16+
REGISTER_VM_SERVICE("ConnectedApp.registerVmService"),
17+
UNREGISTER_VM_SERVICE("ConnectedApp.unregisterVmService");
18+
19+
final public @NotNull String type;
20+
21+
DtdRequest(@NotNull String type) {
22+
this.type = type;
23+
}
24+
}

src/io/flutter/run/daemon/FlutterApp.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.flutter.ObservatoryConnector;
3636
import io.flutter.bazel.Workspace;
3737
import io.flutter.bazel.WorkspaceCache;
38+
import io.flutter.dart.DtdRequest;
3839
import io.flutter.dart.DtdUtils;
3940
import io.flutter.dart.FlutterDartAnalysisServer;
4041
import io.flutter.logging.FlutterConsoleLogManager;
@@ -686,8 +687,8 @@ class FlutterAppDaemonEventListener implements DaemonEvent.Listener {
686687

687688
private final @NotNull FlutterApp app;
688689
private final @NotNull ProgressHelper progress;
689-
private String appVmServiceUri;
690-
private final DtdUtils dtdUtils = new DtdUtils();
690+
private @Nullable String appVmServiceUri;
691+
private static final @NotNull DtdUtils dtdUtils = new DtdUtils();
691692

692693

693694
FlutterAppDaemonEventListener(@NotNull FlutterApp app, @NotNull Project project) {
@@ -751,7 +752,7 @@ public void onAppDebugPort(@NotNull DaemonEvent.AppDebugPort debugInfo) {
751752
final JsonObject params = new JsonObject();
752753
params.addProperty("uri", debugInfo.wsUri);
753754
params.addProperty("name", debugInfo.appId);
754-
sendDtdRequest("ConnectedApp.registerVmService", params);
755+
sendDtdRequest(DtdRequest.REGISTER_VM_SERVICE, params);
755756

756757
// Print the conneciton info to the console.
757758
final ConsoleView console = app.getConsole();
@@ -821,27 +822,30 @@ public void onAppStopped(@NotNull DaemonEvent.AppStopped stopped) {
821822

822823
final JsonObject params = new JsonObject();
823824
params.addProperty("uri", appVmServiceUri);
824-
sendDtdRequest("ConnectedApp.unregisterVmService", params);
825+
sendDtdRequest(DtdRequest.UNREGISTER_VM_SERVICE, params);
825826

826827
progress.cancel();
827828
app.getProcessHandler().destroyProcess();
828829
}
829830

830-
private void sendDtdRequest(@NotNull String requestName, @NotNull JsonObject params) {
831+
private void sendDtdRequest(@NotNull DtdRequest dtdRequest, @NotNull JsonObject params) {
831832
try {
832833
final DartToolingDaemonService dtdService = dtdUtils.readyDtdService(app.getProject()).get();
833834
if (dtdService == null) {
834835
return;
835836
}
836-
// This removes secret from params when we print out after receiving response.
837+
// Requests for this class require sending a secret to DTD to verify that this is a trusted client; however, we don't want to log the
838+
// secret. The DTD service class in the Dart plugin automatically adds the secret to the params, so without making an initial copy of
839+
// the input params, the secret would be logged.
840+
// TODO(helin24 in Dart plugin): Add secret to a copy of the request params.
837841
JsonObject initialParams = params.deepCopy();
838-
dtdService.sendRequest(requestName, params, true, object -> {
842+
dtdService.sendRequest(dtdRequest.type, params, true, object -> {
839843
final JsonObject result = object.getAsJsonObject("result");
840844
final JsonPrimitive type = result != null ? result.getAsJsonPrimitive("type") : null;
841845
if (type != null && "Success".equals(type.getAsString())) {
842-
LOG.info("Successful request " + requestName + " to DTD with params: " + initialParams);
846+
LOG.info("Successful request " + dtdRequest.type + " to DTD with params: " + initialParams);
843847
} else {
844-
LOG.warn("Failed request " + requestName + "to DTD with params: " + initialParams);
848+
LOG.warn("Failed request " + dtdRequest.type + "to DTD with params: " + initialParams);
845849
LOG.warn("Result: " + result);
846850
}
847851
});

0 commit comments

Comments
 (0)