Skip to main content
Glama

scan_dependencies

Scans Maven project dependencies to build a class-to-JAR mapping index for accurate dependency analysis and code generation.

Instructions

扫描Maven项目的所有依赖,建立类名到JAR包的映射索引

Input Schema

NameRequiredDescriptionDefault
forceRefreshNo是否强制刷新索引
projectPathYesMaven项目根目录路径

Input Schema (JSON Schema)

{ "properties": { "forceRefresh": { "default": false, "description": "是否强制刷新索引", "type": "boolean" }, "projectPath": { "description": "Maven项目根目录路径", "type": "string" } }, "required": [ "projectPath" ], "type": "object" }

Implementation Reference

  • src/index.ts:26-28 (registration)
    Tool registration in server capabilities
    scan_dependencies: { description: '扫描Maven项目的所有依赖,建立类名到JAR包的映射索引', },
  • JSON schema definition for scan_dependencies tool input
    name: 'scan_dependencies', description: '扫描Maven项目的所有依赖,建立类名到JAR包的映射索引', inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Maven项目根目录路径', }, forceRefresh: { type: 'boolean', description: '是否强制刷新索引', default: false, }, }, required: ['projectPath'], }, },
  • MCP tool handler function that delegates to DependencyScanner.scanProject
    private async handleScanDependencies(args: any) { const { projectPath, forceRefresh = false } = args; const result = await this.scanner.scanProject(projectPath, forceRefresh); return { content: [ { type: 'text', text: `依赖扫描完成!\n\n` + `扫描的JAR包数量: ${result.jarCount}\n` + `索引的类数量: ${result.classCount}\n` + `索引文件路径: ${result.indexPath}\n\n` + `示例索引条目:\n${result.sampleEntries.slice(0, 5).join('\n')}`, }, ], }; }
  • Core implementation of dependency scanning logic, including Maven dependency resolution, JAR parsing, and index generation.
    async scanProject(projectPath: string, forceRefresh: boolean = false): Promise<ScanResult> { const indexPath = path.join(projectPath, '.mcp-class-index.json'); const isDebug = process.env.NODE_ENV === 'development'; // 如果强制刷新,先删除旧的索引文件 if (forceRefresh && await fs.pathExists(indexPath)) { if (isDebug) { console.error('强制刷新:删除旧的索引文件'); } await fs.remove(indexPath); } // 检查缓存 if (!forceRefresh && await fs.pathExists(indexPath)) { if (isDebug) { console.error('使用缓存的类索引'); } const cachedIndex = await fs.readJson(indexPath); return { jarCount: cachedIndex.jarCount, classCount: cachedIndex.classCount, indexPath, sampleEntries: cachedIndex.sampleEntries }; } if (isDebug) { console.error('开始扫描Maven依赖...'); } // 1. 获取Maven依赖树 const dependencies = await this.getMavenDependencies(projectPath); console.error(`找到 ${dependencies.length} 个依赖JAR包`); // 2. 解析每个JAR包,建立类索引 const classIndex: ClassIndexEntry[] = []; let processedJars = 0; for (const jarPath of dependencies) { try { const classes = await this.extractClassesFromJar(jarPath); classIndex.push(...classes); processedJars++; if (processedJars % 10 === 0) { console.error(`已处理 ${processedJars}/${dependencies.length} 个JAR包`); } } catch (error) { console.warn(`处理JAR包失败: ${jarPath}, 错误: ${error}`); } } // 3. 保存索引到文件 const result: ScanResult = { jarCount: processedJars, classCount: classIndex.length, indexPath, sampleEntries: classIndex.slice(0, 10).map(entry => `${entry.className} -> ${path.basename(entry.jarPath)}` ) }; await fs.outputJson(indexPath, { ...result, classIndex, lastUpdated: new Date().toISOString() }, { spaces: 2 }); console.error(`扫描完成!处理了 ${processedJars} 个JAR包,索引了 ${classIndex.length} 个类`); return result; }

Latest Blog Posts

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/handsomestWei/java-class-analyzer-mcp-server'

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