feat: Add real-time progress output for MCP init action

- MCP server outputs progress to stderr during smart_search init
- Progress format: [Progress] {percent}% - {message}
- Does not interfere with JSON-RPC protocol (stdout)
- Added executeInitWithProgress for external progress callback
- Added executeToolWithProgress to tools/index.ts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-18 00:05:32 +08:00
parent 48ac43d628
commit b9d068d6d4
3 changed files with 143 additions and 2 deletions

View File

@@ -18,8 +18,10 @@ import * as convertTokensToCssMod from './convert-tokens-to-css.js';
import * as sessionManagerMod from './session-manager.js';
import * as cliExecutorMod from './cli-executor.js';
import * as smartSearchMod from './smart-search.js';
import { executeInitWithProgress } from './smart-search.js';
// codex_lens removed - functionality integrated into smart_search
import * as readFileMod from './read-file.js';
import type { ProgressInfo } from './codex-lens.js';
// Import legacy JS tools
import { uiGeneratePreviewTool } from './ui-generate-preview.js';
@@ -260,6 +262,60 @@ function sanitizeResult(result: unknown): unknown {
return result;
}
/**
* Execute a tool with progress callback (for init actions)
*/
export async function executeToolWithProgress(
name: string,
params: Record<string, unknown> = {},
onProgress?: (progress: ProgressInfo) => void
): Promise<{
success: boolean;
result?: unknown;
error?: string;
}> {
// For smart_search init, use special progress-aware execution
if (name === 'smart_search' && params.action === 'init') {
try {
// Notify dashboard - execution started
notifyDashboard({
toolName: name,
status: 'started',
params: sanitizeParams(params)
});
const result = await executeInitWithProgress(params, onProgress);
// Notify dashboard - execution completed
notifyDashboard({
toolName: name,
status: 'completed',
result: sanitizeResult(result)
});
return {
success: result.success,
result,
error: result.error
};
} catch (error) {
notifyDashboard({
toolName: name,
status: 'failed',
error: (error as Error).message || 'Tool execution failed'
});
return {
success: false,
error: (error as Error).message || 'Tool execution failed'
};
}
}
// Fall back to regular execution for other tools
return executeTool(name, params);
}
/**
* Get tool schema in MCP-compatible format
*/