get-file
Fetch file details and download links, including thumbnail, preview, and original formats, by providing the file title using this MCP server tool for MediaWiki.
Instructions
Returns information about a file, including links to download the file in thumbnail, preview, and original formats.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | File title |
Implementation Reference
- src/tools/get-file.ts:25-41 (handler)The handler function that executes the tool logic: makes a REST GET request to /v1/file/{title}, handles errors, and formats the response using getFileToolResult.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 ) }; }
- src/tools/get-file.ts:9-23 (registration)The registration function for the 'get-file' tool, called from src/tools/index.ts. It uses server.tool to register the tool with name, description, input schema, annotations, and points to the handler.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 ) ); }
- src/tools/get-file.ts:14-15 (schema)Input schema definition using Zod: requires a 'title' string parameter.title: z.string().describe( 'File title' ) },
- src/tools/get-file.ts:43-58 (helper)Helper function that formats the retrieved MwRestApiFileObject into a text response with key file information.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' ) } ]; }