Skip to main content
Glama
tizee
by tizee

get_ietf_doc

Retrieve IETF RFC documents by number with pagination support, specifying start line and maximum lines to return. Access document content and metadata directly.

Instructions

Get an RFC document by its number in RFC editor Index with pagination support Args: number: The RFC number str (e.g., "1234") start_line: The line number to start from (default: 1) max_lines: Maximum number of lines to return (default: 200) Returns: A dictionary containing the document content and metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_linesNo
numberYes
start_lineNo

Implementation Reference

  • The main async handler function implementing the logic for the 'get_ietf_doc' MCP tool. It retrieves the server context, calls the get_rfc_document helper with parameters, logs the result, and returns the document data.
    async def get_ietf_doc( ctx: Context, number: int, start_line: int = 1, max_lines: int = DEFAULT_MAX_LINES, ) -> Dict[str, Any]: """ Get an RFC document by its number in RFC editor Index with pagination support Args: number: The RFC number str (e.g., "1234") start_line: The line number to start from (default: 1) max_lines: Maximum number of lines to return (default: 200) Returns: A dictionary containing the document content and metadata """ server_ctx = ctx.request_context.lifespan_context data = get_rfc_document(str(number), start_line, max_lines, CACHE_DIR, server_ctx) logger.debug(f"get_doc: {data}") return data
  • Registers the get_ietf_doc function as a tool on the FastMCP server instance.
    @mcp.tool()
  • Core helper function that implements the document retrieval logic: input validation, index lookup, download/caching, pagination, metadata extraction including page info, and structured output.
    def get_rfc_document( rfc_number: str, start_line: int = 1, max_lines: int = 200, cache_dir: str = CACHE_DIR, index_data: Optional[RFCIndexData] = None ) -> Dict[str, Any]: """ Get an RFC document by its number with pagination support Args: rfc_number: The RFC number (e.g., "1234") start_line: The line number to start from (default: 1) max_lines: Maximum number of lines to return (default: 200) cache_dir: Directory to store cached files index_data: Optional pre-loaded index data Returns: A dictionary containing the document content and metadata """ # Validate input if not rfc_number.isdigit(): return {"error": "RFC number must be a number"} if start_line < 1: return {"error": "start_line must be 1 or greater"} if max_lines < 1: return {"error": "max_lines must be 1 or greater"} # Get index data if not provided if index_data is None: index_path = download_rfc_index(cache_dir) index_data = parse_rfc_index(index_path) # Check if RFC exists in our index if rfc_number not in index_data.rfc_titles: return {"error": f"RFC {rfc_number} not found in index"} # Download RFC if needed try: doc_path = download_rfc(rfc_number, cache_dir) except Exception as e: return {"error": str(e)} # Read and paginate the document with open(doc_path, "r", encoding="utf-8") as f: all_lines = f.readlines() total_lines = len(all_lines) # Validate start_line if start_line > total_lines: return {"error": f"start_line ({start_line}) exceeds document length ({total_lines})"} # Calculate pagination end_line = min(start_line + max_lines - 1, total_lines) paginated_lines = all_lines[start_line-1:end_line] paginated_content = ''.join(paginated_lines) # Check if truncated truncated = end_line < total_lines # Extract page numbers if available by scanning the content page_info = extract_page_info(paginated_content) # Basic metadata title = index_data.rfc_titles.get(rfc_number, "Unknown title") return { "content": paginated_content, "title": title, "path": doc_path, "start_line": start_line, "end_line": end_line, "max_lines": max_lines, "total_lines": total_lines, "truncated": truncated, "truncated_at_line": end_line if truncated else None, "page_info": page_info, "next_chunk_start": end_line + 1 if truncated else None }
  • Dataclass defining the structure for RFC index data, used by get_rfc_document to check RFC existence and retrieve titles.
    @dataclass class RFCIndexData: """Data structure for RFC index information""" index_path: str docs_count: int rfc_titles: Dict[str, str] # Map of RFC number to title

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/tizee/mcp-server-ietf'

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