search_mdn
Search MDN Web Docs to quickly find web development documentation, empowering users to access reliable resources for coding and troubleshooting.
Instructions
Search MDN Web Docs for web development documentation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query |
Implementation Reference
- src/index.ts:108-136 (handler)The core handler function that implements the search_mdn tool logic: queries MDN API, caches results with node-cache, formats top 5 results, handles errors with McpError.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 the ListTools response, defining name, description, and input schema for search_mdn.{ 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-461 (registration)Dispatch handler in CallToolRequestSchema that invokes the searchMDN function for search_mdn tool calls and formats the MCP response.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 defining the expected arguments (query: string) for the search_mdn tool.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' } }, required: ['query'] }