search_wiki
Find information about visas, internet access, food options, getting started guides, and other essential resources for Network School students.
Instructions
Search the Network School wiki for information about visas, internet, food, getting started, and more
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query (e.g., "wifi password", "visa", "breakfast", "sim card") |
Implementation Reference
- src/wiki.ts:85-121 (handler)Core handler function that implements the search_wiki tool logic: reads all .md files in the wiki directory, counts case-insensitive matches of the query, collects results from matching pages, sorts by match count descending, and returns array of {page, content, matches}.export async function searchWiki(query: string): Promise<{ page: string; content: string; matches: number }[]> { const wikiDir = getWikiDir(); const lowerQuery = query.toLowerCase(); try { const files = await readdir(wikiDir); const mdFiles = files.filter(f => f.endsWith('.md')); const results: { page: string; content: string; matches: number }[] = []; for (const file of mdFiles) { const filePath = join(wikiDir, file); const content = await readFile(filePath, 'utf-8'); const lowerContent = content.toLowerCase(); // Count matches const matches = (lowerContent.match(new RegExp(lowerQuery, 'g')) || []).length; if (matches > 0) { const pageName = file.replace('.md', ''); results.push({ page: pageName, content, matches, }); } } // Sort by number of matches (descending) results.sort((a, b) => b.matches - a.matches); return results; } catch (error) { console.error('Error searching wiki:', error); return []; } }
- src/index.ts:113-126 (registration)Tool registration in the list_tools MCP handler, defining name 'search_wiki', description, and input schema requiring a 'query' string.{ name: 'search_wiki', description: 'Search the Network School wiki for information about visas, internet, food, getting started, and more', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (e.g., "wifi password", "visa", "breakfast", "sim card")', }, }, required: ['query'], }, },
- src/index.ts:116-125 (schema)Input schema for search_wiki tool: object with required 'query' string property.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (e.g., "wifi password", "visa", "breakfast", "sim card")', }, }, required: ['query'], },
- src/index.ts:252-302 (helper)Dispatch handler in call_tool MCP request: validates query arg, invokes searchWiki, formats results into a markdown response with titles and contents separated by ---, or error/no-results messages.case 'search_wiki': { const query = args?.query as string; if (!query || typeof query !== 'string') { return { content: [ { type: 'text', text: 'Error: query parameter is required and must be a string', }, ], isError: true, }; } const results = await searchWiki(query); if (results.length === 0) { return { content: [ { type: 'text', text: `No wiki pages found matching "${query}".`, }, ], }; } // Format the results let response = `Found ${results.length} wiki page${results.length !== 1 ? 's' : ''} matching "${query}":\n\n`; results.forEach((result, index) => { const title = result.page .split('-') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); response += `**${index + 1}. ${title}** (${result.matches} match${result.matches !== 1 ? 'es' : ''})\n\n`; response += result.content; response += '\n\n---\n\n'; }); return { content: [ { type: 'text', text: response.trim(), }, ], }; }