update-page
Modify wiki pages by replacing existing content with updated text. Requires a page title, new source content, and a base revision ID for accurate updates.
Instructions
Updates a wiki page. Replaces the existing content of a page with the provided content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comment | No | Summary of the edit | |
| latestId | Yes | Identifier for the revision used as the base for the new source | |
| source | Yes | Page content in the same content model of the existing page | |
| title | Yes | Wiki page title |
Implementation Reference
- src/tools/update-page.ts:9-28 (registration)Registers the 'update-page' tool (includes schema and handler reference) with the MCP server using server.tool().export function updatePageTool( server: McpServer ): RegisteredTool { return server.tool( 'update-page', 'Updates a wiki page. Replaces the existing content of a page with the provided content', { title: z.string().describe( 'Wiki page title' ), source: z.string().describe( 'Page content in the same content model of the existing page' ), latestId: z.number().int().positive().describe( 'Revision ID used as the base for the new source' ), comment: z.string().optional().describe( 'Summary of the edit' ) }, { title: 'Update page', readOnlyHint: false, destructiveHint: true } as ToolAnnotations, async ( { title, source, latestId, comment } ) => handleUpdatePageTool( title, source, latestId, comment ) ); }
- src/tools/update-page.ts:30-55 (handler)The core handler logic that performs the REST PUT request to update the wiki page, handles errors, and returns success or error results.async function handleUpdatePageTool( title: string, source: string, latestId: number, comment?: string ): Promise<CallToolResult> { let data: MwRestApiPageObject; try { data = await makeRestPutRequest<MwRestApiPageObject>( `/v1/page/${ encodeURIComponent( title ) }`, { source: source, comment: formatEditComment( 'update-page', comment ), latest: { id: latestId } }, true ); } catch ( error ) { return { content: [ { type: 'text', text: `Failed to update page: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } return { content: updatePageToolResult( data ) }; }
- src/tools/update-page.ts:57-77 (helper)Helper function to format the API response into user-friendly text content blocks.function updatePageToolResult( result: MwRestApiPageObject ): TextContent[] { return [ { type: 'text', text: `Page updated successfully: ${ getPageUrl( result.title ) }` }, { type: 'text', text: [ 'Page object:', `Page ID: ${ result.id }`, `Title: ${ result.title }`, `Latest revision ID: ${ result.latest.id }`, `Latest revision timestamp: ${ result.latest.timestamp }`, `Content model: ${ result.content_model }`, `License: ${ result.license.url } ${ result.license.title }`, `HTML URL: ${ result.html_url }` ].join( '\n' ) } ]; }
- src/tools/index.ts:41-51 (registration)Top-level function that registers all tools, including updatePageTool via its inclusion in toolRegistrars array (lines 22-39). Note: import at line 11.export function registerAllTools( server: McpServer ): RegisteredTool[] { const registeredTools: RegisteredTool[] = []; for ( const registrar of toolRegistrars ) { try { registeredTools.push( registrar( server ) ); } catch ( error ) { console.error( `Error registering tool: ${ ( error as Error ).message }` ); } } return registeredTools; }