get_service_example
Retrieve a React Native service example by providing the service name, using BluestoneApps MCP Remote Server for remote access to coding standards and examples.
Instructions
Get a React Native service example
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service_name | Yes | Service Name |
Implementation Reference
- src/index.ts:376-438 (handler)The async handler function that implements the core logic of the get_service_example tool. It takes a service_name parameter, attempts to load the corresponding example file from resources/code-examples/react-native/services, falls back to fuzzy matching if not found, and returns the code content or an error message.async ({ service_name }) => { if (!service_name) { return { content: [ { type: "text", text: "Service name not specified", }, ], }; } try { // First try exact match const result = getExampleContent("services", service_name); if (result.error) { // Try to find by fuzzy match const servicesDir = path.join(CODE_EXAMPLES_DIR, "react-native", "services"); const closestMatch = findClosestMatch(servicesDir, service_name); if (closestMatch) { const fuzzyResult = getExampleContent("helper", closestMatch); return { content: [ { type: "text", text: fuzzyResult.content?.[0] ?? fuzzyResult.error ?? "Error: No content available", }, ], }; } else { return { content: [ { type: "text", text: `Service ${service_name} not found`, }, ], }; } } return { content: [ { type: "text", text: result.content?.[0] ?? result.error ?? "Error: No content available", }, ], }; } catch (err) { console.error(`Error getting service example ${service_name}:`, err); return { content: [ { type: "text", text: `Error getting service example: ${err}`, }, ], }; } },
- src/index.ts:373-375 (schema)Zod schema defining the input parameter service_name for the tool.{ service_name: z.string().describe("Service Name"), },
- src/index.ts:370-439 (registration)Registration of the get_service_example tool with McpServer using server.tool, including name, description, schema, and handler.server.tool( "get_service_example", "Get a React Native service example", { service_name: z.string().describe("Service Name"), }, async ({ service_name }) => { if (!service_name) { return { content: [ { type: "text", text: "Service name not specified", }, ], }; } try { // First try exact match const result = getExampleContent("services", service_name); if (result.error) { // Try to find by fuzzy match const servicesDir = path.join(CODE_EXAMPLES_DIR, "react-native", "services"); const closestMatch = findClosestMatch(servicesDir, service_name); if (closestMatch) { const fuzzyResult = getExampleContent("helper", closestMatch); return { content: [ { type: "text", text: fuzzyResult.content?.[0] ?? fuzzyResult.error ?? "Error: No content available", }, ], }; } else { return { content: [ { type: "text", text: `Service ${service_name} not found`, }, ], }; } } return { content: [ { type: "text", text: result.content?.[0] ?? result.error ?? "Error: No content available", }, ], }; } catch (err) { console.error(`Error getting service example ${service_name}:`, err); return { content: [ { type: "text", text: `Error getting service example: ${err}`, }, ], }; } }, );
- src/index.ts:65-84 (helper)Helper function getExampleContent used by the handler to locate and read example files from the specified subcategory directory (e.g., 'services').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 findClosestMatch used for fuzzy matching of example filenames when exact match fails.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; }