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
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