Skip to content

Commit 81464bb

Browse files
pravusjifnearnshaw
andauthored
feat: explorer mcp toggle in preview options (#1440)
* feat: explorer mcp toggle * added min sdk version gating --------- Co-authored-by: Nicolas Earnshaw <earnshaw.nico@gmail.com>
1 parent a2ff3c2 commit 81464bb

12 files changed

Lines changed: 37 additions & 2 deletions

File tree

packages/creator-hub/main/src/modules/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const PREVIEW_OPTIONS_MAP: Record<keyof PreviewArguments, string> = {
8383
openNewInstance: '-n',
8484
skipAuthScreen: '--skip-auth-screen',
8585
multiInstance: '--multi-instance',
86+
mcp: '--mcp',
8687
};
8788

8889
function generatePreviewArguments(opts: PreviewOptions) {
@@ -225,6 +226,7 @@ function updateDeepLinkWithOpts(params: string, newOpts: PreviewOptions): string
225226
setOrDeleteParam(PREVIEW_OPTIONS_MAP.skipAuthScreen, !newOpts.multiInstance);
226227
setOrDeleteParam(PREVIEW_OPTIONS_MAP.enableLandscapeTerrains, newOpts.enableLandscapeTerrains);
227228
setOrDeleteParam(PREVIEW_OPTIONS_MAP.multiInstance, newOpts.multiInstance);
229+
setOrDeleteParam(PREVIEW_OPTIONS_MAP.mcp, newOpts.mcp);
228230

229231
// this param is different from what we recieved from the CLI that the one that the launcher uses.
230232
setOrDeleteParam('open-deeplink-in-new-instance', newOpts.openNewInstance);

packages/creator-hub/renderer/src/components/EditorPage/MenuOptions/PreviewOptions.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function PreviewOptions({
2525
options,
2626
onShowMobileQR,
2727
supportsMultiInstance,
28+
supportsMcp,
2829
projectPath,
2930
}: PreviewOptionsProps) {
3031
const [terrainHiddenByScene, setTerrainHiddenByScene] = useState(false);
@@ -124,6 +125,17 @@ export function PreviewOptions({
124125
label={t('editor.header.actions.preview_options.multi_instance')}
125126
/>
126127
)}
128+
{supportsMcp && (
129+
<FormControlLabel
130+
control={
131+
<Checkbox
132+
checked={!!options.mcp}
133+
onChange={handleChange({ mcp: !options.mcp })}
134+
/>
135+
}
136+
label={t('editor.header.actions.preview_options.mcp')}
137+
/>
138+
)}
127139
</FormGroup>
128140
<Divider />
129141
<ListItemButton onClick={onShowMobileQR}>

packages/creator-hub/renderer/src/components/EditorPage/MenuOptions/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type PreviewOptionsProps = {
55
onChange: (options: PreviewOptions) => void;
66
onShowMobileQR: () => void;
77
supportsMultiInstance: boolean;
8+
supportsMcp: boolean;
89
projectPath: string;
910
};
1011

packages/creator-hub/renderer/src/components/EditorPage/component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function EditorPage() {
6464
publishScene,
6565
getMobileQR,
6666
supportsMultiInstance,
67+
supportsMcp,
6768
isPreviewRunning,
6869
startBevyRealm,
6970
killBevyRealm,
@@ -525,6 +526,7 @@ export function EditorPage() {
525526
onChange={handleChangePreviewOptions}
526527
onShowMobileQR={handleShowMobileQR}
527528
supportsMultiInstance={supportsMultiInstance}
529+
supportsMcp={supportsMcp}
528530
projectPath={project.path}
529531
/>
530532
}

packages/creator-hub/renderer/src/modules/store/editor/slice.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createSlice, isRejectedWithValue } from '@reduxjs/toolkit';
22
import { captureException } from '@sentry/electron/renderer';
33
import { createAsyncThunk } from '/@/modules/store/thunk';
44

5-
import { supportsMultiInstance } from '/shared/flags';
5+
import { supportsMcp, supportsMultiInstance } from '/shared/flags';
66
import type { DeployOptions } from '/shared/types/deploy';
77
import { isProjectError, ProjectError, type Project } from '/shared/types/projects';
88
import { type PreviewOptions } from '/shared/types/settings';
@@ -60,6 +60,7 @@ export const getMobileQR = createAsyncThunk(
6060
export type EditorState = {
6161
version: string | null;
6262
supportsMultiInstance: boolean;
63+
supportsMcp: boolean;
6364
project?: Project;
6465
inspectorPort: number;
6566
publishPort: number;
@@ -79,6 +80,7 @@ export type EditorState = {
7980
const initialState: EditorState = {
8081
version: null,
8182
supportsMultiInstance: false,
83+
supportsMcp: false,
8284
inspectorPort: 0,
8385
publishPort: 0,
8486
loadingPublish: false,
@@ -103,10 +105,12 @@ export const slice = createSlice({
103105
builder.addCase(workspaceActions.runProject.pending, state => {
104106
state.project = undefined;
105107
state.supportsMultiInstance = false;
108+
state.supportsMcp = false;
106109
state.error = null;
107110
});
108111
builder.addCase(workspaceActions.fetchSdkCommandsVersion.fulfilled, (state, action) => {
109112
state.supportsMultiInstance = supportsMultiInstance(action.payload);
113+
state.supportsMcp = supportsMcp(action.payload);
110114
});
111115
builder.addCase(workspaceActions.runProject.fulfilled, (state, action) => {
112116
state.project = action.payload;

packages/creator-hub/renderer/src/modules/store/translation/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"landscape_terrain_enabled": "Enable Landscape Terrains",
6666
"landscape_terrain_disabled_by_scene": "Landscape terrain is hidden by this scene's settings",
6767
"multi_instance": "Multi-Instance Preview",
68+
"mcp": "Enable MCP Server",
6869
"mobile_preview": "Show QR Code for Mobile"
6970
},
7071
"publish_options": {

packages/creator-hub/renderer/src/modules/store/translation/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"landscape_terrain_enabled": "Habilitar terrenos de vista panorámica",
6666
"landscape_terrain_disabled_by_scene": "El terreno panorámico está oculto por la configuración de esta escena",
6767
"multi_instance": "Vista previa multi-instancia",
68+
"mcp": "Habilitar servidor MCP",
6869
"mobile_preview": "Mostrar código QR para móvil"
6970
},
7071
"publish_options": {

packages/creator-hub/renderer/src/modules/store/translation/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"landscape_terrain_enabled": "启用景观地形",
6666
"landscape_terrain_disabled_by_scene": "此场景的设置已隐藏景观地形",
6767
"multi_instance": "多实例预览",
68+
"mcp": "启用 MCP 服务器",
6869
"mobile_preview": "显示移动端二维码"
6970
},
7071
"publish_options": {

packages/creator-hub/renderer/src/modules/store/workspace/slice.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
22

3-
import { supportsMultiInstance } from '/shared/flags';
3+
import { supportsMcp, supportsMultiInstance } from '/shared/flags';
44
import { type Project, SortBy } from '/shared/types/projects';
55
import {
66
DEFAULT_DEPENDENCY_UPDATE_STRATEGY,
@@ -28,6 +28,7 @@ const initialState: Async<Workspace> = {
2828
enableLandscapeTerrains: true,
2929
openNewInstance: false,
3030
multiInstance: false,
31+
mcp: false,
3132
showWarnings: true,
3233
client: DEFAULT_PREVIEW_CLIENT,
3334
},
@@ -188,6 +189,9 @@ export const slice = createSlice({
188189
if (!supportsMultiInstance(action.payload)) {
189190
state.settings.previewOptions.multiInstance = false;
190191
}
192+
if (!supportsMcp(action.payload)) {
193+
state.settings.previewOptions.mcp = false;
194+
}
191195
})
192196
.addCase(thunks.getProject.pending, (state, { meta }) => {
193197
const projectIdx = state.projects.findIndex($ => $.path === meta.arg.path);

packages/creator-hub/shared/flags.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import gte from 'semver/functions/gte';
22

33
// @dcl/sdk bundles @dcl/sdk-commands, so they always share the same version number.
44
const MIN_MULTI_INSTANCE_SDK_COMMANDS_VERSION = '7.20.4';
5+
const MIN_MCP_SDK_COMMANDS_VERSION = '7.25.0';
56

67
export function supportsMultiInstance(version: string | null | undefined): boolean {
78
return !!version && gte(version, MIN_MULTI_INSTANCE_SDK_COMMANDS_VERSION);
89
}
10+
11+
export function supportsMcp(version: string | null | undefined): boolean {
12+
return !!version && gte(version, MIN_MCP_SDK_COMMANDS_VERSION);
13+
}

0 commit comments

Comments
 (0)