52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
from pathlib import Path
|
|
|
|
from fastmcp import FastMCP
|
|
|
|
|
|
ROOT_DIR = Path(__file__).resolve().parent
|
|
UPLOAD_DIR = ROOT_DIR / "uploads"
|
|
UPLOAD_DIR.mkdir(exist_ok=True)
|
|
|
|
|
|
mcp = FastMCP("FilePersistenceSTDIO")
|
|
|
|
|
|
@mcp.tool
|
|
def health() -> dict:
|
|
"""Return basic server health information."""
|
|
return {
|
|
"status": "ok",
|
|
"server": "FilePersistenceSTDIO",
|
|
"transport": "stdio",
|
|
"uploads_dir": str(UPLOAD_DIR),
|
|
}
|
|
|
|
|
|
@mcp.tool
|
|
def list_uploaded_files() -> dict:
|
|
"""List files currently stored in the uploads directory."""
|
|
files = sorted(path.name for path in UPLOAD_DIR.iterdir() if path.is_file())
|
|
return {
|
|
"count": len(files),
|
|
"files": files,
|
|
}
|
|
|
|
|
|
@mcp.tool
|
|
def file_info(filename: str) -> dict:
|
|
"""Return metadata for one uploaded file."""
|
|
path = (UPLOAD_DIR / filename).resolve()
|
|
if path.parent != UPLOAD_DIR.resolve() or not path.exists() or not path.is_file():
|
|
raise FileNotFoundError(f"File not found: {filename}")
|
|
|
|
stat = path.stat()
|
|
return {
|
|
"filename": path.name,
|
|
"size_bytes": stat.st_size,
|
|
"absolute_path": str(path),
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mcp.run(transport="stdio")
|