search_mdn
Find web development documentation on MDN Web Docs by entering search queries to access technical references and guides.
Instructions
Search MDN Web Docs for web development documentation
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query |
Implementation Reference
- src/index.ts:108-136 (handler)Core handler function for search_mdn tool. Queries MDN search API with the given query, caches results using NodeCache for 1 hour, formats and returns top 5 results as a string.
private async searchMDN(query: string): Promise<string> { const cacheKey = `mdn:${query}`; const cached = cache.get<string>(cacheKey); if (cached) return cached; try { const response = await this.axiosInstance.get( 'https://developer.mozilla.org/api/v1/search', { params: { q: query, locale: 'en-US' } } ); const results = response.data.documents.slice(0, 5).map((doc: any, i: number) => `${i + 1}. ${doc.title}\n ${doc.summary}\n https://developer.mozilla.org${doc.mdn_url}\n` ).join('\n'); cache.set(cacheKey, results); return results; } catch (error) { throw new McpError( ErrorCode.InternalError, `MDN API error: ${error instanceof Error ? error.message : 'Unknown error'}` ); } } - src/index.ts:340-353 (registration)Tool registration in listTools handler, including name 'search_mdn', description, and input schema requiring a 'query' string.
{ name: 'search_mdn', description: 'Search MDN Web Docs for web development documentation', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' } }, required: ['query'] } }, - src/index.ts:450-460 (handler)Dispatch handler in CallToolRequestSchema that extracts the query argument and invokes the searchMDN function, returning the result as MCP text content.
case 'search_mdn': { const { query } = request.params.arguments as { query: string }; const results = await this.searchMDN(query); return { content: [ { type: 'text', text: results } ] }; - src/index.ts:343-352 (schema)Input schema definition for search_mdn tool, specifying an object with required 'query' string property.
inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' } }, required: ['query'] }