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

@@ -10,7 +10,7 @@ import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { getAllToolSchemas, executeTool } from '../tools/index.js';
import { getAllToolSchemas, executeTool, executeToolWithProgress } from '../tools/index.js';
import type { ToolSchema, ToolResult } from '../types/tool.js';
const SERVER_NAME = 'ccw-tools';
@@ -104,7 +104,19 @@ function createServer(): Server {
}
try {
const result: ToolResult = await executeTool(name, args || {});
// For smart_search init action, use progress-aware execution
const isInitAction = name === 'smart_search' && args?.action === 'init';
let result: ToolResult;
if (isInitAction) {
// Execute with progress callback that writes to stderr
result = await executeToolWithProgress(name, args || {}, (progress) => {
// Output progress to stderr (visible in terminal, doesn't interfere with JSON-RPC)
console.error(`[Progress] ${progress.percent}% - ${progress.message}`);
});
} else {
result = await executeTool(name, args || {});
}
if (!result.success) {
return {