get_screen_example
Retrieve React Native screen examples by specifying the screen name using the BluestoneApps MCP Remote Server, facilitating access to standardized coding practices.
Instructions
Get a React Native screen example
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| screen_name | Yes | Screen Name |
Implementation Reference
- src/index.ts:448-510 (handler)The inline async handler function that implements the core logic of the get_screen_example tool: checks for screen_name, tries exact match via getExampleContent, falls back to fuzzy matching with findClosestMatch, and returns the code content as text or an error message.async ({ screen_name }) => { if (!screen_name) { return { content: [ { type: "text", text: "Screen name not specified", }, ], }; } try { // First try exact match const result = getExampleContent("screens", screen_name); if (result.error) { // Try to find by fuzzy match const screensDir = path.join(CODE_EXAMPLES_DIR, "react-native", "screens"); const closestMatch = findClosestMatch(screensDir, screen_name); if (closestMatch) { const fuzzyResult = getExampleContent("screens", closestMatch); return { content: [ { type: "text", text: fuzzyResult.content?.[0] ?? fuzzyResult.error ?? "Error: No content available", }, ], }; } else { return { content: [ { type: "text", text: `Screen ${screen_name} not found`, }, ], }; } } return { content: [ { type: "text", text: result.content?.[0] ?? result.error ?? "Error: No content available", }, ], }; } catch (err) { console.error(`Error getting screen example ${screen_name}:`, err); return { content: [ { type: "text", text: `Error getting screen example: ${err}`, }, ], }; } },
- src/index.ts:445-447 (schema)Zod input schema defining the required 'screen_name' parameter as a string.{ screen_name: z.string().describe("Screen Name"), },
- src/index.ts:442-511 (registration)Registers the get_screen_example tool on the MCP server with name, description, input schema, and inline handler.server.tool( "get_screen_example", "Get a React Native screen example", { screen_name: z.string().describe("Screen Name"), }, async ({ screen_name }) => { if (!screen_name) { return { content: [ { type: "text", text: "Screen name not specified", }, ], }; } try { // First try exact match const result = getExampleContent("screens", screen_name); if (result.error) { // Try to find by fuzzy match const screensDir = path.join(CODE_EXAMPLES_DIR, "react-native", "screens"); const closestMatch = findClosestMatch(screensDir, screen_name); if (closestMatch) { const fuzzyResult = getExampleContent("screens", closestMatch); return { content: [ { type: "text", text: fuzzyResult.content?.[0] ?? fuzzyResult.error ?? "Error: No content available", }, ], }; } else { return { content: [ { type: "text", text: `Screen ${screen_name} not found`, }, ], }; } } return { content: [ { type: "text", text: result.content?.[0] ?? result.error ?? "Error: No content available", }, ], }; } catch (err) { console.error(`Error getting screen example ${screen_name}:`, err); return { content: [ { type: "text", text: `Error getting screen example: ${err}`, }, ], }; } }, );
- src/index.ts:65-84 (helper)Helper function used by the handler to load the content of a specific example file from the code-examples/react-native/{subcategory} directory, using findFileInSubdirectories to locate it.function getExampleContent(subcategory: string, filename: string): { content?: string[]; path?: string; error?: string } { const searchDir = path.join(CODE_EXAMPLES_DIR, "react-native", subcategory); const filePath = findFileInSubdirectories(searchDir, filename); if (!filePath || !fs.existsSync(filePath)) { return { error: `Example ${filename} not found` }; } try { const content = fs.readFileSync(filePath, 'utf8'); return { content: [content], path: path.relative(BASE_DIR, filePath) }; } catch (err) { console.error(`Error reading example ${filename}:`, err); return { error: `Error reading example ${filename}` }; } }
- src/index.ts:87-109 (helper)Helper function used for fuzzy matching: finds the first filename in the directory (recursively) whose base name (no extension) contains the searchName (case-insensitive).function findClosestMatch(directory: string, searchName: string, extensions: string[] = ['.js', '.jsx', '.ts', '.tsx']) { if (!fs.existsSync(directory)) return null; let closestMatch = null; for (const ext of extensions) { const files = glob.sync(`${directory}/**/*${ext}`); for (const filePath of files) { const fileName = path.basename(filePath); const fileNameNoExt = path.basename(fileName, path.extname(fileName)); if (fileNameNoExt.toLowerCase().includes(searchName.toLowerCase())) { closestMatch = fileNameNoExt; break; } } if (closestMatch) break; } return closestMatch; }