get-page
Retrieve MediaWiki page content, metadata, or revision IDs for editing workflows using the mediawiki-mcp-server.
Instructions
Returns a wiki page. Use metadata=true to retrieve the revision ID required by update-page. Set content="none" to fetch only metadata without content.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Wiki page title | |
| content | No | Type of content to return | source |
| metadata | No | Whether to include metadata (page ID, revision info, license) in the response |
Implementation Reference
- src/tools/get-page.ts:28-56 (handler)Core handler function that performs the REST API call to fetch the wiki page, processes based on content and metadata parameters, and returns success or error response.async function handleGetPageTool( title: string, content: ContentFormat, metadata: boolean ): Promise<CallToolResult> { if ( content === ContentFormat.none && !metadata ) { return { content: [ { type: 'text', text: 'When content is set to "none", metadata must be true' } ], isError: true }; } try { const data = await makeRestGetRequest<MwRestApiPageObject>( `/v1/page/${ encodeURIComponent( title ) }${ getSubEndpoint( content ) }` ); return { content: getPageToolResult( data, content, metadata ) }; } catch ( error ) { return { content: [ { type: 'text', text: `Failed to retrieve page data: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } }
- src/tools/get-page.ts:10-26 (registration)Registers the 'get-page' tool with the MCP server, specifying name, description, Zod input schema, annotations, and async handler.export function getPageTool( server: McpServer ): RegisteredTool { return server.tool( 'get-page', 'Returns a wiki page. Use metadata=true to retrieve the revision ID required by update-page. Set content="none" to fetch only metadata without content.', { title: z.string().describe( 'Wiki page title' ), content: z.nativeEnum( ContentFormat ).optional().default( ContentFormat.source ).describe( 'Type of content to return' ), metadata: z.boolean().optional().default( false ).describe( 'Whether to include metadata (page ID, revision info, license) in the response' ) }, { title: 'Get page', readOnlyHint: true, destructiveHint: false } as ToolAnnotations, async ( { title, content, metadata } ) => handleGetPageTool( title, content, metadata ) ); }
- src/tools/get-page.ts:58-92 (helper)Helper function to construct the TextContent array for the tool response, handling different content formats and metadata.function getPageToolResult( result: MwRestApiPageObject, content: ContentFormat, metadata: boolean ): TextContent[] { if ( content === ContentFormat.source && !metadata ) { return [ { type: 'text', text: result.source ?? 'Not available' } ]; } if ( content === ContentFormat.html && !metadata ) { return [ { type: 'text', text: result.html ?? 'Not available' } ]; } const results: TextContent[] = [ getPageMetadataTextContent( result ) ]; if ( result.source !== undefined ) { results.push( { type: 'text', text: `Source:\n${ result.source }` } ); } if ( result.html !== undefined ) { results.push( { type: 'text', text: `HTML:\n${ result.html }` } ); } return results; }
- src/tools/get-page.ts:94-107 (helper)Helper function to format page metadata into a single TextContent block.function getPageMetadataTextContent( result: MwRestApiPageObject ): TextContent { return { type: 'text', text: [ `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 ?? 'Not available' }` ].join( '\n' ) }; }
- src/tools/index.ts:22-39 (registration)Array collecting all tool registrar functions, including getPageTool, used by registerAllTools for server-wide tool registration.const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool, searchPageByPrefixTool ];