nsip 0.4.0

NSIP Search API client for nsipsearch.nsip.org/api
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# MCP Tools Reference

Complete reference for the 13 tools exposed by the `nsip mcp` server.

For installation, configuration, resources, and prompts, see [MCP Server Reference](../MCP.md).

---

## Overview

The MCP server exposes 13 tools over the Model Context Protocol (stdio transport, protocol version `2024-11-05`). All tools return JSON results as text content. Errors use standard MCP error codes.

| Tool | Description |
|------|-------------|
| [search]#search | Search for animals with filters and sorting |
| [details]#details | Get detailed EBV data for an animal |
| [lineage]#lineage | Get pedigree / ancestry tree |
| [progeny]#progeny | Get offspring list (paginated) |
| [profile]#profile | Get complete animal profile in one call |
| [breed_groups]#breed_groups | List all breed groups and breeds |
| [trait_ranges]#trait_ranges | Get min/max EBV ranges for a breed |
| [compare]#compare | Compare 2-5 animals side-by-side |
| [rank]#rank | Rank animals by weighted EBV traits |
| [inbreeding_check]#inbreeding_check | Calculate Wright's COI for a mating pair |
| [mating_recommendations]#mating_recommendations | Find optimal mates for an animal |
| [flock_summary]#flock_summary | Summarize a flock's animals and trait averages |
| [database_status]#database_status | Get database last-updated date and statuses |

---

## search

Search for animals in the NSIP database with filters for breed, gender, status, date range, flock, and sorting.

**Parameters:**

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `breed_group_id` | integer | no | -- | Breed group ID to filter by |
| `breed_id` | integer | no | -- | Breed ID to filter by |
| `status` | string | no | -- | `"CURRENT"`, `"SOLD"`, or `"DEAD"` |
| `gender` | string | no | -- | `"Male"`, `"Female"`, or `"Both"` |
| `born_after` | string | no | -- | Only animals born after this date (`YYYY-MM-DD`) |
| `born_before` | string | no | -- | Only animals born before this date (`YYYY-MM-DD`) |
| `proven_only` | boolean | no | false | Only return proven animals |
| `flock_id` | string | no | -- | Flock ID to filter by |
| `sort_by` | string | no | -- | Trait abbreviation to sort by (e.g., `"WWT"`) |
| `reverse` | boolean | no | -- | Reverse the sort order |
| `page` | integer | no | 0 | Page number (0-indexed) |
| `page_size` | integer | no | 15 | Results per page (1-100) |

**Returns:** `SearchResults` -- total count, result objects, page, and page size.

**Example:**

```json
{
  "tool": "search",
  "arguments": {
    "breed_id": 486,
    "gender": "Male",
    "status": "CURRENT",
    "sort_by": "WWT",
    "page_size": 10
  }
}
```

---

## details

Get detailed EBV data, breed, contact info, and status for a specific animal by LPN ID.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `animal_id` | string | yes | LPN ID or registration number |

**Returns:** `AnimalDetails` -- LPN ID, breed, sex, date of birth, status, EBV traits, and contact info.

**Example:**

```json
{
  "tool": "details",
  "arguments": {
    "animal_id": "430735-0032"
  }
}
```

---

## lineage

Get pedigree / ancestry tree for a specific animal including parents and grandparents.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `animal_id` | string | yes | LPN ID of the animal |

**Returns:** `Lineage` -- subject, sire, dam, and extended generations.

**Example:**

```json
{
  "tool": "lineage",
  "arguments": {
    "animal_id": "430735-0032"
  }
}
```

---

## progeny

Get a paginated list of offspring for a specific animal.

**Parameters:**

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `animal_id` | string | yes | -- | LPN ID of the animal |
| `page` | integer | no | 0 | Page number (0-indexed) |
| `page_size` | integer | no | 10 | Results per page |

**Returns:** `Progeny` -- total count, offspring animals with their traits, page, and page size.

**Example:**

```json
{
  "tool": "progeny",
  "arguments": {
    "animal_id": "430735-0032",
    "page": 0,
    "page_size": 20
  }
}
```

---

## profile

Get a complete profile for an animal: details, pedigree, and offspring in one call.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `animal_id` | string | yes | LPN ID of the animal |

