check_package_json
Analyze package.json files to identify dependencies, scripts, and configuration details for development workflow management.
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 reads the package.json file from the given directory, parses it, extracts key information (name, version, dependencies, devDependencies, scripts, main, type), formats it as JSON, and returns it in the tool response format.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:84-92 (schema)Input schema definition for the check_package_json tool, specifying an optional directory parameter.inputSchema: { type: 'object', properties: { directory: { type: 'string', description: 'Directory containing package.json (default: current directory)' } } }
- src/index.ts:81-93 (registration)Tool object registration in the ListToolsRequestHandler, defining 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:143-144 (registration)Dispatch case in the CallToolRequestHandler that routes the tool call to the handler function.case 'check_package_json': return await this.checkPackageJson(args);