generated from zircote/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add mcp module reference to LIBRARY-API.md #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -561,8 +561,223 @@ Min/max bounds for filtering animals by trait value in search criteria. | |||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## mcp Module | ||||||||||
|
|
||||||||||
| The `mcp` module provides a complete Model Context Protocol server implementation with tools, resources, prompts, and analytics for livestock breeding intelligence. | ||||||||||
|
|
||||||||||
| ### NsipServer | ||||||||||
|
|
||||||||||
| MCP server implementation that exposes 13 tools, 5 static resources, 4 resource templates, and 7 guided breeding prompts. | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use nsip::mcp::NsipServer; | ||||||||||
|
|
||||||||||
| let server = NsipServer::new(); | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### `NsipServer::new() -> Self` | ||||||||||
|
|
||||||||||
| Create a new MCP server instance with default NSIP API client. | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use nsip::mcp::NsipServer; | ||||||||||
|
|
||||||||||
| let server = NsipServer::new(); | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### `serve_stdio() -> Result<()>` | ||||||||||
|
|
||||||||||
| Start the MCP server on stdio transport (used by Claude Desktop, Claude Code, Cursor, etc.). | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use nsip::mcp::serve_stdio; | ||||||||||
|
|
||||||||||
| #[tokio::main] | ||||||||||
| async fn main() -> nsip::Result<()> { | ||||||||||
| serve_stdio().await | ||||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ### analytics Submodule | ||||||||||
|
|
||||||||||
| Pure computation functions for breeding analytics with no external dependencies. | ||||||||||
|
|
||||||||||
| #### Types | ||||||||||
|
|
||||||||||
| **`CoiRating`** — Traffic-light rating for inbreeding coefficient: | ||||||||||
| - `Green` — COI < 6.25% (acceptable) | ||||||||||
| - `Yellow` — 6.25% ≤ COI < 12.5% (elevated, proceed with caution) | ||||||||||
| - `Red` — COI ≥ 12.5% (high inbreeding, generally avoid) | ||||||||||
|
|
||||||||||
| **`SharedAncestor`** — Common ancestor found in both sire and dam pedigrees. | ||||||||||
|
|
||||||||||
| | Field | Type | Description | | ||||||||||
| |-------|------|-------------| | ||||||||||
| | `lpn_id` | `String` | LPN ID of the common ancestor | | ||||||||||
| | `sire_depth` | `usize` | Generations from sire to this ancestor | | ||||||||||
| | `dam_depth` | `usize` | Generations from dam to this ancestor | | ||||||||||
|
|
||||||||||
| **`CoiResult`** — Result of coefficient of inbreeding calculation. | ||||||||||
|
|
||||||||||
| | Field | Type | Description | | ||||||||||
| |-------|------|-------------| | ||||||||||
| | `coefficient` | `f64` | Wright's coefficient of inbreeding (0.0–1.0) | | ||||||||||
| | `rating` | `CoiRating` | Traffic-light rating | | ||||||||||
| | `shared_ancestors` | `Vec<SharedAncestor>` | Common ancestors contributing to inbreeding | | ||||||||||
|
|
||||||||||
| **`RankedAnimal`** — Animal with weighted composite score for trait-based ranking. | ||||||||||
|
|
||||||||||
| | Field | Type | Description | | ||||||||||
| |-------|------|-------------| | ||||||||||
| | `lpn_id` | `String` | LPN identifier | | ||||||||||
| | `score` | `f64` | Weighted composite score | | ||||||||||
| | `trait_scores` | `HashMap<String, f64>` | Per-trait weighted scores | | ||||||||||
|
|
||||||||||
| #### Functions | ||||||||||
|
|
||||||||||
| **`calculate_coi(sire_lineage: &Lineage, dam_lineage: &Lineage) -> CoiResult`** | ||||||||||
|
|
||||||||||
| Calculate Wright's coefficient of inbreeding from sire and dam pedigrees. | ||||||||||
|
|
||||||||||
| Formula: `COI = Σ [(0.5)^(n₁ + n₂ + 1)]` where: | ||||||||||
| - `n₁` = path length from sire to common ancestor | ||||||||||
| - `n₂` = path length from dam to common ancestor | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use nsip::{NsipClient, mcp::analytics::calculate_coi}; | ||||||||||
|
|
||||||||||
| # async fn example() -> nsip::Result<()> { | ||||||||||
| let client = NsipClient::new(); | ||||||||||
| let sire_lineage = client.lineage("430735-0032").await?; | ||||||||||
| let dam_lineage = client.lineage("430735-0089").await?; | ||||||||||
|
|
||||||||||
| let coi_result = calculate_coi(&sire_lineage, &dam_lineage); | ||||||||||
| println!("COI: {:.2}% ({:?})", coi_result.coefficient * 100.0, coi_result.rating); | ||||||||||
| # Ok(()) | ||||||||||
| # } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| **`rank_animals(animals: &[AnimalDetails], weights: &HashMap<String, f64>) -> Vec<RankedAnimal>`** | ||||||||||
|
|
||||||||||
| Rank animals by weighted composite of EBV traits. | ||||||||||
|
|
||||||||||
| Score formula: `Σ (trait_value × weight × accuracy/100)` for each trait. | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use std::collections::HashMap; | ||||||||||
| use nsip::{NsipClient, mcp::analytics::rank_animals}; | ||||||||||
|
|
||||||||||
| # async fn example() -> nsip::Result<()> { | ||||||||||
| let client = NsipClient::new(); | ||||||||||
| let search = client.search( | ||||||||||
| nsip::SearchCriteria::new() | ||||||||||
| .with_breed_id(486) | ||||||||||
| .with_gender("Male") | ||||||||||
| .with_status("CURRENT") | ||||||||||
| ).await?; | ||||||||||
|
|
||||||||||
| let weights = HashMap::from([ | ||||||||||
| ("BWT".to_string(), -1.0), | ||||||||||
| ("WWT".to_string(), 2.0), | ||||||||||
| ("YWT".to_string(), 1.5), | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| let ranked = rank_animals(&search.animals, &weights); | ||||||||||
| for animal in ranked.iter().take(5) { | ||||||||||
| println!("{}: {:.2}", animal.lpn_id, animal.score); | ||||||||||
| } | ||||||||||
| # Ok(()) | ||||||||||
| # } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| **`trait_complementarity(sire: &AnimalDetails, dam: &AnimalDetails) -> HashMap<String, f64>`** | ||||||||||
|
|
||||||||||
| Predict midparent EBV values for potential offspring. | ||||||||||
|
|
||||||||||
| Formula: `predicted_EBV = (sire_EBV + dam_EBV) / 2.0` | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| use nsip::{NsipClient, mcp::analytics::trait_complementarity}; | ||||||||||
|
|
||||||||||
| # async fn example() -> nsip::Result<()> { | ||||||||||
| let client = NsipClient::new(); | ||||||||||
| let sire = client.details("430735-0032").await?; | ||||||||||
| let dam = client.details("430735-0089").await?; | ||||||||||
|
Comment on lines
+706
to
+707
|
||||||||||
| let sire = client.details("430735-0032").await?; | |
| let dam = client.details("430735-0089").await?; | |
| let sire = client.animal_details("430735-0032").await?; | |
| let dam = client.animal_details("430735-0089").await?; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example code has two issues:
Line 674:
client.search()should beclient.search_animals()- the method is calledsearch_animals, notsearch.Line 687:
&search.animalsshould be changed becauseSearchResultshas a field calledresults(of typeVec<serde_json::Value>), notanimals. Furthermore,rank_animals()expects&[AnimalDetails], butSearchResults.resultscontains raw JSON values. The example needs to deserialize the results or use a different approach to obtainAnimalDetailsobjects.