Metadata-Version: 2.4
Name: kos-mcp
Version: 1.0.0b1
Summary: The local MCP server of KOS (Katsenia Optimization Solver): solve, inspect and explain LP and MIP models from AI assistants
Author-email: Katsenia SpA <support@katsenia.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://katsenia.com
Project-URL: Documentation, https://katsenia.com/help.html
Keywords: optimization,linear programming,mixed-integer programming,solver,mcp,model context protocol
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: kos-solver>=1.0.0b1
Requires-Dist: mcp<3,>=2.3
Requires-Dist: numpy
Provides-Extra: verify
Requires-Dist: kos-verify>=1.0.0b1; extra == "verify"
Dynamic: license-file

# kos-mcp

The local [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server of KOS, the Katsenia Optimization
Solver. It lets an AI assistant (Claude, Copilot, Cursor, Codex, Gemini and any other MCP client) solve, inspect and
explain linear programs (LP) and mixed-integer linear programs (MIP) with KOS, on your machine.

The assistant starts `kos-mcp` as a local process and talks to it over standard input and output (the MCP *stdio*
transport). There is no server of ours in the loop: models, files and results stay on your computer.

## Install

```
pip install --pre "kos-mcp[verify]"     # kos-solver (the solver), mcp (the MCP SDK) and kos-verify (the verifier)
```

or, to keep it in its own environment, `pipx install --pip-args=--pre "kos-mcp[verify]"` or `uvx --prerelease=allow
--from "kos-mcp[verify]" kos-mcp`. `--pre` is needed while KOS and kos-mcp are beta releases (1.0.0b1). It needs
Python 3.10 or later on Linux, on x86_64 or aarch64 (the platforms of the `kos-solver` package, imported as `kos`);
without `[verify]` everything works except the independent check of LP certificates.

Check it: `kos-mcp --version`. The server then waits for an MCP client on its standard input; it is not meant to be
used by hand.

## Configure your assistant

In every case the command is `kos-mcp` (if the assistant does not find it, give the absolute path that
`which kos-mcp` prints) and options go as arguments, for example `--root /home/me/models`. Use the `kos-mcp` command
rather than `python -m kos_mcp`: started with `-m`, Python itself imports modules from the working folder (the open
project, which may not be yours) before kos-mcp runs. For the same reason, do not start it with a relative entry in
`PYTHONPATH` (such as `.` or an empty entry): Python then imports from the working folder at startup, before kos-mcp
can remove it.

**Claude Code**

```
claude mcp add kos -- kos-mcp
claude mcp add -s user kos -- kos-mcp --root /home/me/models     # for every project, reading only that folder
```

**Claude Desktop**: in `claude_desktop_config.json` (Settings > Developer > Edit Config; on Linux
`~/.config/Claude/`; Claude Desktop for Linux is a beta, for Ubuntu 22.04 LTS or later and Debian 12 or later):

```json
{
  "mcpServers": {
    "kos": { "command": "kos-mcp", "args": [] }
  }
}
```

**Cursor**: in `.cursor/mcp.json` (one project) or `~/.cursor/mcp.json` (all projects); Cursor requires `type`:

```json
{
  "mcpServers": {
    "kos": { "type": "stdio", "command": "kos-mcp", "args": [] }
  }
}
```

**VS Code (GitHub Copilot)**: in `.mcp.json` at the workspace root, or `~/.copilot/mcp-config.json` for the user;
`tools` lists the tools to enable (`"*"`, all of them):

```json
{
  "mcpServers": {
    "kos": { "type": "stdio", "command": "kos-mcp", "args": [], "tools": ["*"] }
  }
}
```

An existing editor-managed configuration in `.vscode/mcp.json` takes the same entry under the key `servers` instead of
`mcpServers`.

**Codex CLI**: `codex mcp add kos -- kos-mcp`, or in `~/.codex/config.toml`:

```toml
[mcp_servers.kos]
command = "kos-mcp"
args = []
```

**Gemini CLI**: `gemini mcp add -s user kos kos-mcp` for every project (it writes `~/.gemini/settings.json`); without
`-s user` it writes the project's `.gemini/settings.json`. Options of the server go after `--`:
`gemini mcp add -s user kos kos-mcp -- --root /home/me/models`. The file takes the same `mcpServers` entry as Claude
Desktop.

## Tools

| tool | what it does |
|---|---|
| `solve_model` | Solves an LP or MIP given as LP or MPS text (`model_text`) or as a `.mps`/`.lp` file (`model_path`), with KOS parameters by name, a profile and a time limit. Returns the status explained in words, the objective, for a MIP the bound, gap and nodes, the iterations and seconds, a first page of variable values by name (optionally only nonzero values or names with a prefix) and a `solve_id`. For an LP, it can add duals and reduced costs, prove the objective in exact arithmetic, and write and verify the certificate. |
| `get_solution_values` | Pages through the values of a previous solve by `solve_id`: variable values, row duals and column reduced costs (LP), or row activities; by offset, by name, by prefix or nonzero only. |
| `inspect_model` | Reads a model without solving it: whether it reads (if not, the error and its line), rows, columns, nonzeros, sense, objective constant, variables by type (continuous, integer, binary) and bounds, rows by type, the ranges of coefficients, costs and bounds, read warnings, notes on likely problems, and whether this server can solve it. |
| `explain_infeasibility` | Solves the model and, if it is infeasible, shows why: for an LP, an irreducible infeasible subsystem (IIS) with each row's expression, side and bound; for a MIP, the IIS of its LP relaxation if that is infeasible; if the relaxation is feasible and the MIP is not, it says the conflict comes from integrality (KOS has no IIS for that case); if the relaxation ended undecided, it says so. |
| `verify_lp_certificate` | Solves an LP, writes the KOS certificate of the result (optimal, infeasible, unbounded or a bound, with the numbers that prove it) and checks it with kos-verify, the independent verifier, in exact arithmetic. |
| `list_parameters` | Lists the KOS parameters (default, values, help) and profiles, filtered by a search text. |

Results are JSON. Numbers are written as the shortest decimal that reads back as the same double, so they are exactly
the numbers KOS computed; infinities are the strings `"inf"` and `"-inf"`. Duals and reduced costs follow the KOS
convention: `d = c - A^T y` in the sense of the model, so `y_i` is the rate of change of the optimal objective per
unit increase of the active bound of row `i`.

`verify_lp_certificate` needs kos-verify, the independent verifier (Apache-2.0): install `kos-mcp[verify]` (or
`kos-verify` in the same environment), or start the server with `--kos-verify PATH/TO/kos_verify.py`. Without it, the
certificate is still written and its kind reported, and the verdict says the check did not run.

## Limits

Every call is limited, and the limits are options of the `kos-mcp` command:

| option | default | |
|---|---|---|
| `--default-time` | 60 (or `--max-time` if lower) | time limit of a solve when the call gives none (seconds) |
| `--max-time` | 600 | largest time limit a call may ask for (seconds) |
| `--grace` | 10 | seconds past a time limit before the server interrupts or stops the work |
| `--max-file-mb` | 100 | largest model file read |
| `--max-text-kb` | 4096 | largest model given as text |
| `--max-rows`, `--max-cols` | 500000 | largest model solved (`inspect_model` still describes larger ones) |
| `--page-size`, `--max-page-size` | 100, 2000 | values per page, by default and at most |
| `--max-response-chars` | 60000 | approximate size of a page of values |
| `--cache-solves` | 16 | solves whose values `get_solution_values` keeps |
| `--max-threads` | the CPUs | largest value of the `threads` parameter |
| `--verify-time` | 300 | time limit of kos-verify (seconds) |
| `--iis-time` | 120 | time limit of an IIS computation (seconds; KOS does not stop it at the solve's time limit) |
| `--max-memory-mb` | half of the machine's memory | address-space limit of the worker process of each call (0: no limit) |
| `--root DIR` | none | read model files only under these folders (repeatable) |

One model is processed at a time; a second call waits a few seconds for its turn and otherwise gets a `busy` error.
Each call runs in a worker process of its own, with its own process group and its own temporary folder. So the server
can stop work that does not end in time: KOS stops a solve at its time limit by itself; an IIS computation does not
stop, and the server ends it after `--iis-time` plus the grace and returns the rest of the result. When the server
stops a worker, it stops whatever the worker started (kos-verify) and removes the temporary folder; if the server
itself dies, its worker notices, removes the folder and ends. A worker that reaches its memory limit ends only its own
call, with an error that says so. When the assistant cancels a call, the solve is interrupted.

## The Community edition

The `kos-solver` package on PyPI is the KOS Community edition, which solves models of up to 2,000 rows (constraints) and
2,000 columns (variables). With it, a larger model gives a `size_limit` error that says so and links to
<https://katsenia.com/pricing.html>; reading and `inspect_model` work at any size (within the server's limits), and
`inspect_model` says whether this installation can solve the model.

## What it reads, and what it does not do

kos-mcp is meant to run with your user's permissions, started by an assistant you trust. What reaches it are the
tool arguments the assistant sends, which may come from text you did not write (a web page, a document), so it does
as little as possible with them:

- it reads only the file named in `model_path`, and only a regular file whose name ends in `.mps` or `.lp`, within the
  size limit and, with `--root`, inside those folders (symbolic links and `..` are resolved before the check);
- it never returns the contents of a file: only what KOS reads from a model (sizes, names, values, read errors with
  their line);
- it runs no code from the models or the arguments, opens no network connection and writes no file except temporary
  ones in a private temporary folder per call that it removes (an LP's certificate and, for a model given as text, its
  copy for kos-verify);
- its worker processes and kos-verify run in isolated mode (`python -I`, in that private folder), so they never import
  a Python file from the folder where the assistant started the server (an untrusted project, say); the server itself
  does not either when started with the `kos-mcp` command and without relative entries in `PYTHONPATH` (see
  "Configure your assistant");
- every call is bounded in time and size as above.

Use `--root` to confine it to the folders that hold your models.

## Why the official MCP SDK

kos-mcp is built on the official Python SDK of the Model Context Protocol (`mcp`, MIT license), maintained with the
protocol itself: it follows the protocol revisions, the negotiation with each client and the stdio transport, so this
server only defines its tools.

## License

Apache License 2.0 (`LICENSE` and `NOTICE`). Copyright 2026 Katsenia SpA. KOS itself (the `kos-solver` package) is
distributed under its own license: <https://katsenia.com/license.html>.