**Returns:** `AnimalProfile` -- combined details, lineage, and progeny.

**Example:**

```json
{
  "tool": "profile",
  "arguments": {
    "animal_id": "430735-0032"
  }
}
```

---

## breed_groups

List all breed groups and individual breeds in the NSIP database.

**Parameters:** None.

**Returns:** Array of `BreedGroup` objects, each containing `id`, `name`, and a `breeds` array.

**Example:**

```json
{
  "tool": "breed_groups",
  "arguments": {}
}
```

---

## trait_ranges

Get the minimum and maximum EBV trait ranges for a specific breed. Useful for understanding breed norms and setting trait filters.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `breed_id` | integer | yes | Breed ID to query |

**Returns:** JSON object with per-trait min/max values.

**Example:**

```json
{
  "tool": "trait_ranges",
  "arguments": {
    "breed_id": 486
  }
}
```

---

## compare

Compare 2-5 animals side-by-side on their EBV traits. Optionally filter to specific traits.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `animal_ids` | array of strings | yes | LPN IDs to compare (2-5 items) |
| `traits` | string | no | Comma-separated trait filter (e.g., `"BWT,WWT,YWT"`) |

**Returns:** Array of `AnimalDetails` objects for the requested animals.

**Example:**

```json
{
  "tool": "compare",
  "arguments": {
    "animal_ids": ["430735-0032", "430735-0041", "430735-0058"],
    "traits": "BWT,WWT,YWT,EMD"
  }
}
```

---

## rank

Rank animals within a breed by weighted EBV traits. Specify trait weights to prioritize breeding goals.

**Parameters:**

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `breed_id` | integer | yes | -- | Breed ID to search within |
| `weights` | object | yes | -- | Trait weights as `{"TRAIT": weight}` (e.g., `{"BWT": -1.0, "WWT": 2.0}`) |
| `gender` | string | no | -- | `"Male"`, `"Female"`, or `"Both"` |
| `status` | string | no | -- | Animal status filter (e.g., `"CURRENT"`) |
| `top_n` | integer | no | 10 | Number of top-ranked results to return |

**Ranking formula:** `Score = sum(trait_value * weight * accuracy / 100)` for each trait where both a weight and value exist.

**Returns:** Ranked list of animals with their composite scores and individual trait values.

**Example -- terminal sire selection:**

```json
{
  "tool": "rank",
  "arguments": {
    "breed_id": 486,
    "weights": {
      "BWT": -1.0,
      "WWT": 2.0,
      "YWT": 1.5,
      "EMD": 1.0
    },
    "gender": "Male",
    "status": "CURRENT",
    "top_n": 5
  }
}
```

**Example -- maternal sire selection:**

```json
{
  "tool": "rank",
  "arguments": {
    "breed_id": 486,
    "weights": {
      "NLB": 2.0,
      "NWT": 2.0,
      "PWT": 1.5,
      "BWT": -0.5
    },
    "gender": "Male",
    "top_n": 10
  }
}
```

---

## inbreeding_check

Calculate Wright's coefficient of inbreeding (COI) for a potential sire-dam mating. Returns the COI value, a traffic-light rating, and shared ancestors.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `sire_id` | string | yes | LPN ID of the sire |
| `dam_id` | string | yes | LPN ID of the dam |

**COI formula:** `COI = sum[(0.5)^(n1 + n2 + 1)]` where `n1` and `n2` are path lengths from sire and dam to each common ancestor.

**Traffic-light thresholds:**

| Rating | COI range | Interpretation |
|--------|-----------|----------------|
| Green | < 6.25% | Acceptable -- proceed with mating |
| Yellow | 6.25% - 12.5% | Elevated -- consider alternatives |
| Red | > 12.5% | High -- generally avoid |

**Returns:** COI coefficient, rating, and list of shared ancestors with path depths.

**Example:**

```json
{
  "tool": "inbreeding_check",
  "arguments": {
    "sire_id": "430735-0032",
    "dam_id": "430735-0089"
  }
}
```

**Example response:**

