Skip to main content
Glama
penguinszp001

mcp-server-demo

inspect_file

Retrieve file metadata and content previews for text, CSV, or image files to support workflow decisions.

Instructions

Return file metadata and content preview for text/csv/image workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
preview_charsNo
include_base64No

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'inspect_file' MCP tool handler function. It resolves the file path, reads file metadata (name, size, MIME type), provides text preview for text files (up to preview_chars), notes for images, and optionally includes base64-encoded content. Returns the result as a JSON string.
    @mcp.tool()
    def inspect_file(path: str, preview_chars: int = 4000, include_base64: bool = False) -> str:
        """Return file metadata and content preview for text/csv/image workflows."""
        target = _resolve_file_ops_path(path)
        if not target.is_file():
            raise ValueError(f"File does not exist: {target}")
    
        mime_type, _ = mimetypes.guess_type(str(target))
        if not mime_type:
            mime_type = "application/octet-stream"
    
        raw = target.read_bytes()
        result: dict[str, Any] = {
            "path": str(target),
            "name": target.name,
            "size_bytes": len(raw),
            "mime_type": mime_type,
        }
    
        if mime_type.startswith("text/") or mime_type in {"application/json", "text/csv"}:
            text = raw.decode("utf-8", errors="replace")
            result["text_preview"] = text[:preview_chars]
            result["text_preview_truncated"] = len(text) > preview_chars
        elif mime_type.startswith("image/"):
            result["image_note"] = "Use analyze_image_with_openai for model vision interpretation."
    
        if include_base64:
            result["base64"] = base64.b64encode(raw).decode("ascii")
    
        return json.dumps(result, indent=2)
  • server.py:201-201 (registration)
    Registration of inspect_file as an MCP tool via the @mcp.tool() decorator.
    @mcp.tool()
  • Helper function _resolve_file_ops_path used by inspect_file to validate and resolve file paths within MCP_FILE_OPS_ROOT, preventing path traversal escapes.
    def _resolve_file_ops_path(path: str | None = None) -> Path:
        if not FILE_OPS_ROOT:
            raise ValueError("MCP_FILE_OPS_ROOT is not configured in .env.")
    
        root = Path(FILE_OPS_ROOT).expanduser().resolve()
        root.mkdir(parents=True, exist_ok=True)
    
        target = root if path is None else (root / path).resolve()
        if target != root and root not in target.parents:
            raise ValueError("Path escapes the configured MCP_FILE_OPS_ROOT.")
        return target
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description bears full responsibility for behavioral disclosure. It omits details about metadata fields, preview truncation, handling of non-text files, or effects of parameters like include_base64. The behavioral traits are insufficiently transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence, but it sacrifices essential detail about parameters and behavioral context. It is neither verbose nor well-structured for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters and no annotations, the description is largely incomplete. It fails to convey how the tool works in various workflows (e.g., image vs. csv), what metadata is returned, or how preview_chars affects output. The presence of an output schema does not excuse the lack of high-level context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description does not explain any parameter's meaning beyond the schema. Terms like path, preview_chars, and include_base64 are left undefined, forcing reliance on parameter names alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'return', the resource 'file metadata and content preview', and the context 'for text/csv/image workflows'. It effectively distinguishes from sibling tools like read_file (full content) and list_files (names).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use inspect_file versus alternatives such as read_file or analyze_image_with_openai. There are no examples or exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/penguinszp001/mcp-server-demo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server