Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYesFile path on the local disk
titleYesFile title
textYesWikitext on the file page
commentNoReason for uploading the file

Implementation Reference

  • 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 ) }; }
  • 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 ) ); }
  • 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 ];
  • 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 ) }; }
  • 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; }

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