```json
{
  "coefficient": 0.03125,
  "rating": "Green",
  "shared_ancestors": [
    {
      "lpn_id": "410220-0015",
      "sire_depth": 2,
      "dam_depth": 2
    }
  ]
}
```

---

## mating_recommendations

Find optimal mates for an animal. Searches the breed for candidates, checks inbreeding, and ranks by trait complementarity.

**Parameters:**

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `animal_id` | string | yes | -- | LPN ID of the animal to find mates for |
| `breed_id` | integer | yes | -- | Breed ID to search for potential mates |
| `target_traits` | string | no | `WWT,BWT,NLB` | Traits to optimize (comma-separated) |
| `max_results` | integer | no | 5 | Maximum number of recommendations |

**Default trait weights (when `target_traits` is omitted):**
- WWT: 1.0
- BWT: -0.5
- NLB: 0.5

Traits where lower values are preferred (`BWT`, `DAG`, `WEC`, `FEC`) automatically receive negative weights.

**Offspring EBV prediction:** `predicted_offspring_EBV = (sire_EBV + dam_EBV) / 2`

**Returns:** Ranked list of recommended mates, each with a score, COI check, and predicted offspring EBVs.

**Example:**

```json
{
  "tool": "mating_recommendations",
  "arguments": {
    "animal_id": "430735-0032",
    "breed_id": 486,
    "target_traits": "WWT,EMD,NLB",
    "max_results": 3
  }
}
```

**Example response:**

```json
[
  {
    "mate_lpn_id": "430735-0089",
    "rank_score": 18.42,
    "coi": {
      "coefficient": 0.015,
      "rating": "Green"
    },
    "predicted_offspring_ebvs": {
      "BWT": 0.15,
      "WWT": 11.3,
      "EMD": 1.8,
      "NLB": 0.12
    }
  }
]
```

---

## flock_summary

Summarize a flock's animals: count, gender breakdown, and average EBV traits.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `flock_id` | string | yes | Flock ID to summarize |
| `breed_id` | integer | no | Breed ID to filter within the flock |

**Returns:** Flock summary with total count, sample size, male/female counts, and trait averages.

**Example:**

```json
{
  "tool": "flock_summary",
  "arguments": {
    "flock_id": "430735",
    "breed_id": 486
  }
}
```

**Example response:**

```json
{
  "flock_id": "430735",
  "total_count": 87,
  "sample_size": 87,
  "males": 12,
  "females": 75,
  "trait_averages": {
    "BWT": 0.32,
    "WWT": 8.45,
    "YWT": 12.10,
    "NLB": 0.08,
    "EMD": 0.95
  }
}
```

---

## database_status

Get the NSIP database last-updated date and available animal statuses.

**Parameters:** None.

**Returns:** Database status object with last-updated date and available statuses.

**Example:**

```json
{
  "tool": "database_status",
  "arguments": {}
}
```

---

## EBV Trait Abbreviations

These abbreviations are used in `sort_by`, `traits`, `weights`, and `target_traits` parameters:

| Abbreviation | Name | Unit | Selection Direction |
|--------------|------|------|---------------------|
| BWT | Birth Weight | lbs | Lower preferred |
| WWT | Weaning Weight | lbs | Higher preferred |
| PWWT | Post-Weaning Weight | lbs | Higher preferred |
| YWT | Yearling Weight | lbs | Higher preferred |
| FAT | Fat Depth | mm | Moderate preferred |
| EMD | Eye Muscle Depth | mm | Higher preferred |
| NLB | Number of Lambs Born | lambs | Higher preferred |
| NWT | Number of Lambs Weaned | lambs | Higher preferred |
| PWT | Pounds Weaned | lbs | Higher preferred |
| DAG | Dag Score | score | Lower preferred |
| WGR | Wool Growth Rate | g/day | Higher preferred |
| WEC | Worm Egg Count | eggs/g | Lower preferred |
| FEC | Fecal Egg Count | eggs/g | Lower preferred |

---

## See Also

- [MCP Server Reference]../MCP.md -- installation, configuration, resources, and prompts
- [CLI Reference]CLI.md -- command-line interface
- [Library API Reference]LIBRARY-API.md -- Rust library API
- [Configuration Reference]CONFIGURATION.md -- environment and client settings