Skip to main content
Glama

get_doc

Retrieve document content from a specified path, with pagination support to fetch a specific page or the entire document.

Instructions

指定したドキュメントの内容を取得(ページネーション対応)

Args:
    path: ドキュメントのファイルパス
    page: ページ番号(1から開始、Noneの場合は全文取得)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
pageNo

Implementation Reference

  • The MCP tool handler for 'get_doc'. Defined as an async FastMCP tool with @mcp.tool() decorator. Takes 'path' (str) and optional 'page' (int) parameters. Delegates to DocumentManager.get_document().
    @mcp.tool()
    async def get_doc(path: str, page: int | None = None) -> str:
        """指定したドキュメントの内容を取得(ページネーション対応)
    
        Args:
            path: ドキュメントのファイルパス
            page: ページ番号(1から開始、Noneの場合は全文取得)
        """
        return doc_manager.get_document(path, page)
  • The core implementation of get_document logic in DocumentManager. Handles document lookup, pagination (character-count-based), metadata header generation, and error handling for missing documents or invalid page numbers.
    def get_document(self, path: str, page: int | None = None) -> str:
        """指定されたドキュメントの内容を返す(文字数ベースページネーション対応)
    
        Args:
            path: ドキュメントのファイルパス
            page: ページ番号(1から開始、Noneの場合は自動判定)
        """
        if path not in self.docs_content:
            return f"Error: Document not found: {path}"
    
        content = self.docs_content[path]
        total_chars = len(content)
    
        # ページ指定がない場合(従来の動作)
        if page is None:
            # 大きなファイルには自動的に1ページ目を返す
            if total_chars > self.large_file_threshold:
                # 1ページ目として処理
                page = 1
            else:
                # 小さなファイルは従来通り全文を返す
                return content
    
        # ページネーション処理(文字数ベース)
        total_pages = (
            total_chars + self.max_chars_per_page - 1
        ) // self.max_chars_per_page
    
        # エラーハンドリング
        if page < 1:
            return "Error: Page number must be 1 or greater"
        if page > total_pages:
            return f"Error: Page {page} not found. Total pages: {total_pages} (max chars per page: {self.max_chars_per_page:,})"
    
        # ページ範囲計算(文字数ベース、行を分割しないよう調整)
        start_char = (page - 1) * self.max_chars_per_page
        end_char = min(start_char + self.max_chars_per_page, total_chars)
    
        # 行の途中で切れないよう調整
        if end_char < total_chars:
            # 次の改行文字まで含める
            next_newline = content.find("\n", end_char)
            if next_newline != -1:
                end_char = next_newline + 1
    
        page_content = content[start_char:end_char]
    
        # 行数カウント(表示用)
        lines_before_start = content[:start_char].count("\n")
        page_lines = page_content.count("\n")
        total_lines = content.count("\n") + 1
        start_line = lines_before_start + 1
        end_line = min(start_line + page_lines, total_lines)
    
        # メタデータヘッダー
        header = f"📄 Document: {path}\n"
        header += f"📖 Page {page}/{total_pages} (chars {start_char + 1:,}-{end_char:,}/{total_chars:,})\n"
        header += f"📏 Lines {start_line}-{end_line}/{total_lines:,} | Max chars per page: {self.max_chars_per_page:,}\n"
    
        # 大きなファイルで自動的にページ1を表示した場合は使い方を追加
        if page == 1 and total_chars > self.large_file_threshold:
            header += "⚠️  Large document auto-paginated. To see other pages:\n"
            header += f"💡 get_doc('{path}', page=2)  # Next page\n"
            header += f"💡 get_doc('{path}', page={total_pages})  # Last page\n"
    
        header += "─" * 60 + "\n\n"
    
        return header + page_content
  • Tool registration via the @mcp.tool() decorator on the 'get_doc' async function. FastMCP automatically registers any function decorated with @mcp.tool() as an MCP tool.
    @mcp.tool()
    async def get_doc(path: str, page: int | None = None) -> str:
  • Input schema for the 'get_doc' tool. Parameters: 'path' (str, required) and 'page' (int | None, optional). The docstring serves as the description/schema for the MCP tool.
    async def get_doc(path: str, page: int | None = None) -> str:
        """指定したドキュメントの内容を取得(ページネーション対応)
    
        Args:
            path: ドキュメントのファイルパス
            page: ページ番号(1から開始、Noneの場合は全文取得)
        """
Behavior4/5

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

No annotations are provided, so the description carries the burden. It explains pagination behavior (page number starting at 1, None for full content), adding value beyond the schema. However, it does not mention other traits like permissions or rate limits, but for a simple read tool, this is sufficient.

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

Conciseness4/5

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

The description is concise with two brief lines for parameters. It is front-loaded with the main purpose and then key parameter details. Could be slightly more structured, but no extraneous content.

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

Completeness4/5

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

Given the tool's simplicity (2 parameters, no output schema), the description covers the main behavior (reading content with pagination). It could mention the return format, but overall it is adequate for an agent to invoke correctly.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates by explaining the 'path' parameter as file path and 'page' as page number with special handling for None. This adds meaning beyond the schema's minimal type information.

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 tool retrieves document content with pagination support, using a specific verb ('get') and resource ('document content'). This distinguishes it from siblings like grep_docs, list_docs, and semantic_search.

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?

The description provides no guidance on when to use this tool versus alternatives (e.g., grep_docs, semantic_search). It only mentions pagination but does not specify contexts or exclusions.

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/herring101/docs-mcp'

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