# Search Naics Categories

`Search_Naics_Categories` is the GovTribe MCP dataset tool for finding canonical NAICS category records by code, GovTribe ID, or descriptive query text.

## When To Use

Typical questions this tool answers well:

* Which NAICS category record matches a specific six-digit NAICS code?
* What GovTribe NAICS identifier should be used in downstream filters?
* Which NAICS categories are most relevant to a capability area described in plain language?
* How can I include or exclude a known set of NAICS categories before searching awards or opportunities?
* How many NAICS category records match my current filter criteria before I fetch row data?

## Required Reading

1. Search\_Query\_Guide: Required before setting free-text query strings when search\_mode is used.
2. Search\_Mode\_Guide: Required before choosing keyword vs semantic retrieval.

## Input Contract

* `query`: Free-text query string. See Required Reading: Search\_Query\_Guide.
  * `type`: `string`
  * `required`: `no`
  * `default`: `n/a`
* `page`: 1-based page index.
  * `type`: `null|number`
  * `required`: `no`
  * `default`: `1`
* `per_page`: Rows per page.
  * `type`: `null|number`
  * `required`: `no`
  * `default`: `10`
* `search_mode`: Query interpretation mode. See Required Reading: Search\_Mode\_Guide.
  * `type`: `string`
  * `required`: `no`
  * `default`: `keyword`
  * `options`: `keyword`, `semantic`
* `naics_category_ids`: Include or exclude results by NAICS categories. Use GovTribe IDs or NAICS codes.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
* `naics_category_ids_operator`: Choose whether to include or exclude values for NAICS Category IDs (GovTribe or NAICS code).
  * `type`: `null|string`
  * `required`: `no`
  * `default`: `in`
  * `options`: `in`, `not_in`
* `fields_to_return`: Optional field list for row payloads. If omitted and `per_page > 0`, rows default to `govtribe_id`. For `per_page: 0` aggregation/meta calls, this field may be omitted. Specify `fields_to_return` whenever the user asks for fields beyond `govtribe_id`, and prefer omitting it in pure aggregation workflows.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
  * `options`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`, `code`, `updated_at`, `federal_contract_awards`, `federal_contract_opportunities`

## Output Contract

* Top-level keys:
  * `current_page`: Current page number when `per_page > 0`.
  * `data`: Array of result rows when `per_page > 0`.
  * `from`: First row position in the current page.
  * `last_page`: Last page number for current filters.
  * `path`: GovTribe search URL for this result set.
  * `per_page`: Applied page size.
  * `to`: Last row position in the current page.
  * `total`: Total matched row count for current query filters.
  * `contains`: Dataset label for the returned result set.
  * `search_results_id_can_generate_saved_search`: Saved-search eligibility flag.
  * `search_results_id`: Server-side search result identifier.
  * `view_search_results_url`: URL to open this exact result set.
  * `per_page: 0` behavior: response includes `path`, `total`, `contains`, `search_results_id_can_generate_saved_search`, `search_results_id`, and `view_search_results_url`.
* Row keys:
  * `govtribe_id`
  * `govtribe_type`
  * `govtribe_url`
  * `name`
  * `code`
  * `updated_at`
  * `federal_contract_awards`
  * `federal_contract_opportunities`
* Relationship retrieval map:
  * `federal_contract_awards`
    * `resource_type`: `federal_contract_award`
    * `tool`: `Search_Federal_Contract_Awards`
    * `filter`: `federal_contract_award_ids`
    * `nested_keys`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`
  * `federal_contract_opportunities`
    * `resource_type`: `federal_contract_opportunity`
    * `tool`: `Search_Federal_Contract_Opportunities`
    * `filter`: `federal_contract_opportunity_ids`
    * `nested_keys`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`

## Usage Patterns

Pattern A: Resolve one known NAICS code into a canonical category row. Tool: `Search_Naics_Categories`

```json
{
  "query": "",
  "search_mode": "keyword",
  "fields_to_return": [
    "govtribe_id"
  ],
  "page": 1,
  "per_page": 1,
  "naics_category_ids": [
    "541611"
  ],
  "naics_category_ids_operator": "in"
}
```

Pattern B: Keyword lookup for multiple specific NAICS codes in one call. Tool: `Search_Naics_Categories`

```json
{
  "query": "",
  "search_mode": "keyword",
  "fields_to_return": [
    "govtribe_id"
  ],
  "page": 1,
  "per_page": 25,
  "naics_category_ids": [
    "541512",
    "541330",
    "561210"
  ],
  "naics_category_ids_operator": "in"
}
```

Pattern C: Semantic discovery when the user describes a capability area instead of a code. Tool: `Search_Naics_Categories`

```json
{
  "query": "cybersecurity consulting services",
  "search_mode": "semantic",
  "fields_to_return": [
    "govtribe_id"
  ],
  "page": 1,
  "per_page": 10
}
```

Pattern D: Exclude known categories while exploring alternatives. Tool: `Search_Naics_Categories`

```json
{
  "query": "",
  "search_mode": "keyword",
  "fields_to_return": [
    "govtribe_id"
  ],
  "page": 1,
  "per_page": 10,
  "naics_category_ids": [
    "541611"
  ],
  "naics_category_ids_operator": "not_in"
}
```

Pattern E: Return metadata only for sizing and saved-search handoff, then rerun with `per_page > 0` to fetch rows. Tool: `Search_Naics_Categories`

```json
{
  "query": "",
  "search_mode": "keyword",
  "page": 1,
  "per_page": 0
}
```
