P2Predict

v1.4.0
io.github.ahmed-khalil-hafsi/p2predict Checked 4 hours ago Published 1 day ago

Local MCP server for parametric price benchmarking in procurement and engineering.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

list_models

List all trained P2Predict models in the configured models directory. Call this first to discover which models are available. Each model carries a plain `say_to_user` line, its target, and its specs. Lead with `say_to_user`; do NOT read out raw fields like algorithm or R² (and never the words 'SHAP', 'log-target', 'R²') to a category manager. Pass include_internal=true only when you need the algorithm name / R² / log-target flag for your own reasoning. The response also carries a `server` block (version + git short-SHA + source path) identifying the build t…

ParameterTypeDescription
include_internalboolean

get_model_info

Get detailed information about a specific model. Returns a plain `say_to_user` line, the target, and the model's specs with their types (Numerical/Categorical) and allowed categories — everything you need to build a predict/explain call. Use it to understand what inputs a model expects. Lead with `say_to_user`; do NOT surface algorithm / R² / log-target (or the words 'SHAP', 'log-target', 'R²') to the user. Pass include_internal=true for those raw fields when you need them to reason.

ParameterTypeDescription
model_id *string
include_internalboolean

predict

Predict the target value (e.g. price) for a single part. Pass the model_id from list_models and a dictionary of feature values matching the model's expected features. Example: {"Weight": 15, "Region": "EU", "Supplier": "A"} Returns an `in_domain` block alongside the prediction — read it before you quote the number. 'out_of_domain' means the part sits outside the data the model was built on (an unseen supplier, a spec far past anything observed), so the estimate isn't reliable no matter how confident it looks; quote `in_domain.say_to_user` and point the user…

ParameterTypeDescription
features *object
model_id *string

predict_batch

Predict the target value for multiple parts at once. More efficient than calling predict repeatedly. Pass a list of feature dictionaries, one per part. Returns one prediction per row. Optionally enriches every row with the same views the single-part tools give, so you don't have to fan out to explain / predict_interval: - coverage (1-99): adds a likely-price range per row (conformal interval) when the model carries calibration data; read `interval.reliability` and `interval.say_to_user` per row exactly as predict_interval does. Left None (default…

ParameterTypeDescription
model_id *string
rows *array
coverage
with_explanationboolean

explain

Explain what is driving a part's predicted price, spec by spec. Returns a business-ready view to quote directly — `starting_point` (the baseline price every part starts from) and `price_drivers` (each spec / supplier's effect in BOTH dollars and percent, biggest mover first) — plus the underlying technical attribution for your own reasoning. top_n controls how many top drivers are highlighted (default 3). Reading it for the user: the explanation carries an axiom check (baseline +/x contributions = prediction); if it fails the explanation is unsound. SIGN-C…

ParameterTypeDescription
features *object
model_id *string
top_ninteger

predict_interval

Predict with a likely range (conformal prediction interval). For a 90% interval, about 9 in 10 similar parts fall within the range. coverage is an integer 1-99 (default 90). Requires a model trained with P2Predict v0.5+ (which stores calibration data). Reading it for the user: the band WIDTH is the per-part trust signal, and the payload computes it for you — `interval.reliability` ('trust' | 'caution' | 'quote') and a plain `interval.say_to_user` sentence you can quote directly. A tight band = predict with confidence; a very wide band — or a lower bound at…

ParameterTypeDescription
features *object
model_id *string
coverageinteger

what_if

Compare a base scenario with a counterfactual where features change. Returns a plain `summary` to quote directly (does the change add or save, how many dollars, what percent, old vs. new price), plus both predictions, the delta, and per-driver attribution of each change for your reasoning. Answers "what if we switch from supplier A to B?" Set coverage to null to skip intervals. `summary.reliability` grades how far to trust the DIRECTION of the move — 'trust' | 'caution' | 'quote' — with a plain `summary.say_to_user` line to quote. It fires when the changed…

ParameterTypeDescription
changes *object
features *object
model_id *string
coverage

predict_from_csv

Batch-predict from a CSV file on the local filesystem. The file-based sibling of predict_batch — use it when the user drops a spreadsheet of parts. Reads csv_path, predicts every row, and returns one prediction per row (point estimates by default). The same opt-in enrichments as predict_batch apply per row: - coverage (1-99): adds a likely-price range per row (conformal interval) with its `interval.reliability` / `interval.say_to_user` read. Requires a model with calibration data; an explicit coverage on an uncalibrated model returns a no_calib…

ParameterTypeDescription
csv_path *string
model_id *string
coverage
with_explanationboolean

propose_training_plan

Inspect a training CSV and return a plain-language plan BEFORE training. Call this first whenever a user wants to build a should-cost / pricing model. It reads the CSV, decides what it would predict, which columns it would use as specs, which it would leave out (and why — target leakage, dates, ID-like columns), and whether the target should use a log-target. It also reports suspicious prices (`price_outliers`, with CSV lines) and missing values (`missing_values`). It trains nothing and writes nothing. Relay `plain_summary` and `questions_for_the_user` to the us…

ParameterTypeDescription
csv_path *string
target *string
feature_outlier_policystring
max_featuresinteger
outlier_policystring

train

Train a new P2Predict model from a local CSV file. Prefer calling `propose_training_plan` first and confirming with the user — this tool is the execution step. The CSV must have spec columns and a price/cost target column. Training runs locally; no data leaves the machine. The trained model is saved and immediately available. Safe defaults (always surfaced in the returned `warnings` list): - When features are auto-selected (features=None), columns that look like target leakage (a near-duplicate of the price being predicted), date columns (e.g. a qu…

ParameterTypeDescription
csv_path *string
target *string
algorithmstring
allow_leaky_featuresboolean
budgetstring
feature_outlier_policystring
features
log_targetstring
max_featuresinteger
outlier_policystring

get_model_quality

Structured, agent-readable model-quality report — the JSON form of the PDF. Use this (not just generate_report, which only writes a PDF) when you need to *reason about or relay* model quality. Every judgment is computed so you don't eyeball thresholds: - `assessment.verdict` — LEAD WITH THIS. One of: 'trustworthy' | 'usable' | 'unreliable' | 'unknown' | 'insufficient_data'. It folds bias and sample size into a plain `headline` you can quote verbatim — e.g. a modest model that is even-handed reads 'usable', not just 'Needs Improvement'.…

ParameterTypeDescription
model_id *string
include_holdoutboolean
include_metricsboolean

generate_report

Generate a procurement-style model-quality PDF report (3 pages). Page 1: summary metrics + predicted vs actual scatter. Page 2: error distribution + median % error by price band. Page 3: top-N feature importance. The PDF is the human deliverable; the return value also echoes the same numbers as a structured `quality` block (identical to get_model_quality) so you can both hand the user the file AND reason over the metrics. Works best with models trained via the MCP train tool (which stores holdout data). For older models, the report may be unavailable.

ParameterTypeDescription
model_id *string
output_path