1
1
import { v1 } from "@docker/extension-api-client-types" ;
2
- import { getUser , escapeJSONForPlatformShell } from "../FileUtils" ;
2
+ import { BUSYBOX } from "../Constants" ;
3
+ import { getUser , writeToMount } from "../FileUtils" ;
3
4
import { MCPClient , SAMPLE_MCP_CONFIG } from "./MCPTypes" ;
4
5
5
6
class ClaudeDesktopClient implements MCPClient {
@@ -39,7 +40,7 @@ class ClaudeDesktopClient implements MCPClient {
39
40
const user = await getUser ( client )
40
41
path = path . replace ( '$USER' , user )
41
42
try {
42
- const result = await client . docker . cli . exec ( 'run' , [ '--rm' , '--mount' , `type=bind,source="${ path } ",target=/config.json` , 'alpine:latest' , 'sh ' , '-c' , `"cat /config.json"` ] )
43
+ const result = await client . docker . cli . exec ( 'run' , [ '--rm' , '--mount' , `type=bind,source="${ path } ",target=/config.json` , BUSYBOX , '/bin/cat ' , '/config.json' ] )
43
44
return { content : result . stdout || undefined , path : path } ;
44
45
} catch ( e ) {
45
46
return { content : null , path : path } ;
@@ -63,30 +64,31 @@ class ClaudeDesktopClient implements MCPClient {
63
64
}
64
65
const user = await getUser ( client )
65
66
path = path . replace ( '$USER' , user )
66
- let payload = {
67
- mcpServers : {
68
- MCP_DOCKER : SAMPLE_MCP_CONFIG . mcpServers . MCP_DOCKER
69
- }
70
- }
67
+
68
+ let payload : Record < string , any > = { }
71
69
try {
72
- const result = await client . docker . cli . exec ( 'run' , [ '--rm' , '--mount' , `type=bind,source="${ path } ",target=/claude_desktop_config` , 'alpine:latest' , 'sh' , '-c' , `"cat /claude_desktop_config/claude_desktop_config.json"` ] )
70
+ const result = await client . docker . cli . exec ( 'run' , [
71
+ '--rm' ,
72
+ '--mount' ,
73
+ `type=bind,source="${ path } ",target=/claude_desktop_config` ,
74
+ BUSYBOX ,
75
+ '/bin/cat' ,
76
+ '/claude_desktop_config/claude_desktop_config.json' ,
77
+ ] )
73
78
if ( result . stdout ) {
74
79
payload = JSON . parse ( result . stdout )
75
- payload . mcpServers . MCP_DOCKER = SAMPLE_MCP_CONFIG . mcpServers . MCP_DOCKER
76
80
}
77
81
} catch ( e ) {
78
82
// No config or malformed config found, overwrite it
79
83
}
84
+
85
+ if ( ! payload . mcpServers ) {
86
+ payload . mcpServers = { }
87
+ }
88
+ payload . mcpServers . MCP_DOCKER = SAMPLE_MCP_CONFIG . mcpServers . MCP_DOCKER
89
+
80
90
try {
81
- await client . docker . cli . exec ( 'run' ,
82
- [
83
- '--rm' ,
84
- '--mount' ,
85
- `type=bind,source="${ path } ",target=/claude_desktop_config` ,
86
- '--workdir' ,
87
- '/claude_desktop_config' ,
88
- 'vonwig/function_write_files:latest' ,
89
- escapeJSONForPlatformShell ( { files : [ { path : 'claude_desktop_config.json' , content : JSON . stringify ( payload , null , 2 ) } ] } , client . host . platform ) ] )
91
+ await writeToMount ( client , `type=bind,source="${ path } ",target=/claude_desktop_config` , '/claude_desktop_config/claude_desktop_config.json' , JSON . stringify ( payload , null , 2 ) ) ;
90
92
} catch ( e ) {
91
93
client . desktopUI . toast . error ( ( e as any ) . stderr )
92
94
}
@@ -111,26 +113,10 @@ class ClaudeDesktopClient implements MCPClient {
111
113
path = path . replace ( '$USER' , user )
112
114
try {
113
115
// This method is only called after the config has been validated, so we can safely assume it's a valid config.
114
- const previousConfig = JSON . parse ( ( await client . docker . cli . exec ( 'run' , [ '--rm' , '--mount' , `type=bind,source="${ path } ",target=/claude_desktop_config` , '--workdir ' , '/claude_desktop_config' , 'alpine:latest' , 'sh ' , '-c' , `"cat /claude_desktop_config/claude_desktop_config.json"` ] ) ) . stdout || '{}' )
116
+ const previousConfig = JSON . parse ( ( await client . docker . cli . exec ( 'run' , [ '--rm' , '--mount' , `type=bind,source="${ path } ",target=/claude_desktop_config` , '-w ' , '/claude_desktop_config' , BUSYBOX , '/bin/cat ' , '/claude_desktop_config/claude_desktop_config.json' ] ) ) . stdout || '{}' )
115
117
const newConfig = { ...previousConfig }
116
118
delete newConfig . mcpServers . MCP_DOCKER
117
- await client . docker . cli . exec ( 'run' , [
118
- '--rm' ,
119
- '--mount' ,
120
- `type=bind,source="${ path } ",target=/claude_desktop_config` ,
121
- '--workdir' ,
122
- '/claude_desktop_config' ,
123
- 'vonwig/function_write_files:latest' ,
124
- escapeJSONForPlatformShell (
125
- {
126
- files :
127
- [ {
128
- path : 'claude_desktop_config.json' ,
129
- content : JSON . stringify ( newConfig , null , 2 )
130
- } ]
131
- } ,
132
- client . host . platform )
133
- ] )
119
+ await writeToMount ( client , `type=bind,source="${ path } ",target=/claude_desktop_config` , '/claude_desktop_config/claude_desktop_config.json' , JSON . stringify ( newConfig , null , 2 ) ) ;
134
120
} catch ( e ) {
135
121
client . desktopUI . toast . error ( ( e as any ) . stderr )
136
122
}
0 commit comments