Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(mcp): stop reading process.platform in the browser when reporting installs (#20406)

Arvin Xuf77d872657be
diff --git a/src/store/tool/slices/mcpStore/action.test.ts b/src/store/tool/slices/mcpStore/action.test.ts
index db012fb70ce..f0e4aa12e06 100644
--- a/src/store/tool/slices/mcpStore/action.test.ts
+++ b/src/store/tool/slices/mcpStore/action.test.ts
@@ -10,9 +10,15 @@ import { pluginService } from '@/services/plugin';
import { globalHelpers } from '@/store/global/helpers';
import { type CheckMcpInstallResult } from '@/types/plugins';
import { MCPInstallStep } from '@/types/plugins';
+import type * as PlatformModule from '@/utils/platform';
import { useToolStore } from '../../store';
+vi.mock('@/utils/platform', async (importOriginal) => ({
+ ...(await importOriginal<typeof PlatformModule>()),
+ getPlatform: () => 'Mac OS',
+}));
+
vi.mock('@/libs/trpc/client', () => ({
asyncClient: {},
lambdaClient: {
@@ -1398,6 +1404,30 @@ describe('mcpStore actions', () => {
}),
);
});
+
+ it('should fall back to the browser platform when the check result has none', async () => {
+ const { result } = renderHook(() => useToolStore());
+ const { platform: _, ...checkResultWithoutPlatform } = mockCheckResult;
+ vi.spyOn(mcpService, 'checkInstallation').mockResolvedValue(
+ checkResultWithoutPlatform as CheckMcpInstallResult,
+ );
+
+ act(() => {
+ useToolStore.setState({
+ mcpPluginItems: [mockPlugin],
+ });
+ });
+
+ let installResult;
+ await act(async () => {
+ installResult = await result.current.installMCPPlugin('test-plugin');
+ });
+
+ expect(installResult).toBe(true);
+ expect(discoverService.reportMcpInstallResult).toHaveBeenCalledWith(
+ expect.objectContaining({ platform: 'Mac OS', success: true }),
+ );
+ });
});
});
});
diff --git a/src/store/tool/slices/mcpStore/action.ts b/src/store/tool/slices/mcpStore/action.ts
index 5763df8833f..51a853a5775 100644
--- a/src/store/tool/slices/mcpStore/action.ts
+++ b/src/store/tool/slices/mcpStore/action.ts
@@ -27,6 +27,7 @@ import {
type MCPPluginListParams,
} from '@/types/plugins';
import { MCPInstallStep } from '@/types/plugins';
+import { getPlatform } from '@/utils/platform';
import { sleep } from '@/utils/sleep';
import { setNamespace } from '@/utils/storeDebug';
@@ -598,7 +599,7 @@ export class PluginMCPStoreActionImpl {
resources: (manifest as any).resources,
tools: (manifest as any).tools,
},
- platform: result?.platform || process.platform,
+ platform: result?.platform || getPlatform(),
success: true,
userAgent,
version: manifest.version || data.version,
@@ -686,7 +687,7 @@ export class PluginMCPStoreActionImpl {
installDurationMs,
installParams: connection,
metadata: errorInfo.metadata,
- platform: result?.platform || process.platform,
+ platform: result?.platform || getPlatform(),
success: false,
userAgent,
version: data?.version,