wiki_get_page_tree
Retrieves the hierarchical page structure from an Azure DevOps wiki, enabling users to navigate and manage content by specifying organization, project, wiki ID, and optional depth.
Instructions
Retrieve hierarchical page structure from wiki
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| depth | No | Optional maximum depth to retrieve | |
| organization | No | Azure DevOps organization name | |
| project | No | Project name | |
| wikiId | Yes | Wiki identifier |
Input Schema (JSON Schema)
{
"properties": {
"depth": {
"description": "Optional maximum depth to retrieve",
"type": "number"
},
"organization": {
"description": "Azure DevOps organization name",
"type": "string"
},
"project": {
"description": "Project name",
"type": "string"
},
"wikiId": {
"description": "Wiki identifier",
"type": "string"
}
},
"required": [
"wikiId"
],
"type": "object"
}
Implementation Reference
- src/azure-client.ts:153-215 (handler)Core handler function that executes the wiki_get_page_tree tool logic by calling the Azure DevOps Wiki API to retrieve the hierarchical page structure and processing it into a tree of WikiPageNode objects.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/types.ts:10-15 (schema)Zod input schema validation for the wiki_get_page_tree tool parameters.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/server.ts:56-81 (registration)MCP tool registration including name, description, and input schema definition.{ 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:243-264 (handler)MCP server handler wrapper that parses arguments, initializes client if needed, calls the core getPageTree method, and formats response.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/server.ts:167-168 (registration)Tool dispatch/registration in the CallToolRequestSchema switch statement.case 'wiki_get_page_tree': return await this.handleGetPageTree(args);