wiki_get_page
Access the content of an Azure DevOps wiki page using its ID and path.
Instructions
Get content of a specific wiki page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organization | No | Azure DevOps organization name | |
| project | No | Project name | |
| wikiId | Yes | Wiki identifier | |
| path | Yes | Page path or page ID |
Implementation Reference
- src/azure-client.ts:217-282 (handler)The actual implementation of the getPage function that fetches wiki page content from the Azure DevOps REST API. It takes a WikiGetPageRequest, calls the Azure DevOps Wiki Pages API with the path and includeContent=true, parses the response, and returns a WikiPageContent object.
async getPage(request: WikiGetPageRequest): Promise<WikiPageContent> { 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 encodedPath = encodeURIComponent(request.path); const apiUrl = `${orgUrl}/${project}/_apis/wiki/wikis/${request.wikiId}/pages?path=${encodedPath}&includeContent=true&api-version=7.1`; const response = await this.connection.rest.client.get(apiUrl); if (!response.message || response.message.statusCode !== 200) { throw new Error(`Failed to get page: HTTP ${response.message?.statusCode || 'Unknown'}`); } const responseBody = await response.readBody(); if (!responseBody) { throw new Error('Empty response body'); } const data = JSON.parse(responseBody); // Handle the response structure let pageData; if (data.value) { // If value is an array, get the first element if (Array.isArray(data.value) && data.value.length > 0) { pageData = data.value[0]; } else if (Array.isArray(data.value) && data.value.length === 0) { // Empty array means page not found throw new Error(`Page not found: ${request.path}`); } else { // value is not an array, use it directly pageData = data.value; } } else { // No value property, use data directly pageData = data; } if (!pageData || pageData === null) { throw new Error(`Page not found: ${request.path}`); } return { id: pageData.id?.toString() || '', path: pageData.path || request.path, title: pageData.path ? pageData.path.split('/').pop() || '' : '', content: pageData.content || '', gitItemPath: pageData.gitItemPath || '', order: pageData.order || 0, version: pageData.version || '', isParentPage: pageData.isParentPage || false }; } catch (error) { throw new Error(`Failed to get page: ${error instanceof Error ? error.message : String(error)}`); } } - src/server.ts:266-287 (handler)The handleGetPage method in the server class that parses the request args using WikiGetPageRequestSchema, gets the client, calls client.getPage(request), and returns the result as JSON.
private async handleGetPage(args: any) { const request = WikiGetPageRequestSchema.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 page = await client.getPage(request); return { content: [{ type: 'text', text: JSON.stringify(page, null, 2) }] }; } - src/types.ts:17-22 (schema)The Zod schema WikiGetPageRequestSchema defining validation for the input: organization (optional), project (optional), wikiId (required), path (required).
export const WikiGetPageRequestSchema = z.object({ organization: z.string().min(1).optional(), project: z.string().min(1).optional(), wikiId: z.string().min(1), path: z.string().min(1), }); - src/types.ts:61-70 (schema)The WikiPageContent interface defining the output type for the getPage operation: id, path, title, content, gitItemPath, order, version, isParentPage.
export interface WikiPageContent { id: string; path: string; title: string; content: string; gitItemPath: string; order: number; version: string; isParentPage: boolean; } - src/server.ts:82-170 (registration)Registration of the 'wiki_get_page' tool in the ListToolsRequestSchema handler with its name, description, and input schema (organization, project, wikiId, path). Also dispatched in the CallToolRequestSchema switch statement at line 169.
{ name: 'wiki_get_page', description: 'Get content of a specific wiki page', inputSchema: { type: 'object', properties: { organization: { type: 'string', description: 'Azure DevOps organization name' }, project: { type: 'string', description: 'Project name' }, wikiId: { type: 'string', description: 'Wiki identifier' }, path: { type: 'string', description: 'Page path or page ID' } }, required: ['wikiId', 'path'] } }, { name: 'wiki_update_page', description: 'Update content of an existing wiki page or create a new page if it does not exist', inputSchema: { type: 'object', properties: { organization: { type: 'string', description: 'Azure DevOps organization name' }, project: { type: 'string', description: 'Project name' }, wikiId: { type: 'string', description: 'Wiki identifier' }, path: { type: 'string', description: 'Page path or page ID' }, content: { type: 'string', description: 'New page content (Markdown)' } }, required: ['wikiId', 'path', 'content'] } }, { name: 'list_wiki', description: 'List all wikis in a project', inputSchema: { type: 'object', properties: { organization: { type: 'string', description: 'Azure DevOps organization name' }, project: { type: 'string', description: 'Project name' } }, required: [] } } ] as Tool[] }; }); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'search_wiki': return await this.handleSearchWiki(args); case 'wiki_get_page_tree': return await this.handleGetPageTree(args); case 'wiki_get_page': return await this.handleGetPage(args);