list_sections
List pages from the documentation tree. Retrieve root pages or immediate children of a specified parent page.
Instructions
List pages in the documentation tree.
Args: parent_id: If omitted, returns root pages of the OF space. Otherwise returns immediate children of the given page id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parent_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/of_mcp/server.py:104-120 (handler)The actual 'list_sections' tool handler — decorated with @mcp.tool(). It uses db.list_root_pages() or db.list_children() based on whether parent_id is provided, then formats results as a flat Markdown bullet list.
@mcp.tool() def list_sections(parent_id: str | None = None) -> str: """List pages in the documentation tree. Args: parent_id: If omitted, returns root pages of the OF space. Otherwise returns immediate children of the given page id. """ with closing(_conn()) as conn: rows = db.list_root_pages(conn) if not parent_id else db.list_children(conn, parent_id) if not rows: if parent_id: return f"No children for page {parent_id}." return f"Index is empty. Run `of-mcp-crawl` first. Status: {_index_status()}" lines = [f"- {r['title']} (id={r['id']}) {r['url']}" for r in rows] header = "Root pages:" if not parent_id else f"Children of {parent_id}:" return header + "\n" + "\n".join(lines) - src/of_mcp/db.py:194-200 (helper)Helper function list_root_pages: queries pages where parent_id IS NULL or empty, ordered by title. Used by list_sections when parent_id is None.
def list_root_pages(conn: sqlite3.Connection) -> list[sqlite3.Row]: return list( conn.execute( "SELECT id, title, url FROM pages WHERE parent_id IS NULL OR parent_id = ''" " ORDER BY title" ).fetchall() ) - src/of_mcp/db.py:203-209 (helper)Helper function list_children: queries immediate children of a given parent_id, ordered by title. Used by list_sections when parent_id is provided.
def list_children(conn: sqlite3.Connection, parent_id: str) -> list[sqlite3.Row]: return list( conn.execute( "SELECT id, title, url FROM pages WHERE parent_id = ? ORDER BY title", (parent_id,), ).fetchall() ) - src/of_mcp/server.py:34-34 (registration)The FastMCP server instance 'mcp' is created here. The @mcp.tool() decorator on list_sections registers it automatically with the MCP framework.
mcp = FastMCP("of-mcp")