# Search Hosts — Datadog

> Search monitored infrastructure hosts. Filter by tag (env:production), name (host:web-01), or partial match. Sort by cpu, iowait, load, status, or apps. Host names from results can scope queries in Get Metric Data (e.g…

- Key: `datadog-search-hosts`
- Type: Action (Read-only)
- Version: 1.0.2
- App: Datadog (`datadog`) — https://pipedream.com/apps/datadog.md
- This page (HTML): https://pipedream.com/apps/datadog/actions/search-hosts
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/datadog/actions/search-hosts/search-hosts.mjs

## Description

Search monitored infrastructure hosts. Filter by tag (`env:production`), name (`host:web-01`), or partial match. Sort by `cpu`, `iowait`, `load`, `status`, or `apps`. Host names from results can scope queries in **Get Metric Data** (e.g. `avg:system.cpu.user{host:web-01}`), filter logs in **Search Logs** (`host:web-01`), or filter metrics in **Search Metrics**. Max 1000 results. [See the docs](https://docs.datadoghq.com/api/latest/hosts/#get-all-hosts-for-your-organization)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `region` | `string` | Yes | The regional site for a Datadog customer |
| `filter` | `string` | No | Filter hosts by name, alias, or tag. E.g. env:production or host:web-01. |
| `sortField` | `string` | No | Field to sort hosts by. |
| `sortDir` | `string` | No | Direction of sort. |
| `count` | `integer` | No | Number of hosts to return. Max 1000. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "datadog",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "datadog-search-hosts",
  arguments: {
    region: "Region",
    filter: "Filter",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "datadog-search-hosts",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    datadog: { authProvisionId: "apn_xxxxxxx" },
    region: "Region",
    filter: "Filter",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "datadog-search-hosts",
    "configured_props": {
      "datadog": { "authProvisionId": "apn_xxxxxxx" },
      "region": "Region",
      "filter": "Filter"
    }
  }'
```

---

- App: https://pipedream.com/apps/datadog.md · All apps: https://pipedream.com/apps
