Skip to main content
Glama

CTS MCP Server

by EricA1019
parse_worker.ts2.66 kB
/** * Parse Worker Thread * * Worker thread entry point for parallel AST parsing. * Receives file paths via workerData and returns parsed AST trees. * * Architecture: * - Main thread: ProjectScanner orchestrates workers * - Worker threads: This file, parses chunk of files independently * - Communication: parentPort messaging (structured clone) * * @module scanner/parse_worker */ import { parentPort, workerData } from 'worker_threads'; import { TreeSitterBridge } from '../parsers/tree_sitter_bridge.js'; import { statSync } from 'fs'; import type { WorkerPayload, WorkerResult, ASTWithMetadata } from './types.js'; /** * Worker thread main function. * * Parses all files in workerData.files and sends results via parentPort. */ async function main() { if (!parentPort) { console.error('parse_worker.ts must be run as a Worker thread'); process.exit(1); } const payload = workerData as WorkerPayload; const { files, workerId } = payload; const trees: ASTWithMetadata[] = []; const errors: Array<{ filePath: string; error: string }> = []; // Initialize tree-sitter bridge const bridge = new TreeSitterBridge(); try { await bridge.init(); } catch (error) { parentPort.postMessage({ trees: [], workerId, errors: [{ filePath: '<init>', error: `Failed to initialize tree-sitter: ${error instanceof Error ? error.message : String(error)}`, }], } satisfies WorkerResult); return; } // Parse each file in chunk for (const filePath of files) { try { const startTime = Date.now(); const tree = await bridge.parseFile(filePath); const parseDuration = Date.now() - startTime; // Get file metadata const stats = statSync(filePath); trees.push({ tree, filePath, sizeBytes: stats.size, parseDurationMs: parseDuration, mtime: Math.floor(stats.mtimeMs), }); } catch (error) { // Non-fatal error - collect and continue errors.push({ filePath, error: error instanceof Error ? error.message : String(error), }); } } // Send results back to main thread const result: WorkerResult = { trees, workerId, errors, }; parentPort.postMessage(result); } // Run worker main().catch((error) => { if (parentPort) { parentPort.postMessage({ trees: [], workerId: workerData?.workerId ?? -1, errors: [{ filePath: '<worker>', error: `Worker crashed: ${error instanceof Error ? error.message : String(error)}`, }], } satisfies WorkerResult); } process.exit(1); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EricA1019/CTS_MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server