search-page
Search wiki page titles and contents using specific terms and retrieve matching results with a configurable limit for MediaWiki content.
Instructions
Search wiki page titles and contents for the provided search terms, and returns matching pages.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of search results to return (1-100) | |
| query | Yes | Search terms |
Implementation Reference
- src/tools/search-page.ts:30-58 (handler)Main handler function that executes the tool: calls REST API /v1/search/page, handles errors, formats results using helper.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:11-28 (registration)Tool registration function defining name 'search-page', description, input schema (query: string, limit?: number), annotations, and handler reference. Called from index.ts.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:61-73 (helper)Helper to format each search result page into a text 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:7-25 (registration)Imports and includes searchPageTool in the list of tool registrars for global registration via registerAllTools.import { searchPageTool } from './search-page.js'; import { setWikiTool } from './set-wiki.js'; import { addWikiTool } from './add-wiki.js'; import { removeWikiTool } from './remove-wiki.js'; import { updatePageTool } from './update-page.js'; import { getFileTool } from './get-file.js'; import { createPageTool } from './create-page.js'; import { uploadFileTool } from './upload-file.js'; 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,
- src/tools/search-page.ts:18-20 (schema)Zod input schema definition for the tool: query (string), limit (optional number 1-100).query: z.string().describe( 'Search terms' ), limit: z.number().int().min( 1 ).max( 100 ).optional().describe( 'Maximum number of search results to return' ) },