auditPackage
Perform comprehensive security audits of frontend project dependencies to detect vulnerabilities and generate detailed Markdown reports with risk assessments and fix recommendations.
Instructions
审计前端工程的所有直接和间接依赖,得到安全审计结果。支持本地工程的审计,也支持远程仓库的审计。审计结果为标准格式的markdown字符串,不用修改,直接用于展示即可。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectRoot | Yes | 本地工程的根路径,或者远程仓库的URL地址 | |
| savePath | Yes | 保存审计结果的路径,传递当前工程的根路径下的工程明audit.md,如果没有当前工程,则传递桌面路径下的audit.md(注意,桌面路径必须传入绝对路径) |
Implementation Reference
- src/mcpServer.js:12-40 (registration)Full registration of the 'auditPackage' MCP tool, including name, title, description, input schema, and inline handler function that delegates to the core auditPackage logic.server.registerTool( 'auditPackage', { title: '审计前端工程', description: '审计前端工程的所有直接和间接依赖,得到安全审计结果。支持本地工程的审计,也支持远程仓库的审计。审计结果为标准格式的markdown字符串,不用修改,直接用于展示即可。', inputSchema: { projectRoot: z .string() .describe('本地工程的根路径,或者远程仓库的URL地址'), savePath: z .string() .describe( '保存审计结果的路径,传递当前工程的根路径下的工程明audit.md,如果没有当前工程,则传递桌面路径下的audit.md(注意,桌面路径必须传入绝对路径)' ), }, }, async ({ projectRoot, savePath }) => { await auditPackage(projectRoot, savePath); return { content: [ { type: 'text', text: `审计完成,结果已保存到: ${savePath}`, }, ], }; } );
- src/mcpServer.js:29-39 (handler)Inline handler for the MCP 'auditPackage' tool: invokes the core auditPackage function and returns a markdown content response indicating completion.async ({ projectRoot, savePath }) => { await auditPackage(projectRoot, savePath); return { content: [ { type: 'text', text: `审计完成,结果已保存到: ${savePath}`, }, ], }; }
- src/entry/index.js:13-28 (helper)Core orchestrator function for auditing a package: manages temporary work directory, project parsing, lockfile generation, auditing, rendering, cleanup, and result saving.export async function auditPackage(projectRoot, savePath) { // 1. 创建工作目录 const workDir = await createWorkDir(); // 2. 解析项目,向工作目录添加pacakge.json const packageJson = await parseProject(projectRoot); // 3. 生成lock文件 await generateLock(workDir, packageJson); // 4. 对工作目录进行审计 const auditResult = await audit(workDir, packageJson); // 5. 渲染审计结果 const renderedResult = await render(auditResult, packageJson); // 6. 删除工作目录 await deleteWorkDir(workDir); // 7. 将结果保存到指定路径 await fs.promises.writeFile(savePath, renderedResult); }
- src/mcpServer.js:18-27 (schema)Zod-based input schema definition for the 'auditPackage' tool parameters: projectRoot (local path or remote URL) and savePath (output file path).inputSchema: { projectRoot: z .string() .describe('本地工程的根路径,或者远程仓库的URL地址'), savePath: z .string() .describe( '保存审计结果的路径,传递当前工程的根路径下的工程明audit.md,如果没有当前工程,则传递桌面路径下的audit.md(注意,桌面路径必须传入绝对路径)' ), },