search_entities
Find specific entities in New Relic by name, type, or tags using a search query. Filter results by entity types and account ID for precise data retrieval.
Instructions
Search for entities in New Relic by name, type, or tags
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_types | No | Filter by entity types (e.g., APPLICATION, HOST) | |
| query | Yes | Search query for entities | |
| target_account_id | No | Optional New Relic account ID |
Implementation Reference
- src/tools/entity.ts:54-102 (handler)The main execution logic for the 'search_entities' tool. Constructs a GraphQL query using the provided search query, optional entity types and account ID, executes it via the NewRelicClient, and returns the entities and nextCursor.async searchEntities(input: { query: string; entity_types?: string[]; target_account_id?: string; }): Promise<{ entities: Array<Record<string, unknown>>; nextCursor?: string }> { const accountId = input.target_account_id; let query = input.query; if (accountId) { query += ` AND accountId = '${accountId}'`; } if (input.entity_types && input.entity_types.length > 0) { const types = input.entity_types.map((t: string) => `'${t}'`).join(','); query += ` AND type IN (${types})`; } const graphqlQuery = `{ actor { entitySearch(query: "${query}") { results { entities { guid name type domain tags { key values } } nextCursor } } } }`; const response = (await this.client.executeNerdGraphQuery(graphqlQuery)) as { data?: { actor?: { entitySearch?: { results?: { entities: Array<Record<string, unknown>>; nextCursor?: string }; }; }; }; }; return response.data?.actor?.entitySearch?.results || { entities: [] }; }
- src/tools/entity.ts:11-35 (schema)Tool definition including name, description, and input schema for 'search_entities', specifying required 'query' and optional 'entity_types' and 'target_account_id'.getSearchTool(): Tool { return { name: 'search_entities', description: 'Search for entities in New Relic by name, type, or tags', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query for entities', }, entity_types: { type: 'array', items: { type: 'string' }, description: 'Filter by entity types (e.g., APPLICATION, HOST)', }, target_account_id: { type: 'string', description: 'Optional New Relic account ID', }, }, required: ['query'], }, }; }
- src/server.ts:228-245 (registration)Dispatch handler in the server's executeTool switch statement that validates inputs for 'search_entities' and calls the EntityTool's searchEntities method.case 'search_entities': { const { query, entity_types } = args as Record<string, unknown>; if (typeof query !== 'string' || query.trim() === '') { throw new Error('search_entities: "query" (non-empty string) is required'); } let types: string[] | undefined; if (entity_types !== undefined) { if (!Array.isArray(entity_types)) { throw new Error('search_entities: "entity_types" must be an array of strings'); } types = (entity_types as unknown[]).filter((t): t is string => typeof t === 'string'); } return await new EntityTool(this.client).searchEntities({ query, entity_types: types, target_account_id: accountId, }); }
- src/server.ts:71-72 (registration)Registration of the search_entities tool by calling entityTool.getSearchTool() and adding it to the list of available tools.apmTool.getListApplicationsTool(), entityTool.getSearchTool(),