Skip to content

Commit 1c8d8a9

Browse files
committed
Revert "feat: Add browser compatibility for HTTP-only MCP clients"
This reverts commit ccbb0c3.
1 parent ccbb0c3 commit 1c8d8a9

File tree

6 files changed

+8
-292
lines changed

6 files changed

+8
-292
lines changed

index.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { MCPAgent } from './src/agents/mcp_agent.js'
22
import { RemoteAgent } from './src/agents/remote.js'
33
import { MCPClient } from './src/client.js'
4+
import { loadConfigFile } from './src/config.js'
45
import { BaseConnector } from './src/connectors/base.js'
56
import { HttpConnector } from './src/connectors/http.js'
7+
import { StdioConnector } from './src/connectors/stdio.js'
68
import { WebSocketConnector } from './src/connectors/websocket.js'
79

810
import { Logger, logger } from './src/logging.js'
@@ -24,18 +26,4 @@ export { AIMessage, BaseMessage, HumanMessage, SystemMessage, ToolMessage } from
2426
// Re-export StreamEvent type from LangChain for convenience
2527
export type { StreamEvent } from '@langchain/core/tracers/log_stream'
2628

27-
export { BaseConnector, HttpConnector, Logger, logger, MCPAgent, MCPClient, MCPSession, RemoteAgent, WebSocketConnector }
28-
29-
// Conditionally export Node.js-specific functionality
30-
// Check if we're in a Node.js environment
31-
const isNodeJS = typeof process !== 'undefined'
32-
&& process.versions
33-
&& process.versions.node
34-
&& typeof window === 'undefined'
35-
36-
// Only export these in Node.js environments to prevent browser import errors
37-
export const StdioConnector = isNodeJS ? undefined : undefined
38-
export const loadConfigFile = isNodeJS ? undefined : undefined
39-
40-
// Note: The actual Node.js implementations are loaded by the config.ts module
41-
// when needed, avoiding import-time errors in browser environments
29+
export { BaseConnector, HttpConnector, loadConfigFile, Logger, logger, MCPAgent, MCPClient, MCPSession, RemoteAgent, StdioConnector, WebSocketConnector }

package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,8 @@
2828
],
2929
"exports": {
3030
".": {
31-
"browser": {
32-
"types": "./dist/browser.d.ts",
33-
"import": "./dist/browser.js"
34-
},
35-
"node": {
36-
"types": "./dist/index.d.ts",
37-
"import": "./dist/index.js"
38-
},
39-
"default": {
40-
"types": "./dist/index.d.ts",
41-
"import": "./dist/index.js"
42-
}
31+
"types": "./dist/index.d.ts",
32+
"import": "./dist/index.js"
4333
}
4434
},
4535
"main": "./dist/index.js",

src/browser.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/client-browser.ts

Lines changed: 0 additions & 145 deletions
This file was deleted.

src/config-browser.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/config.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
import type { BaseConnector } from './connectors/base.js'
2+
import { readFileSync } from 'node:fs'
23
import { HttpConnector } from './connectors/http.js'
4+
import { StdioConnector } from './connectors/stdio.js'
35
import { WebSocketConnector } from './connectors/websocket.js'
46

5-
// Check if we're in a Node.js environment
6-
const isNodeJS = typeof process !== 'undefined'
7-
&& process.versions
8-
&& process.versions.node
9-
&& typeof window === 'undefined'
10-
11-
// Conditionally import Node.js-specific modules
12-
let StdioConnector: any
13-
let readFileSync: any
14-
15-
if (isNodeJS) {
16-
try {
17-
// Dynamic import for Node.js-specific modules
18-
Promise.all([
19-
import('./connectors/stdio.js'),
20-
import('node:fs'),
21-
]).then(([stdioModule, fsModule]) => {
22-
StdioConnector = stdioModule.StdioConnector
23-
readFileSync = fsModule.readFileSync
24-
}).catch((error) => {
25-
console.warn('Failed to load Node.js modules:', error)
26-
})
27-
}
28-
catch (error) {
29-
console.warn('Failed to load Node.js modules:', error)
30-
}
31-
}
32-
337
export function loadConfigFile(filepath: string): Record<string, any> {
34-
if (!isNodeJS || !readFileSync) {
35-
throw new Error('loadConfigFile is only available in Node.js environments')
36-
}
37-
388
const raw = readFileSync(filepath, 'utf-8')
399
return JSON.parse(raw)
4010
}
@@ -43,10 +13,6 @@ export function createConnectorFromConfig(
4313
serverConfig: Record<string, any>,
4414
): BaseConnector {
4515
if ('command' in serverConfig && 'args' in serverConfig) {
46-
if (!isNodeJS || !StdioConnector) {
47-
throw new Error('StdioConnector is not available in browser environments. Use HTTP or WebSocket connectors instead.')
48-
}
49-
5016
return new StdioConnector({
5117
command: serverConfig.command,
5218
args: serverConfig.args,
@@ -73,5 +39,5 @@ export function createConnectorFromConfig(
7339
})
7440
}
7541

76-
throw new Error('Cannot determine connector type from config. Browser environments only support HTTP and WebSocket connectors.')
42+
throw new Error('Cannot determine connector type from config')
7743
}

0 commit comments

Comments
 (0)