upload-file
Upload files from your local disk to a MediaWiki wiki with specified titles, wikitext, and upload comments.
Instructions
Uploads a file to the wiki from the local disk.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | File path on the local disk | |
| title | Yes | File title | |
| text | Yes | Wikitext on the file page | |
| comment | No | Reason for uploading the file |
Implementation Reference
- src/tools/upload-file.ts:32-55 (handler)The core handler function that performs the file upload to the wiki using mwn.upload, catches errors, and returns appropriate CallToolResult with content.async function handleUploadFileTool( filepath: string, title: string, text: string, comment?: string ): Promise< CallToolResult > { let data: ApiUploadResponse; try { const mwn = await getMwn(); data = await mwn.upload( filepath, title, text, getApiUploadParams( comment ) ); } catch ( error ) { return { content: [ { type: 'text', text: `Upload failed: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } return { content: uploadFileToolResult( data ) }; }
- src/tools/upload-file.ts:11-30 (registration)Registers the 'upload-file' tool using server.tool, including input schema with zod validators, annotations, and attaches the handler function.export function uploadFileTool( server: McpServer ): RegisteredTool { return server.tool( 'upload-file', 'Uploads a file to the wiki from the local disk.', { filepath: z.string().describe( 'File path on the local disk' ), title: z.string().describe( 'File title' ), text: z.string().describe( 'Wikitext on the file page' ), comment: z.string().optional().describe( 'Reason for uploading the file' ) }, { title: 'Upload file', readOnlyHint: false, destructiveHint: true } as ToolAnnotations, async ( { filepath, title, text, comment } ) => handleUploadFileTool( filepath, title, text, comment ) ); }
- src/tools/index.ts:22-39 (registration)Includes the uploadFileTool registrar in the list of all tool registrars invoked by registerAllTools to register the tool with the MCP server.const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool, searchPageByPrefixTool ];
- src/tools/upload-file.ts:57-61 (helper)Helper function to prepare API upload parameters, formatting the edit comment specifically for 'upload-file' tool.function getApiUploadParams( comment?: string ): ApiUploadParams { return { comment: formatEditComment( 'upload-file', comment ) }; }
- src/tools/upload-file.ts:63-77 (helper)Helper function to format the successful upload response as TextContent array with success message and JSON details.function uploadFileToolResult( data: ApiUploadResponse ): TextContent[] { const result: TextContent[] = [ { type: 'text', text: 'File uploaded successfully' } ]; result.push( { type: 'text', text: `Upload details: ${ JSON.stringify( data, null, 2 ) }` } ); return result; }