From 5aa952f7c7ea3ef523728570e358cdc23da41d6d Mon Sep 17 00:00:00 2001 From: Razvan Rotaru Date: Wed, 3 Dec 2025 23:02:58 +0200 Subject: [PATCH] fix(client): use type-only imports for @modelcontextprotocol/sdk types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change value imports to `import type` syntax for SDK types to prevent bundlers from including Node.js server code in browser builds. When bundling @mcp-ui/client for pure browser environments, the @modelcontextprotocol/sdk's server-side code (which imports Express) was being included due to the import chain, causing "require is not defined" errors at runtime. Since the SDK is only used for TypeScript types (not runtime values), using `import type` ensures these imports are stripped at compile time and don't trigger bundling of the SDK's server-side modules. Files changed: - UIResourceRendererWC.tsx: EmbeddedResource type - metadataUtils.ts: Resource type - processResource.ts: EmbeddedResource, Resource types - UIResourceRenderer.unmocked.test.tsx: EmbeddedResource type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- sdks/typescript/client/src/components/UIResourceRendererWC.tsx | 2 +- .../components/__tests__/UIResourceRenderer.unmocked.test.tsx | 2 +- sdks/typescript/client/src/utils/metadataUtils.ts | 2 +- sdks/typescript/client/src/utils/processResource.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdks/typescript/client/src/components/UIResourceRendererWC.tsx b/sdks/typescript/client/src/components/UIResourceRendererWC.tsx index 33740688..412e1874 100644 --- a/sdks/typescript/client/src/components/UIResourceRendererWC.tsx +++ b/sdks/typescript/client/src/components/UIResourceRendererWC.tsx @@ -2,7 +2,7 @@ import r2wc from '@r2wc/react-to-web-component'; import { UIResourceRenderer, type UIResourceRendererProps } from './UIResourceRenderer'; import { FC, useCallback, useRef } from 'react'; import { UIActionResult } from '../types'; -import { EmbeddedResource } from '@modelcontextprotocol/sdk/types.js'; +import type { EmbeddedResource } from '@modelcontextprotocol/sdk/types.js'; type UIResourceRendererWCProps = Omit & { diff --git a/sdks/typescript/client/src/components/__tests__/UIResourceRenderer.unmocked.test.tsx b/sdks/typescript/client/src/components/__tests__/UIResourceRenderer.unmocked.test.tsx index 68cda4a1..b17cd15c 100644 --- a/sdks/typescript/client/src/components/__tests__/UIResourceRenderer.unmocked.test.tsx +++ b/sdks/typescript/client/src/components/__tests__/UIResourceRenderer.unmocked.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, render } from '@testing-library/react'; import '@testing-library/jest-dom'; import React from 'react'; -import { EmbeddedResource } from '@modelcontextprotocol/sdk/types.js'; +import type { EmbeddedResource } from '@modelcontextprotocol/sdk/types.js'; import { UIResourceRenderer } from '../UIResourceRenderer'; import { UI_METADATA_PREFIX } from '../../types'; diff --git a/sdks/typescript/client/src/utils/metadataUtils.ts b/sdks/typescript/client/src/utils/metadataUtils.ts index cd32c3da..8305c75a 100644 --- a/sdks/typescript/client/src/utils/metadataUtils.ts +++ b/sdks/typescript/client/src/utils/metadataUtils.ts @@ -1,4 +1,4 @@ -import { Resource } from '@modelcontextprotocol/sdk/types.js'; +import type { Resource } from '@modelcontextprotocol/sdk/types.js'; import { UI_METADATA_PREFIX, UIResourceMetadata } from '../types'; export function getResourceMetadata(resource: Partial): Record { diff --git a/sdks/typescript/client/src/utils/processResource.ts b/sdks/typescript/client/src/utils/processResource.ts index c1b549d6..2d4f524f 100644 --- a/sdks/typescript/client/src/utils/processResource.ts +++ b/sdks/typescript/client/src/utils/processResource.ts @@ -1,4 +1,4 @@ -import { EmbeddedResource, Resource } from '@modelcontextprotocol/sdk/types.js'; +import type { EmbeddedResource, Resource } from '@modelcontextprotocol/sdk/types.js'; type ProcessResourceResult = { error?: string;