@papercraneai/sandbox-agent 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +14 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -383,11 +383,14 @@ const showPreviewTool = tool("ShowPreview", "Shows the preview iframe for a spec
|
|
|
383
383
|
}]
|
|
384
384
|
};
|
|
385
385
|
});
|
|
386
|
-
//
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
386
|
+
// Factory to create a fresh MCP server per chat session
|
|
387
|
+
// (each Protocol instance can only be connected to one transport at a time)
|
|
388
|
+
function createClientToolsServer() {
|
|
389
|
+
return createSdkMcpServer({
|
|
390
|
+
name: "client-tools",
|
|
391
|
+
tools: [showPreviewTool]
|
|
392
|
+
});
|
|
393
|
+
}
|
|
391
394
|
// Recursively build file tree
|
|
392
395
|
async function buildFileTree(dirPath) {
|
|
393
396
|
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
@@ -1180,13 +1183,14 @@ app.post("/chat", async (req, res) => {
|
|
|
1180
1183
|
"KillShell",
|
|
1181
1184
|
"mcp__client-tools__ShowPreview"
|
|
1182
1185
|
];
|
|
1186
|
+
const clientTools = createClientToolsServer();
|
|
1183
1187
|
const options = {
|
|
1184
1188
|
maxTurns,
|
|
1185
1189
|
cwd,
|
|
1186
1190
|
permissionMode: "bypassPermissions",
|
|
1187
1191
|
allowDangerouslySkipPermissions: true,
|
|
1188
1192
|
mcpServers: {
|
|
1189
|
-
"client-tools":
|
|
1193
|
+
"client-tools": clientTools
|
|
1190
1194
|
},
|
|
1191
1195
|
allowedTools: allowedTools || defaultTools,
|
|
1192
1196
|
settingSources: ["project"],
|
|
@@ -1267,6 +1271,10 @@ app.post("/chat", async (req, res) => {
|
|
|
1267
1271
|
res.end();
|
|
1268
1272
|
}
|
|
1269
1273
|
}
|
|
1274
|
+
finally {
|
|
1275
|
+
// Close the per-session MCP server to free resources
|
|
1276
|
+
await clientTools.instance?.close().catch(() => { });
|
|
1277
|
+
}
|
|
1270
1278
|
});
|
|
1271
1279
|
// =============================================================================
|
|
1272
1280
|
// Registration & Heartbeat
|