getConnectedApps
Retrieve connected apps in a React Native project by specifying the Metro server port. Simplify debugging with actionable insights into active app connections.
Instructions
Get the connected apps
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metroServerPort | Yes | The port number of the Metro server |
Implementation Reference
- src/tools/getConnectedApps/tool.ts:11-39 (handler)Handler function that fetches connected apps via Metro server's inspector endpoint, returns formatted app JSON or error.handler: async ({ metroServerPort }: GetConnectedAppsSchema) => { const metroServerOrigin = `http://localhost:${metroServerPort}`; try { const apps = await queryAllInspectorAppsAsync(metroServerOrigin); if (!apps || apps.length === 0) { throw new Error( 'No connected apps found, please ensure that Metro is running', ); } return { content: apps.map((app) => ({ type: 'text', text: JSON.stringify(app, null, 2), })), }; } catch (error) { return { content: [ { type: 'text', text: `Error: ${(error as Error).message}`, }, ], isError: true, }; } },
- Zod schema defining the input: metroServerPort (number). Includes TypeScript type export.export const getConnectedAppsSchema = z.object({ metroServerPort: z.number().describe('The port number of the Metro server'), }); export type GetConnectedAppsSchema = z.infer<typeof getConnectedAppsSchema>;
- src/tools/getConnectedApps/tool.ts:7-40 (registration)Primary tool registration object defining name, description, input schema, and handler reference.export const getConnectedAppsTool: ToolRegistration<GetConnectedAppsSchema> = { name: 'getConnectedApps', description: 'Get the connected apps', inputSchema: makeJsonSchema(getConnectedAppsSchema), handler: async ({ metroServerPort }: GetConnectedAppsSchema) => { const metroServerOrigin = `http://localhost:${metroServerPort}`; try { const apps = await queryAllInspectorAppsAsync(metroServerOrigin); if (!apps || apps.length === 0) { throw new Error( 'No connected apps found, please ensure that Metro is running', ); } return { content: apps.map((app) => ({ type: 'text', text: JSON.stringify(app, null, 2), })), }; } catch (error) { return { content: [ { type: 'text', text: `Error: ${(error as Error).message}`, }, ], isError: true, }; } }, };
- src/tools/index.ts:9-13 (registration)Tool is imported and registered in the central createTools function, wrapping the handler.{ ...getConnectedAppsTool, // biome-ignore lint/suspicious/noExplicitAny: All tools validate their input schemas, so any is fine. handler: (args: any) => getConnectedAppsTool.handler(args), },