search_entities
Find New Relic entities by name, type, or tags. Filter by account ID and entity types to locate specific monitored resources.
Instructions
Search for entities in New Relic by name, type, or tags
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query for entities | |
| entity_types | No | Filter by entity types (e.g., APPLICATION, HOST) | |
| target_account_id | No | Optional New Relic account ID |
Implementation Reference
- src/tools/entity.ts:54-101 (handler)The actual handler logic for search_entities. Builds a GraphQL query with filters for account ID and entity types, then calls executeNerdGraphQuery and returns the entities.
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)Schema definition for the search_entities tool, defining input parameters: query (required string), entity_types (optional array of strings), and target_account_id (optional string).
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:57-73 (registration)Tool registration in the server constructor. entityTool.getSearchTool() is called and added to the tools map at line 72.
private registerTools(): void { const nrqlTool = new NrqlTool(this.client); const apmTool = new ApmTool(this.client); const entityTool = new EntityTool(this.client); const alertTool = new AlertTool(this.client); const syntheticsTool = new SyntheticsTool(this.client); const nerdGraphTool = new NerdGraphTool(this.client); const restDeployments = new RestDeploymentsTool(); const restApm = new RestApmTool(); const restMetrics = new RestMetricsTool(); // Register all tools const tools = [ nrqlTool.getToolDefinition(), apmTool.getListApplicationsTool(), entityTool.getSearchTool(), entityTool.getDetailsTool(), - src/server.ts:228-245 (registration)The case handler in executeTool that dispatches to EntityTool.searchEntities after validating inputs (query must be non-empty string, entity_types must be array of strings).
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, }); }