Skip to main content
Glama

get-file

Read-onlyIdempotent

Retrieve file metadata (uploader, timestamp, size, MIME type) and download URLs for thumbnail, preview, and original. Automatically adds the File: prefix if missing.

Instructions

Returns metadata for a file (uploader, timestamp, size, MIME type) along with download URLs for the thumbnail, preview, and original. The File: prefix is added automatically if omitted.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesFile title (with or without the "File:" prefix)

Implementation Reference

  • The `handle` function that executes the get-file tool logic. It queries the MediaWiki API for imageinfo (url, size, mime, timestamp, user) of the given file title, normalizes the title with a 'File:' prefix if needed, and returns metadata including thumbnailUrl, descriptionUrl, and original URL.
    	async handle({ title }, ctx: ToolContext): Promise<CallToolResult> {
    		const mwn = await ctx.mwn();
    
    		const fileTitle = title.startsWith('File:') ? title : `File:${title}`;
    
    		const response = await mwn.request({
    			action: 'query',
    			titles: fileTitle,
    			prop: 'imageinfo',
    			iiprop: 'url|size|mime|timestamp|user',
    			iiurlwidth: 200,
    			formatversion: '2',
    		});
    
    		// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- mwn API response shape; trusted at this boundary
    		const page = response.query?.pages?.[0] as ApiPage | undefined;
    
    		if (!page || page.missing) {
    			return ctx.format.notFound(`File "${title}" not found`);
    		}
    
    		const info: ImageInfo | undefined = page.imageinfo?.[0];
    
    		if (!info) {
    			return ctx.format.notFound(`No file info available for "${title}"`);
    		}
    
    		return ctx.format.ok({
    			title: page.title,
    			descriptionUrl: info.descriptionurl,
    			timestamp: info.timestamp,
    			user: info.user,
    			size: info.size,
    			mime: info.mime,
    			url: info.url,
    			thumbnailUrl: (info as ImageInfo & { thumburl?: string }).thumburl,
    		});
    	},
    };
  • Zod input schema for get-file: requires a single string parameter `title` (the file title, with or without the 'File:' prefix).
    const inputSchema = {
    	title: z.string().describe('File title (with or without the "File:" prefix)'),
    } as const;
  • The full tool definition object: name 'get-file', description, inputSchema, annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint), failureVerb, and target extractor.
    export const getFile: Tool<typeof inputSchema> = {
    	name: 'get-file',
    	description:
    		'Returns metadata for a file (uploader, timestamp, size, MIME type) along with download URLs for the thumbnail, preview, and original. The File: prefix is added automatically if omitted.',
    	inputSchema,
    	annotations: {
    		title: 'Get file',
    		readOnlyHint: true,
    		destructiveHint: false,
    		idempotentHint: true,
    		openWorldHint: true,
    	} as ToolAnnotations,
    	failureVerb: 'retrieve file data',
    	target: (a) => a.title,
    
    	async handle({ title }, ctx: ToolContext): Promise<CallToolResult> {
    		const mwn = await ctx.mwn();
    
    		const fileTitle = title.startsWith('File:') ? title : `File:${title}`;
    
    		const response = await mwn.request({
    			action: 'query',
    			titles: fileTitle,
    			prop: 'imageinfo',
    			iiprop: 'url|size|mime|timestamp|user',
    			iiurlwidth: 200,
    			formatversion: '2',
    		});
    
    		// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- mwn API response shape; trusted at this boundary
    		const page = response.query?.pages?.[0] as ApiPage | undefined;
    
    		if (!page || page.missing) {
    			return ctx.format.notFound(`File "${title}" not found`);
    		}
    
    		const info: ImageInfo | undefined = page.imageinfo?.[0];
    
    		if (!info) {
    			return ctx.format.notFound(`No file info available for "${title}"`);
    		}
    
    		return ctx.format.ok({
    			title: page.title,
    			descriptionUrl: info.descriptionurl,
    			timestamp: info.timestamp,
    			user: info.user,
    			size: info.size,
    			mime: info.mime,
    			url: info.url,
    			thumbnailUrl: (info as ImageInfo & { thumburl?: string }).thumburl,
    		});
    	},
    };
  • The `registerAllTools` function that registers all tools (including get-file) with the MCP server via the `register()` helper. get-file is included in the `standardTools` array at line 51 and gets dispatched and registered in the registration loop at line 83.
    export function registerAllTools(
    	server: McpServer,
    	reconcile: Reconcile,
    	ctx: ToolContext,
    ): Map<string, RegisteredTool> {
    	const registered = new Map<string, RegisteredTool>();
    
    	// oxlint-disable-next-line typescript/no-explicit-any
    	const allStandardTools: Tool<any>[] = [
    		...standardTools,
    		...extensionPacks.flatMap((p) => p.tools),
    	];
    	for (const tool of allStandardTools) {
    		try {
    			registered.set(tool.name, register(server, tool, dispatch(tool, ctx)));
    		} catch (error) {
    			logger.error('Error registering tool', { error: errorMessage(error) });
    		}
    	}
    
    	const mgmtCtx: ManagementContext = { ...ctx, reconcile };
    	for (const tool of managementTools) {
    		try {
    			registered.set(tool.name, register(server, tool, dispatch(tool, mgmtCtx)));
    		} catch (error) {
    			logger.error('Error registering tool', { error: errorMessage(error) });
    		}
    	}
    
    	// Extension-gated tools start disabled. They're enabled by reconcile() once
    	// the extension detector confirms the relevant extension is installed on
    	// the active wiki. This avoids a race where tools/list arrives before the
    	// initial reconcile completes.
    	for (const pack of extensionPacks) {
    		for (const tool of pack.tools) {
    			const reg = registered.get(tool.name);
    			if (reg && reg.enabled) {
    				reg.disable();
    			}
    		}
    	}
    
    	return registered;
    }
  • The `register()` helper function that binds a tool's name, description, inputSchema, and annotations to the MCP server's `registerTool()` method.
    export function register<TSchema extends ZodRawShape, TCtx extends ToolContext>(
    	server: McpServer,
    	tool: Tool<TSchema, TCtx>,
    	handler: (args: z.infer<z.ZodObject<TSchema>>) => Promise<CallToolResult>,
    ): RegisteredTool {
    	return server.registerTool(
    		tool.name,
    		{
    			description: tool.description,
    			inputSchema: tool.inputSchema,
    			annotations: tool.annotations,
    		},
    		// The SDK callback signature is `(args, extra) => ...`. Our descriptor
    		// handlers ignore the `extra` parameter, so we widen the type here. The
    		// `ZodRawShape` constraint from zod is the same shape as the SDK's
    		// `ZodRawShapeCompat` (Record<string, AnySchema>) — TypeScript just
    		// can't unify them through the generic boundary.
    		// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- generic boundary; MCP SDK's ToolCallback can't be unified with our typed handler
    		handler as unknown as ToolCallback<TSchema>,
    	);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint and idempotentHint true. The description adds value by detailing the returned data (metadata fields and URLs) and the automatic prefix behavior, providing behavioral context beyond annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences, front-loaded with the primary purpose, and a secondary sentence for a key usage hint. No unnecessary words or redundancies.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with no output schema, the description covers the core functionality (metadata fields, download URLs) and the parameter format. Missing details like error handling are acceptable given the tool's simplicity and annotation richness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, baseline is 3. The description reinforces the schema by repeating the 'File:' prefix handling, adding a helpful nuance that improves clarity for the agent.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool returns metadata (uploader, timestamp, size, MIME type) and download URLs, using specific verbs and resources. It distinguishes itself from sibling tools like upload-file or update-file by focusing on metadata retrieval.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains the automatic 'File:' prefix addition, which is a practical usage hint. While it doesn't explicitly contrast with siblings, the context makes it clear this is for file metadata; could mention when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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