wiki_get_page_tree
Retrieve hierarchical page tree from an Azure DevOps wiki, showing page structure and order.
Instructions
Retrieve hierarchical page structure from wiki
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organization | No | Azure DevOps organization name | |
| project | No | Project name | |
| wikiId | Yes | Wiki identifier | |
| depth | No | Optional maximum depth to retrieve |
Implementation Reference
- src/server.ts:243-264 (handler)Handler function that parses the request with WikiPageTreeRequestSchema, gets the client, calls client.getPageTree(), and returns the result as JSON.
private async handleGetPageTree(args: any) { const request = WikiPageTreeRequestSchema.parse(args); const organization = request.organization || this.config.defaultOrganization; const project = request.project || this.config.defaultProject; if (!organization) { throw new Error('Organization is required either as parameter or in server configuration'); } if (!project) { throw new Error('Project is required either as parameter or in server configuration'); } const client = await this.getClient(organization, project); const tree = await client.getPageTree(request); return { content: [{ type: 'text', text: JSON.stringify(tree, null, 2) }] }; } - src/types.ts:10-15 (schema)Zod schema for WikiPageTreeRequest: validates organization (optional), project (optional), wikiId (required), depth (optional positive integer).
export const WikiPageTreeRequestSchema = z.object({ organization: z.string().min(1).optional(), project: z.string().min(1).optional(), wikiId: z.string().min(1), depth: z.number().int().positive().optional(), }); - src/azure-client.ts:153-215 (helper)Client method getPageTree() that makes the actual REST API call to Azure DevOps Wiki pages endpoint, handles recursion level based on depth, processes the hierarchical page nodes, and returns WikiPageNode[].
async getPageTree(request: WikiPageTreeRequest): Promise<WikiPageNode[]> { if (!this.wikiApi || !this.connection) { throw new Error('Azure DevOps client not initialized'); } try { const organization = request.organization || this.config.organization; const project = request.project || this.config.project; if (!organization || !project) { throw new Error('Organization and project must be provided'); } const orgUrl = this.config.azureDevOpsUrl || `https://dev.azure.com/${organization}`; const recursionLevel = request.depth ? 'Full' : 'OneLevel'; const apiUrl = `${orgUrl}/${project}/_apis/wiki/wikis/${request.wikiId}/pages?recursionLevel=${recursionLevel}&api-version=7.1`; const response = await this.connection.rest.client.get(apiUrl); if (!response.message || response.message.statusCode !== 200) { return []; } const responseBody = await response.readBody(); if (!responseBody) { return []; } const data = JSON.parse(responseBody); let pages = []; if (data.value) { pages = data.value; } else if (data.subPages) { pages = [data]; } else { pages = [data]; } const processPages = (pageList: unknown[]): WikiPageNode[] => { return pageList.map((page: unknown) => { const pageData = page as { id?: number; path?: string; order?: number; gitItemPath?: string; subPages?: unknown[] }; return { id: pageData.id?.toString() || '', path: pageData.path || '', title: pageData.path ? pageData.path.split('/').pop() || '' : '', order: pageData.order || 0, gitItemPath: pageData.gitItemPath || '', subPages: pageData.subPages ? processPages(pageData.subPages) : [] }; }).sort((a, b) => a.order - b.order); }; return processPages(pages); } catch (error) { throw new Error(`Failed to get page tree: ${error instanceof Error ? error.message : String(error)}`); } } - src/server.ts:56-81 (registration)Tool registration in the ListToolsRequestSchema handler: defines name 'wiki_get_page_tree', description, and inputSchema for the tool.
{ name: 'wiki_get_page_tree', description: 'Retrieve hierarchical page structure from wiki', inputSchema: { type: 'object', properties: { organization: { type: 'string', description: 'Azure DevOps organization name' }, project: { type: 'string', description: 'Project name' }, wikiId: { type: 'string', description: 'Wiki identifier' }, depth: { type: 'number', description: 'Optional maximum depth to retrieve' } }, required: ['wikiId'] } }, - src/server.ts:167-168 (registration)Switch-case dispatch in CallToolRequestSchema handler that routes 'wiki_get_page_tree' to handleGetPageTree().
case 'wiki_get_page_tree': return await this.handleGetPageTree(args);