Skip to main content
Glama
ProfessionalWiki

mediawiki-mcp-server

get-file

Retrieve file information and download links from MediaWiki, including thumbnail, preview, and original formats, by providing the file title.

Instructions

Returns information about a file, including links to download the file in thumbnail, preview, and original formats.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesFile title

Implementation Reference

  • The handler function that executes the get-file tool logic: fetches file information via REST API using the provided title, handles errors, and formats the response.
    async function handleGetFileTool( title: string ): Promise< CallToolResult > {
    	let data: MwRestApiFileObject;
    	try {
    		data = await makeRestGetRequest<MwRestApiFileObject>( `/v1/file/${ encodeURIComponent( title ) }` );
    	} catch ( error ) {
    		return {
    			content: [
    				{ type: 'text', text: `Failed to retrieve file data: ${ ( error as Error ).message }` } as TextContent
    			],
    			isError: true
    		};
    	}
    
    	return {
    		content: getFileToolResult( data )
    	};
    }
  • Registers the 'get-file' tool with the MCP server, including name, description, input schema (title: string), annotations, and references the handler function.
    export function getFileTool( server: McpServer ): RegisteredTool {
    	return server.tool(
    		'get-file',
    		'Returns information about a file, including links to download the file in thumbnail, preview, and original formats.',
    		{
    			title: z.string().describe( 'File title' )
    		},
    		{
    			title: 'Get file',
    			readOnlyHint: true,
    			destructiveHint: false
    		} as ToolAnnotations,
    		async ( { title } ) => handleGetFileTool( title )
    	);
    }
  • Helper function that converts the raw file data into a formatted text content array for the tool response.
    function getFileToolResult( result: MwRestApiFileObject ): TextContent[] {
    	return [
    		{
    			type: 'text',
    			text: [
    				`File title: ${ result.title }`,
    				`File description URL: ${ result.file_description_url }`,
    				`Latest revision timestamp: ${ result.latest.timestamp }`,
    				`Latest revision user: ${ result.latest.user.name }`,
    				`Preferred URL: ${ result.preferred.url }`,
    				`Original URL: ${ result.original.url }`,
    				`Thumbnail URL: ${ result.thumbnail?.url }`
    			].join( '\n' )
    		}
    	];
    }

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