search-page
Search MediaWiki page titles and contents using specific terms to find relevant pages. This tool helps locate information by querying wiki databases and returning matching results.
Instructions
Search wiki page titles and contents for the provided search terms, and returns matching pages.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search terms | |
| limit | No | Maximum number of search results to return |
Implementation Reference
- src/tools/search-page.ts:11-28 (registration)Registers the "search-page" tool on the MCP server, including name, description, input schema with query and optional limit, annotations, and delegates to handler.export function searchPageTool( server: McpServer ): RegisteredTool { // TODO: Not having named parameters is a pain, // but using low-level Server type or using a wrapper function are addedd complexity return server.tool( 'search-page', 'Search wiki page titles and contents for the provided search terms, and returns matching pages.', { query: z.string().describe( 'Search terms' ), limit: z.number().int().min( 1 ).max( 100 ).optional().describe( 'Maximum number of search results to return' ) }, { title: 'Search page', readOnlyHint: true, destructiveHint: false } as ToolAnnotations, async ( { query, limit } ) => handleSearchPageTool( query, limit ) ); }
- src/tools/search-page.ts:30-58 (handler)Executes the tool: sends REST GET to /v1/search/page with query and optional limit, handles errors, formats and returns search results or error/no results messages.async function handleSearchPageTool( query: string, limit?: number ): Promise< CallToolResult > { let data: MwRestApiSearchPageResponse; try { data = await makeRestGetRequest<MwRestApiSearchPageResponse>( '/v1/search/page', { q: query, ...( limit ? { limit: limit.toString() } : {} ) } ); } catch ( error ) { return { content: [ { type: 'text', text: `Failed to retrieve search data: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } const pages = data.pages || []; if ( pages.length === 0 ) { return { content: [ { type: 'text', text: `No pages found for ${ query }` } as TextContent ] }; } return { content: pages.map( getSearchResultToolResult ) }; }
- src/tools/search-page.ts:61-73 (helper)Helper function to format a single search result into a TextContent block with title, description, ID, URL, and thumbnail.function getSearchResultToolResult( result: MwRestApiSearchResultObject ): TextContent { const { server, articlepath } = wikiService.getCurrent().config; return { type: 'text', text: [ `Title: ${ result.title }`, `Description: ${ result.description ?? 'Not available' }`, `Page ID: ${ result.id }`, `Page URL: ${ `${ server }${ articlepath }/${ result.key }` }`, `Thumbnail URL: ${ result.thumbnail?.url ?? 'Not available' }` ].join( '\n' ) }; }
- src/tools/index.ts:22-39 (registration)Includes searchPageTool in the array of tool registrars, which are invoked by registerAllTools to register all tools on the server.const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool, searchPageByPrefixTool ];