Skip to main content
Glama

get_doc

Retrieve specified document content with pagination support by providing the file path and optional page number for partial extraction.

Instructions

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

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNo
pathYes

Implementation Reference

  • MCP tool handler and registration for 'get_doc'. Thin wrapper that calls DocumentManager.get_document(path, page). Schema defined by function signature and docstring.
    @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)
  • Core helper method implementing document retrieval with character-based pagination, error handling, and metadata headers. Directly invoked by the get_doc tool handler.
    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
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pagination support ('ページネーション対応'), which is useful context beyond the input schema, and clarifies that page=None retrieves the full text. However, it lacks details on permissions, rate limits, error handling, or response format, leaving gaps for a read operation tool.

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 appropriately sized and front-loaded: the first sentence states the purpose and key feature (pagination), followed by a clear Args section. Every sentence adds value, with no redundant information. It could be slightly more structured by separating usage notes from parameter explanations, but it remains efficient.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, read operation), no annotations, and no output schema, the description is partially complete. It covers the basic purpose and parameters adequately but lacks details on behavioral aspects like response format, error cases, or integration with siblings. For a tool without structured output, more context on what is returned would be beneficial.

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?

The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'path' is the document's file path and 'page' is the page number starting from 1, with None meaning full-text retrieval. This compensates well for the schema's lack of descriptions, though it doesn't cover all potential nuances like path format or pagination details.

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

Purpose4/5

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

The description clearly states the tool's purpose: '指定したドキュメントの内容を取得' (retrieve content of specified document). It specifies the verb (取得/get) and resource (ドキュメント/document), though it doesn't explicitly differentiate from sibling tools like grep_docs or list_docs. The mention of pagination support adds specificity but not sibling differentiation.

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

Usage Guidelines3/5

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

The description implies usage context through the pagination note and parameter explanations, suggesting this tool is for retrieving document content with optional pagination. However, it doesn't explicitly state when to use this tool versus alternatives like grep_docs (likely for searching) or list_docs (likely for listing), nor does it mention any prerequisites 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

Related 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