check_package_json
Analyze package.json files to identify dependencies, scripts, and configurations. Supports multiple package managers and provides detailed insights for development workflows.
Instructions
Read and analyze package.json file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | Directory containing package.json (default: current directory) |
Implementation Reference
- src/index.ts:214-247 (handler)The handler function that executes the tool's logic: reads package.json, parses it, analyzes key fields (name, version, dependencies, devDependencies, scripts, main, type), and returns a text response with the analysis.private async checkPackageJson(args: any) { const directory = args?.directory || process.cwd(); const packagePath = join(directory, 'package.json'); if (!existsSync(packagePath)) { throw new Error(`package.json not found in ${directory}`); } try { const packageContent = readFileSync(packagePath, 'utf8'); const packageJson = JSON.parse(packageContent); const analysis = { name: packageJson.name || 'N/A', version: packageJson.version || 'N/A', dependencies: Object.keys(packageJson.dependencies || {}), devDependencies: Object.keys(packageJson.devDependencies || {}), scripts: Object.keys(packageJson.scripts || {}), main: packageJson.main || 'N/A', type: packageJson.type || 'commonjs' }; return { content: [ { type: 'text', text: `Package.json analysis:\n${JSON.stringify(analysis, null, 2)}` } ] }; } catch (error: any) { throw new Error(`Failed to parse package.json: ${error.message}`); } }
- src/index.ts:81-93 (registration)Registers the tool in the ListTools response, specifying name, description, and input schema.{ name: 'check_package_json', description: 'Read and analyze package.json file', inputSchema: { type: 'object', properties: { directory: { type: 'string', description: 'Directory containing package.json (default: current directory)' } } } },
- src/index.ts:84-92 (schema)Input schema definition for the tool, defining an optional 'directory' string parameter.inputSchema: { type: 'object', properties: { directory: { type: 'string', description: 'Directory containing package.json (default: current directory)' } } }
- src/index.ts:143-144 (helper)Switch case in the CallToolRequest handler that routes the tool call to the checkPackageJson method.case 'check_package_json': return await this.checkPackageJson(args);