search_entities
Search for New Relic entities by name, type, or tags to identify and locate monitoring resources within your account.
Instructions
Search for entities in New Relic by name, type, or tags
Input Schema
TableJSON 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)Primary handler implementing the search_entities tool logic: constructs a GraphQL query for New Relic entity search based on input parameters and executes it via the client.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)Defines the input schema and metadata (name, description) for the search_entities tool.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:69-106 (registration)Registers the search_entities tool (via entityTool.getSearchTool()) into the server's tools Map for MCP listTools and callTool handling.const tools = [ nrqlTool.getToolDefinition(), apmTool.getListApplicationsTool(), entityTool.getSearchTool(), entityTool.getDetailsTool(), alertTool.getPoliciesTool(), alertTool.getIncidentsTool(), alertTool.getAcknowledgeTool(), syntheticsTool.getListMonitorsTool(), syntheticsTool.getCreateMonitorTool(), nerdGraphTool.getQueryTool(), // REST v2 tools restDeployments.getCreateTool(), restDeployments.getListTool(), restDeployments.getDeleteTool(), restApm.getListApplicationsTool(), restMetrics.getListMetricNamesTool(), restMetrics.getMetricDataTool(), restMetrics.getListApplicationHostsTool(), { name: 'get_account_details', description: 'Get New Relic account details', inputSchema: { type: 'object' as const, properties: { target_account_id: { type: 'string' as const, description: 'Optional account ID to get details for', }, }, }, }, ]; tools.forEach((tool) => { this.tools.set(tool.name, tool); }); }
- src/server.ts:228-245 (handler)Server-side wrapper handler for search_entities: performs input validation and delegates execution to EntityTool.searchEntities.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, }); }