Skip to main content

Python client for the Koshi MCP server — retrieval, memory, context, and quality tools for any LLM workflow. Auto-downloads a native AOT binary; no .NET install required.

Project description

koshi

PyPI version Python versions License

Python client for the Koshi MCP server. Retrieval, memory, context engineering, and quality scoring for any LLM workflow — 20 tools, all wrapped as Pythonic methods.

No .NET install required. The first call auto-downloads a small native AOT binary (~15 MB) into your user cache.


Install

pip install koshi

Requires Python 3.10+ on Linux x64/arm64, macOS x64/arm64, or Windows x64/arm64. Zero runtime dependencies — every byte is Python stdlib.

Quick start

from koshi import Client

with Client() as koshi:
    print(koshi.version())                          # diagnostics
    koshi.index_directory("/path/to/your/repo")     # BM25 index of all text files
    print(koshi.search("auth pattern", top_k=5))    # ranked retrieval
    koshi.remember(content="JWT tokens expire after 1h",
                   subject="auth", type="Decision")
    print(koshi.recall("auth"))                     # memory recall with recency + confidence

The first Client() call:

  1. Detects your OS/CPU.
  2. Looks for the matching koshi-mcp binary in KOSHI_BIN → versioned cache → PATH → GitHub release.
  3. Downloads, verifies SHA-256 (hashes are baked into the wheel — supply-chain safe), caches under your user cache dir.
  4. Spawns it as a subprocess, performs the MCP initialize handshake.
  5. Confirms the server's reported version matches the Python package version exactly. Mismatch raises IncompatibleBinaryError.

The 20 tools

Group Methods
Retrieval index_directory, index, search, list_indexed, clear_index
Memory remember, recall, forget, memory_stats, clear_memories
Context compile_context, token_count, budget_plan
Team / Quality register_team, score_turn, team_dashboard, analyze_feedback, list_teams
Diagnostics version, health

Every method returns the formatted text response from the MCP server. The full Koshi tool reference lives in the main README.

Environment variables

Var Effect
KOSHI_BIN Path to a koshi-mcp binary. Skips auto-download, overrides PATH lookup. Version still verified at spawn time.
KOSHI_MEMORY_FILE Persist memories to this JSON file across server restarts. Default: in-memory only.
KOSHI_INDEX_PATH Default directory for search / index_directory if you don't pass one.
KOSHI_INDEX_FILE Persist the BM25 retrieval index to this JSON file across server restarts. Auto-loads on first search; stale snapshots are invalidated by a (relpath, size, mtime) fingerprint check. Default: in-memory only.

Where binaries live

OS Cache path
Linux $XDG_CACHE_HOME/koshi/bin/<version>/ or ~/.cache/koshi/bin/<version>/
macOS ~/Library/Caches/koshi/bin/<version>/
Windows %LOCALAPPDATA%\koshi\bin\<version>\

The version is part of the path, so upgrading pip install -U koshi does not invalidate the cache for older Python projects pinned to an older koshi version.

Air-gapped / offline

Download the binary that matches your platform from a GitHub release of Koshi on a machine with internet, copy it onto the target machine, and point KOSHI_BIN at it. The version must match the installed koshi Python package exactly.

Error handling

from koshi import (
    Client,
    KoshiError,            # base class
    BinaryNotFoundError,   # nothing on disk + download failed
    IncompatibleBinaryError,  # version mismatch
    BinaryCorruptedError,  # SHA-256 mismatch
    UnsupportedPlatformError,  # no AOT artifact for this OS/CPU
    ProtocolError,         # malformed MCP message
    ToolError,             # tool returned an error response
    KoshiTimeoutError,     # request took longer than client.timeout
)

Why this exists

Koshi's engine is .NET. That's a deliberate choice — the runtime gets us best-in-class JSON, threading, and a great MCP SDK. But it's also adoption friction: most MCP users live in Python.

koshi (Python) closes the gap. You pip install koshi and never think about .NET. Under the hood, you're talking to the same engine the .NET ecosystem uses (Koshi.Mcp on NuGet), wire-compatible byte-for-byte.

Links

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koshi-0.5.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

koshi-0.5.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file koshi-0.5.1.tar.gz.

File metadata

  • Download URL: koshi-0.5.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for koshi-0.5.1.tar.gz
Algorithm Hash digest
SHA256 538c829f483b3eb58e15d3cce8862dd8a2a742ae2cd3938faedb3e32e64c2043
MD5 2387d860599a31090320387c8ae9cb49
BLAKE2b-256 ec58f96a32432780dc4b033db9c12cee2ba89e530117fc249fdea861a50f7f14

See more details on using hashes here.

File details

Details for the file koshi-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: koshi-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for koshi-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a68dc4199aafb1daf899a531fae60f1bbc1efe9978baacfb87d15799fdc48d5c
MD5 386f62e8828dbde99cba9d975c49f79c
BLAKE2b-256 94dbe1946ac61841a6c5699ec26ba6d3936c9513278dc45e9c2789bb22ace5c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page