Skip to main content
Glama

upload-file-from-url

Upload files to a MediaWiki wiki directly from web URLs. Provide a URL, title, and wikitext to add files to the wiki without manual downloading and uploading.

Instructions

Uploads a file to the wiki from a web URL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the file to upload
titleYesFile title
textYesWikitext on the file page
commentNoReason for uploading the file

Implementation Reference

  • Main execution logic for the 'upload-file-from-url' tool. Handles the upload via mwn.uploadFromUrl, specific error handling for disabled URL uploads, and returns success or error results.
    async function handleUploadFileFromUrlTool( url: string, title: string, text: string, comment?: string ): Promise< CallToolResult > { let data: ApiUploadResponse; try { const mwn = await getMwn(); data = await mwn.uploadFromUrl( url, title, text, getApiUploadParams( comment ) ); } catch ( error ) { const errorMessage = ( error as Error ).message; // Prevent the LLM from attempting to find an existing image on the wiki // after failing to upload by URL. if ( errorMessage.includes( 'copyuploaddisabled' ) ) { return { content: [ { type: 'text', text: 'Upload failed: Upload by URL is disabled for this wiki. Please download the image from the URL to the local disk first, then use the upload-file tool to upload it from the local file path.' } as TextContent ], isError: true }; } return { content: [ { type: 'text', text: `Upload failed: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } return { content: uploadFileFromUrlToolResult( data ) }; }
  • Registers the 'upload-file-from-url' tool with the MCP server, including name, description, input schema (Zod), annotations, and handler function reference. This also defines the schema.
    export function uploadFileFromUrlTool( server: McpServer ): RegisteredTool { return server.tool( 'upload-file-from-url', 'Uploads a file to the wiki from a web URL.', { url: z.string().url().describe( 'URL of the file to upload' ), 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 from URL', readOnlyHint: false, destructiveHint: true } as ToolAnnotations, async ( { url, title, text, comment } ) => handleUploadFileFromUrlTool( url, title, text, comment ) ); }
  • Imports the uploadFileFromUrlTool registrar and includes it in the toolRegistrars array. The registerAllTools function iterates over registrars to register all tools including this one.
    import { uploadFileFromUrlTool } from './upload-file-from-url.js'; import { deletePageTool } from './delete-page.js'; import { getRevisionTool } from './get-revision.js'; import { undeletePageTool } from './undelete-page.js'; import { getCategoryMembersTool } from './get-category-members.js'; import { searchPageByPrefixTool } from './search-page-by-prefix.js'; const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool, searchPageByPrefixTool ]; export function registerAllTools( server: McpServer ): RegisteredTool[] { const registeredTools: RegisteredTool[] = []; for ( const registrar of toolRegistrars ) { try { registeredTools.push( registrar( server ) ); } catch ( error ) { console.error( `Error registering tool: ${ ( error as Error ).message }` ); } } return registeredTools; }
  • Helper function to prepare API upload parameters, formatting the edit comment specifically for this tool.
    function getApiUploadParams( comment?: string ): ApiUploadParams { return { comment: formatEditComment( 'upload-file-from-url', comment ) }; }
  • Helper function to format the successful upload response as an array of TextContent blocks.
    function uploadFileFromUrlToolResult( data: ApiUploadResponse ): TextContent[] { const result: TextContent[] = [ { type: 'text', text: 'File uploaded successfully from URL' } ]; 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