analyze_content
Analyze markdown files to automatically determine document categories based on content, enabling systematic organization and workflow management.
Instructions
Analyze markdown files to automatically determine document categories
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory_path | Yes | Path to directory containing markdown files |
Implementation Reference
- src/index.ts:1563-1614 (handler)Handler for the 'document_organizer__analyze_content' tool (matches 'analyze_content'). Parses input, recursively finds .md files if not specified, calls analyzeMarkdownContent on each, categorizes by content analysis, returns JSON with breakdown and details.
case "document_organizer__analyze_content": { const { directory_path, md_files } = AnalyzeContentArgsSchema.parse(args); let markdownFiles = md_files; if (!markdownFiles) { // Find all markdown files markdownFiles = []; async function findMdFiles(dir: string) { const items = await fs.readdir(dir, { withFileTypes: true }); for (const item of items) { const fullPath = path.join(dir, item.name); if (item.isFile() && path.extname(item.name).toLowerCase() === '.md') { markdownFiles!.push(fullPath); } else if (item.isDirectory()) { await findMdFiles(fullPath); } } } await findMdFiles(directory_path); } const analyses = []; for (const mdPath of markdownFiles) { const analysis = await analyzeMarkdownContent(mdPath); analyses.push({ file_path: mdPath, ...analysis }); } // Group by category const categorized = analyses.reduce((acc, analysis) => { if (!acc[analysis.category]) { acc[analysis.category] = []; } acc[analysis.category].push(analysis.file_path); return acc; }, {} as Record<string, string[]>); return { content: [ { type: "text", text: JSON.stringify({ total_files: analyses.length, categorized_breakdown: categorized, detailed_analysis: analyses }, null, 2) } ] }; } - src/index.ts:54-57 (schema)Zod schema defining input parameters for the analyze_content tool: directory_path (required) and optional md_files array.
const AnalyzeContentArgsSchema = z.object({ directory_path: z.string().describe("Path to directory containing markdown files"), md_files: z.array(z.string()).optional().describe("Specific MD files to analyze (if not provided, analyzes all)") }); - src/index.ts:1316-1319 (registration)Tool registration in the tools array, with name 'document_organizer__analyze_content', description, and inputSchema referencing AnalyzeContentArgsSchema.
name: "document_organizer__analyze_content", description: "📊 INTELLIGENT DOCUMENT CATEGORIZATION - Analyze markdown files to automatically determine document categories using keyword-based content analysis. Scans document content and classifies into categories: Research, Planning, Documentation, Technical, Business, or General. Returns category assignments with confidence scores and detected keywords for organizational decision making.", inputSchema: zodToJsonSchema(AnalyzeContentArgsSchema) as ToolInput, }, - src/index.ts:1229-1276 (helper)Helper function analyzeMarkdownContent that performs keyword-based categorization on individual markdown files, returning category, confidence score, and matched keywords. Used by the tool handler.
async function analyzeMarkdownContent(mdPath: string): Promise<{ category: string; confidence: number; keywords: string[] }> { try { const content = await fs.readFile(mdPath, 'utf-8'); const firstPart = content.slice(0, 2000).toLowerCase(); // Simple categorization based on content analysis const categories = { 'Research': ['analysis', 'research', 'study', 'investigation', 'findings', 'methodology'], 'Planning': ['plan', 'strategy', 'roadmap', 'timeline', 'goals', 'objectives', 'discussion'], 'Documentation': ['documentation', 'guide', 'manual', 'instructions', 'tutorial', 'reference'], 'Technical': ['technical', 'implementation', 'architecture', 'design', 'specification', 'api'], 'Business': ['business', 'market', 'competitive', 'revenue', 'commercial', 'strategy'] }; let bestCategory = 'General'; let bestScore = 0; const foundKeywords: string[] = []; for (const [category, keywords] of Object.entries(categories)) { let score = 0; for (const keyword of keywords) { if (firstPart.includes(keyword)) { score++; foundKeywords.push(keyword); } } if (score > bestScore) { bestScore = score; bestCategory = category; } } const confidence = Math.min(bestScore / 3, 1.0); // Normalize to 0-1 return { category: bestCategory, confidence, keywords: foundKeywords }; } catch (error) { return { category: 'General', confidence: 0, keywords: [] }; } }