data fixes, partial custom indicator support
This commit is contained in:
@@ -27,7 +27,8 @@ export function createMCPToolWrapper(
|
||||
toolInfo: MCPToolInfo,
|
||||
mcpClient: MCPClientConnector,
|
||||
logger: FastifyBaseLogger,
|
||||
onImage?: (image: { data: string; mimeType: string }) => void
|
||||
onImage?: (image: { data: string; mimeType: string }) => void,
|
||||
onWorkspaceMutation?: (storeName: string, newState: unknown) => void
|
||||
): DynamicStructuredTool {
|
||||
// Convert MCP input schema to Zod schema
|
||||
const zodSchema = mcpInputSchemaToZod(toolInfo.inputSchema);
|
||||
@@ -42,6 +43,28 @@ export function createMCPToolWrapper(
|
||||
|
||||
logger.info({ tool: toolInfo.name }, 'MCP tool call completed');
|
||||
|
||||
// Fire workspace mutation callback when workspace_patch or workspace_write succeeds.
|
||||
// The sandbox returns {"success": true, "data": <newState>} as a text content item.
|
||||
if (
|
||||
onWorkspaceMutation &&
|
||||
(toolInfo.name === 'workspace_patch' || toolInfo.name === 'workspace_write')
|
||||
) {
|
||||
const content = (result as any)?.content;
|
||||
if (Array.isArray(content)) {
|
||||
for (const item of content) {
|
||||
if (item.type === 'text' && item.text) {
|
||||
try {
|
||||
const parsed = JSON.parse(item.text);
|
||||
if (parsed?.success && parsed?.data !== undefined) {
|
||||
onWorkspaceMutation((input as any).store_name as string, parsed.data);
|
||||
}
|
||||
} catch { /* ignore parse errors */ }
|
||||
break; // only need first text item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle different MCP result formats
|
||||
if (typeof result === 'string') {
|
||||
return result;
|
||||
@@ -180,7 +203,10 @@ export function createMCPToolWrappers(
|
||||
toolInfos: MCPToolInfo[],
|
||||
mcpClient: MCPClientConnector,
|
||||
logger: FastifyBaseLogger,
|
||||
onImage?: (image: { data: string; mimeType: string }) => void
|
||||
onImage?: (image: { data: string; mimeType: string }) => void,
|
||||
onWorkspaceMutation?: (storeName: string, newState: unknown) => void
|
||||
): DynamicStructuredTool[] {
|
||||
return toolInfos.map(toolInfo => createMCPToolWrapper(toolInfo, mcpClient, logger, onImage));
|
||||
return toolInfos.map(toolInfo =>
|
||||
createMCPToolWrapper(toolInfo, mcpClient, logger, onImage, onWorkspaceMutation)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user