Skip to main content
Glama
get-file.ts1.83 kB
import { z } from 'zod'; /* eslint-disable n/no-missing-import */ import type { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js'; import type { CallToolResult, TextContent, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js'; /* eslint-enable n/no-missing-import */ import { makeRestGetRequest } from '../common/utils.js'; import type { MwRestApiFileObject } from '../types/mwRestApi.js'; 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 ) ); } 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 ) }; } 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' ) } ]; }

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