Skip to main content
Glama

search-page

Read-onlyIdempotent

Search wiki page titles and full-text content. Returns matching pages with snippets, size, and timestamps. Up to 100 results per query.

Instructions

Searches wiki page titles and page content (full-text) for the provided terms. Returns matching pages with a snippet, size, and timestamp. Accepts up to 100 matches per call (default 10); additional matches beyond the cap are flagged in the response — narrow the query to surface more. For title-prefix lookup (e.g. autocomplete), use search-page-by-prefix.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch terms
limitNoMaximum number of search results to return

Implementation Reference

  • The main handler for the 'search-page' tool. Defines the inputSchema (query string + optional limit 1-100), exports the Tool object with name 'search-page', and implements the handle() function that calls the MediaWiki API search (action=query, list=search) with the provided terms. Returns results with title, pageId, snippet, size, wordCount, timestamp, and url. Handles truncation when more results are available via response.continue.
    import { z } from 'zod';
    import type { CallToolResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
    import type { ApiSearchResult } from 'mwn';
    import type { Tool } from '../runtime/tool.js';
    import type { ToolContext } from '../runtime/context.js';
    import { getPageUrl } from '../wikis/utils.js';
    import type { TruncationInfo } from '../results/truncation.js';
    
    const inputSchema = {
    	query: z.string().describe('Search terms'),
    	limit: z
    		.number()
    		.int()
    		.min(1)
    		.max(100)
    		.optional()
    		.describe('Maximum number of search results to return'),
    } as const;
    
    export const searchPage: Tool<typeof inputSchema> = {
    	name: 'search-page',
    	description:
    		'Searches wiki page titles and page content (full-text) for the provided terms. Returns matching pages with a snippet, size, and timestamp. Accepts up to 100 matches per call (default 10); additional matches beyond the cap are flagged in the response — narrow the query to surface more. For title-prefix lookup (e.g. autocomplete), use search-page-by-prefix.',
    	inputSchema,
    	annotations: {
    		title: 'Search page',
    		readOnlyHint: true,
    		destructiveHint: false,
    		idempotentHint: true,
    		openWorldHint: true,
    	} as ToolAnnotations,
    	failureVerb: 'retrieve search data',
    	target: (a) => a.query,
    
    	async handle({ query, limit }, ctx: ToolContext): Promise<CallToolResult> {
    		const mwn = await ctx.mwn();
    
    		const params: Record<string, string | number | boolean> = {
    			action: 'query',
    			list: 'search',
    			srsearch: query,
    			srwhat: 'text',
    			srprop: 'snippet|size|timestamp|wordcount',
    			formatversion: '2',
    		};
    
    		if (limit !== undefined) {
    			params.srlimit = limit;
    		}
    
    		const response = await mwn.request(params);
    		const searchResults: ApiSearchResult[] = response.query?.search ?? [];
    
    		const truncation: TruncationInfo | null = response.continue
    			? {
    					reason: 'capped-no-continuation',
    					returnedCount: searchResults.length,
    					limit: limit ?? 10,
    					itemNoun: 'matches',
    					narrowHint: 'narrow the query or raise limit (max 100)',
    				}
    			: null;
    
    		return ctx.format.ok({
    			results: searchResults.map((r) => ({
    				title: r.title,
    				pageId: r.pageid,
    				snippet: r.snippet,
    				size: r.size,
    				wordCount: (r as ApiSearchResult & { wordcount?: number }).wordcount,
    				timestamp: r.timestamp,
    				url: getPageUrl(r.title, ctx.selection),
    			})),
    			...(truncation !== null ? { truncation } : {}),
    		});
    	},
    };
  • Input schema using Zod: requires a 'query' string, optional 'limit' integer between 1-100.
    const inputSchema = {
    	query: z.string().describe('Search terms'),
    	limit: z
    		.number()
    		.int()
    		.min(1)
    		.max(100)
    		.optional()
    		.describe('Maximum number of search results to return'),
    } as const;
  • Import of the searchPage tool from the search-page module.
    import { searchPage } from './search-page.js';
  • The searchPage tool is included in the standardTools array (line 47) and registered with the MCP server via register() in registerAllTools() (line 83), which calls server.registerTool() with the tool's name, description, inputSchema, and annotations.
    const standardTools: Tool<any>[] = [
    	getPage,
    	getPages,
    	getPageHistory,
    	getRecentChanges,
    	searchPage,
    	searchPageByPrefix,
    	parseWikitext,
    	comparePages,
    	getFile,
    	getRevision,
    	getCategoryMembers,
    	createPage,
    	updatePage,
    	deletePage,
    	undeletePage,
    	uploadFile,
    	uploadFileFromUrl,
    	updateFile,
    	updateFileFromUrl,
    	oauthStatus,
    	oauthLogout,
    ];
  • The getPageUrl helper function used by search-page to construct full URLs from page titles and the current wiki selection configuration.
    export function getPageUrl(title: string, wikiSelection: WikiSelection): string {
    	const { server, articlepath } = wikiSelection.getCurrent().config;
    	// MediaWiki convention: spaces become underscores. encodeURI preserves
    	// '/' (subpages) and ':' (namespace prefixes) while encoding spaces and
    	// non-ASCII characters. Characters disallowed in MW titles ('#', '?',
    	// '|', '[', ']', etc.) cannot reach this function via a real page title.
    	return `${server}${articlepath}/${encodeURI(title.replace(/ /g, '_'))}`;
    }
Behavior5/5

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

Adds value beyond annotations: describes return fields (snippet, size, timestamp) and behavior when results exceed cap (flagged). Annotations already mark as read-only and idempotent; no contradiction.

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 sentences, front-loaded with purpose, no unnecessary words. Efficient and clear.

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

Completeness5/5

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

Given no output schema, description adequately covers return values and limitations. Tool is simple with two parameters; no gaps in context.

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

Parameters3/5

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

Schema has 100% coverage with descriptions for both parameters. Description adds default and cap information but does not significantly extend meaning beyond schema.

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 performs full-text search on both page titles and content, and distinguishes from the sibling search-page-by-prefix which does title-prefix lookup.

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

Usage Guidelines5/5

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

Explicitly mentions the cap of 100 results, default of 10, and advises to narrow query for more results. Provides explicit alternative: use search-page-by-prefix for autocomplete.

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