Spaces:
Sleeping
Sleeping
Bot commited on
Commit ·
98c5c6c
1
Parent(s): ee9e12a
Fix npx permission issue in Stdio transport by injecting /tmp fallbacks
Browse files
src/lib/ai/mcp/create-mcp-client.ts
CHANGED
|
@@ -212,11 +212,19 @@ export class MCPClient {
|
|
| 212 |
}
|
| 213 |
|
| 214 |
const config = MCPStdioConfigZodSchema.parse(this.serverConfig);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
this.transport = new StdioClientTransport({
|
| 216 |
command: config.command,
|
| 217 |
args: config.args,
|
| 218 |
-
// Merge process.env with config.env, ensuring PATH is preserved and filtering out undefined values
|
| 219 |
-
env: Object.entries({ ...process.env, ...config.env }).reduce(
|
| 220 |
(acc, [key, value]) => {
|
| 221 |
if (value !== undefined) {
|
| 222 |
acc[key] = value;
|
|
|
|
| 212 |
}
|
| 213 |
|
| 214 |
const config = MCPStdioConfigZodSchema.parse(this.serverConfig);
|
| 215 |
+
|
| 216 |
+
// Inject writeable fallback directories for restricted container users (e.g. npx cache permissions)
|
| 217 |
+
const fallbackEnv: Record<string, string> = {
|
| 218 |
+
HOME: "/tmp",
|
| 219 |
+
npm_config_cache: "/tmp/.npm",
|
| 220 |
+
XDG_CACHE_HOME: "/tmp/.cache",
|
| 221 |
+
};
|
| 222 |
+
|
| 223 |
this.transport = new StdioClientTransport({
|
| 224 |
command: config.command,
|
| 225 |
args: config.args,
|
| 226 |
+
// Merge process.env with fallbackEnv and config.env, ensuring PATH is preserved and filtering out undefined values
|
| 227 |
+
env: Object.entries({ ...process.env, ...fallbackEnv, ...config.env }).reduce(
|
| 228 |
(acc, [key, value]) => {
|
| 229 |
if (value !== undefined) {
|
| 230 |
acc[key] = value;
|