#!/usr/bin/env python3
"""
minimal_mcp_server.py — Custom FastMCP Server Starter
Template from นักสืบอัลกอริทึม (Code Detective)
Run with: python3 minimal_mcp_server.py
"""

import os
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP Server
mcp = FastMCP("code-detective-agent-tools")

@mcp.tool()
def inspect_code_health(filepath: str) -> dict:
    """Analyze file size, line count, and estimate token cost for LLM."""
    if not os.path.exists(filepath):
        return {"error": f"File not found: {filepath}"}
    
    with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
        lines = f.readlines()
    
    char_count = sum(len(line) for line in lines)
    est_tokens = char_count // 4
    
    return {
        "status": "success",
        "filepath": filepath,
        "total_lines": len(lines),
        "total_characters": char_count,
        "estimated_tokens": est_tokens,
        "recommendation": "Lean & Clean" if est_tokens < 2000 else "Needs Chunking or Slicing"
    }

if __name__ == "__main__":
    mcp.run()
