analyze_content
Parse and evaluate the structure of HTML files to identify elements, hierarchy, and layout. Use this tool to extract meaningful insights from local HTML content for debugging or analysis.
Instructions
Analyze HTML content structure
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to local HTML file |
Implementation Reference
- src/index.ts:127-140 (handler)Core handler function in FilePreviewWrapper that reads the HTML file and uses regex to count structural elements: headings (h1-h6), paragraphs, images, and links.async analyzeContent(filePath: string) { if (!fs.existsSync(filePath)) { throw new McpError(ErrorCode.InvalidRequest, `File not found: ${filePath}`); } const content = fs.readFileSync(filePath, 'utf-8'); return { headings: (content.match(/<h[1-6][^>]*>.*?<\/h[1-6]>/g) || []).length, paragraphs: (content.match(/<p[^>]*>.*?<\/p>/g) || []).length, images: (content.match(/<img[^>]*>/g) || []).length, links: (content.match(/<a[^>]*>.*?<\/a>/g) || []).length, }; }
- src/index.ts:34-44 (schema)Tool object definition including name, description, and input schema specifying the required 'filePath' parameter.const analyzeContentTool: Tool = { name: 'analyze_content', description: 'Analyze HTML content structure', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to local HTML file' } }, required: ['filePath'] } };
- src/index.ts:166-169 (registration)Registration of the analyze_content tool (along with preview_file) in the server's capabilities for tools.tools: { preview_file: previewFileTool, analyze_content: analyzeContentTool }
- src/index.ts:241-243 (registration)Tool listing handler that returns the registered tools including analyze_content.return { tools: [previewFileTool, analyzeContentTool], };
- src/index.ts:202-216 (helper)Dispatch handler in CallToolRequestSchema that validates input, calls the analyzeContent method, and formats the response as JSON text.case "analyze_content": { const args = request.params.arguments as { filePath: string }; if (!args.filePath) { throw new Error("Missing required argument: filePath"); } const analysis = await filePreview.analyzeContent(args.filePath); return { content: [ { type: "text", text: JSON.stringify(analysis, null, 2) } ], }; }