Skip to main content
Glama

update-page

Update MediaWiki page content by replacing existing text with new source material using revision IDs to maintain edit history.

Instructions

Updates a wiki page. Replaces the existing content of a page with the provided content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesWiki page title
sourceYesPage content in the same content model of the existing page
latestIdYesRevision ID used as the base for the new source
commentNoSummary of the edit

Implementation Reference

  • The handler function that executes the tool logic: makes a REST PUT request to update the wiki page with new source, using the provided latest revision ID as base, handles errors, and returns formatted result.
    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 ) }; }
  • Registers the 'update-page' tool with the MCP server, defines input schema using Zod, tool annotations, and links to the handler function.
    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 ) ); }
  • Helper function to format the successful update result into TextContent array with page details.
    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' ) } ]; }
  • Top-level registration: includes updatePageTool in the list of registrars and calls them all to register tools with the MCP server.
    const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool, searchPageByPrefixTool ]; 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ProfessionalWiki/MediaWiki-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server