Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.
Rust ai-agentsclaude-codeclicodexcoding-agentskanbanlocal-firstmcpmcp-servermodel-context-protocolproductivityproject-managementraspberry-pirustself-hostedsqlitetask-manager
Add the MCP server (kanzo mcp)
emanuele-em0b582a69951c
diff --git a/Cargo.lock b/Cargo.lockindex 42643f2..13302c4 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2,6 +2,15 @@# It is not intended for manual editing.version = 4+[[package]]+name = "android_system_properties"+version = "0.1.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"+dependencies = [+ "libc",+]+[[package]]name = "anstream"version = "1.0.0"@@ -64,6 +73,12 @@ version = "1.1.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"+[[package]]+name = "autocfg"+version = "1.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"+[[package]]name = "axum"version = "0.8.9"@@ -116,12 +131,24 @@ dependencies = ["tracing",]+[[package]]+name = "base64"+version = "0.23.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"+[[package]]name = "bitflags"version = "2.13.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"+[[package]]+name = "bumpalo"+version = "3.20.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"+[[package]]name = "bytes"version = "1.12.1"@@ -144,6 +171,18 @@ version = "1.0.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"+[[package]]+name = "chrono"+version = "0.4.45"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"+dependencies = [+ "iana-time-zone",+ "num-traits",+ "serde",+ "windows-link",+]+[[package]]name = "clap"version = "4.6.7"@@ -175,7 +214,7 @@ dependencies = ["heck","proc-macro2","quote",- "syn",+ "syn 3.0.9",][[package]]@@ -190,6 +229,46 @@ version = "1.0.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"+[[package]]+name = "core-foundation-sys"+version = "0.8.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"++[[package]]+name = "darling"+version = "0.24.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec"+dependencies = [+ "darling_core",+ "darling_macro",+]++[[package]]+name = "darling_core"+version = "0.24.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6837e2cf7485aaae18f86181d2f0e9a7ed297a025e220aeabf63fdebd3a2ddff"+dependencies = [+ "ident_case",+ "proc-macro2",+ "quote",+ "strsim",+ "syn 3.0.9",+]++[[package]]+name = "darling_macro"+version = "0.24.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785"+dependencies = [+ "darling_core",+ "quote",+ "syn 3.0.9",+]+[[package]]name = "dirs"version = "7.0.0"@@ -211,6 +290,12 @@ dependencies = ["windows-sys",]+[[package]]+name = "dyn-clone"+version = "1.0.20"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"+[[package]]name = "equivalent"version = "1.0.3"@@ -266,12 +351,71 @@ dependencies = ["percent-encoding",]+[[package]]+name = "futures"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-executor",+ "futures-io",+ "futures-sink",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-channel"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"+dependencies = [+ "futures-core",+ "futures-sink",+]+[[package]]name = "futures-core"version = "0.3.34"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"+[[package]]+name = "futures-executor"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432"+dependencies = [+ "futures-core",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-io"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"++[[package]]+name = "futures-macro"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 3.0.9",+]++[[package]]+name = "futures-sink"+version = "0.3.34"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"+[[package]]name = "futures-task"version = "0.3.34"@@ -284,8 +428,13 @@ version = "0.3.34"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"dependencies = [+ "futures-channel","futures-core",+ "futures-io",+ "futures-macro",+ "futures-sink","futures-task",+ "memchr","pin-project-lite","slab",]@@ -404,6 +553,36 @@ dependencies = ["tower-service",]+[[package]]+name = "iana-time-zone"+version = "0.1.65"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"+dependencies = [+ "android_system_properties",+ "core-foundation-sys",+ "iana-time-zone-haiku",+ "js-sys",+ "log",+ "wasm-bindgen",+ "windows-core",+]++[[package]]+name = "iana-time-zone-haiku"+version = "0.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"+dependencies = [+ "cc",+]++[[package]]+name = "ident_case"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"+[[package]]name = "indexmap"version = "2.14.2"@@ -412,6 +591,8 @@ checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"dependencies = ["equivalent","hashbrown",+ "serde",+ "serde_core",][[package]]@@ -426,6 +607,17 @@ version = "1.0.18"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"+[[package]]+name = "js-sys"+version = "0.3.106"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5"+dependencies = [+ "cfg-if",+ "futures-util",+ "wasm-bindgen",+]+[[package]]name = "kanzo"version = "0.1.0"@@ -434,7 +626,9 @@ dependencies = ["axum","clap","dirs",+ "rmcp","rusqlite",+ "schemars","serde","serde_json","tempfile",@@ -518,6 +712,15 @@ dependencies = ["windows-sys",]+[[package]]+name = "num-traits"+version = "0.2.19"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"+dependencies = [+ "autocfg",+]+[[package]]name = "once_cell"version = "1.21.4"@@ -559,6 +762,12 @@ dependencies = ["windows-link",]+[[package]]+name = "pastey"+version = "0.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"+[[package]]name = "percent-encoding"version = "2.3.2"@@ -620,6 +829,63 @@ dependencies = ["thiserror",]+[[package]]+name = "ref-cast"+version = "1.0.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3"+dependencies = [+ "ref-cast-impl",+]++[[package]]+name = "ref-cast-impl"+version = "1.0.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 3.0.9",+]++[[package]]+name = "rmcp"+version = "3.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ece64e19631fc38758181e637c15509a2c2709ee53bfde1e1d58f9dc991f919e"+dependencies = [+ "base64",+ "chrono",+ "futures",+ "indexmap",+ "libc",+ "pastey",+ "pin-project-lite",+ "rmcp-macros",+ "schemars",+ "serde",+ "serde_json",+ "thiserror",+ "tokio",+ "tokio-util",+ "tracing",+ "uuid",+]++[[package]]+name = "rmcp-macros"+version = "3.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "967fa7f7935d7d6217d593df0e8e5c9307bcaf256974a5a9ee64476c97735389"+dependencies = [+ "darling",+ "proc-macro2",+ "quote",+ "serde_json",+ "syn 3.0.9",+]+[[package]]name = "rsqlite-vfs"version = "0.2.0"@@ -657,12 +923,44 @@ dependencies = ["windows-sys",]+[[package]]+name = "rustversion"+version = "1.0.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"+[[package]]name = "ryu"version = "1.0.23"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"+[[package]]+name = "schemars"+version = "1.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e"+dependencies = [+ "chrono",+ "dyn-clone",+ "ref-cast",+ "schemars_derive",+ "serde",+ "serde_json",+]++[[package]]+name = "schemars_derive"+version = "1.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e1c3a92094fa7d61aa124645844facb6b554dfc797136d0f5fd1f890e2bffc69"+dependencies = [+ "proc-macro2",+ "quote",+ "serde_derive_internals",+ "syn 3.0.9",+]+[[package]]name = "scopeguard"version = "1.2.0"@@ -696,7 +994,18 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"dependencies = ["proc-macro2","quote",- "syn",+ "syn 3.0.9",+]++[[package]]+name = "serde_derive_internals"+version = "0.30.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f852137cce035d6a4df67ccce505ff6b3e9fd3a10e3e52b24dc71e650bb1a9bd"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 3.0.9",][[package]]@@ -798,6 +1107,17 @@ version = "0.11.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"+[[package]]+name = "syn"+version = "2.0.119"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]+[[package]]name = "syn"version = "3.0.9"@@ -845,7 +1165,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"dependencies = ["proc-macro2","quote",- "syn",+ "syn 3.0.9",][[package]]@@ -873,7 +1193,21 @@ checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"dependencies = ["proc-macro2","quote",- "syn",+ "syn 3.0.9",+]++[[package]]+name = "tokio-util"+version = "0.7.20"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b"+dependencies = [+ "bytes",+ "futures-core",+ "futures-sink",+ "libc",+ "pin-project-lite",+ "tokio",][[package]]@@ -951,9 +1285,21 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"dependencies = ["log","pin-project-lite",+ "tracing-attributes","tracing-core",]+[[package]]+name = "tracing-attributes"+version = "0.1.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]+[[package]]name = "tracing-core"version = "0.1.36"@@ -975,6 +1321,17 @@ version = "0.2.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"+[[package]]+name = "uuid"+version = "1.29.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514"+dependencies = [+ "getrandom",+ "js-sys",+ "wasm-bindgen",+]+[[package]]name = "vcpkg"version = "0.2.15"@@ -987,12 +1344,110 @@ version = "0.11.1+wasi-snapshot-preview1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"+[[package]]+name = "wasm-bindgen"+version = "0.2.129"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"+dependencies = [+ "cfg-if",+ "once_cell",+ "rustversion",+ "wasm-bindgen-macro",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-macro"+version = "0.2.129"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"+dependencies = [+ "quote",+ "wasm-bindgen-macro-support",+]++[[package]]+name = "wasm-bindgen-macro-support"+version = "0.2.129"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"+dependencies = [+ "bumpalo",+ "proc-macro2",+ "quote",+ "syn 3.0.9",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-shared"+version = "0.2.129"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "windows-core"+version = "0.62.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"+dependencies = [+ "windows-implement",+ "windows-interface",+ "windows-link",+ "windows-result",+ "windows-strings",+]++[[package]]+name = "windows-implement"+version = "0.60.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]++[[package]]+name = "windows-interface"+version = "0.59.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]+[[package]]name = "windows-link"version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"+[[package]]+name = "windows-result"+version = "0.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"+dependencies = [+ "windows-link",+]++[[package]]+name = "windows-strings"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"+dependencies = [+ "windows-link",+]+[[package]]name = "windows-sys"version = "0.61.2"diff --git a/Cargo.toml b/Cargo.tomlindex c1bed48..18718ea 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -15,7 +15,9 @@ anyhow = "1.0.104"axum = "0.8.9"clap = { version = "4.6.7", features = ["derive"] }dirs = "7.0.0"+rmcp = { version = "=3.7.0", features = ["server", "transport-io", "macros"] }rusqlite = { version = "0.41.0", features = ["bundled"] }+schemars = "1.2.3"serde = { version = "1.0.229", features = ["derive"] }serde_json = "1.0.154"tokio = { version = "1.54.1", features = ["full"] }diff --git a/src/main.rs b/src/main.rsindex d158fce..752d192 100644--- a/src/main.rs+++ b/src/main.rs@@ -1,4 +1,5 @@mod home;+mod mcp;mod store;mod web;@@ -11,7 +12,7 @@ use crate::home::Home;/// A local kanban board for you and your agents.///-/// Run `kanzo` to open the board.+/// Run `kanzo` to open the board. Agents connect with `kanzo mcp`.#[derive(Parser)]#[command(name = "kanzo", version)]struct Cli {@@ -33,6 +34,8 @@ struct Cli {#[derive(Subcommand)]enum Command {+ /// Run the MCP server on stdio (agents launch this, not you)+ Mcp,/// Create the data folder; the first run does this tooInit {/// Folder to create [default: the data folder]@@ -60,6 +63,7 @@ async fn run(cli: Cli) -> anyhow::Result<()> {let home = Home::open(dir)?;match cli.command {None => web::serve(home, cli.port, !cli.no_open).await,+ Some(Command::Mcp) => mcp::serve(home).await,Some(Command::Init { .. }) => {println!("Kanzo data folder ready at {}", home.dir.display());Ok(())diff --git a/src/mcp.rs b/src/mcp.rsnew file mode 100644index 0000000..3686928--- /dev/null+++ b/src/mcp.rs@@ -0,0 +1,412 @@+//! `kanzo mcp`: the board as MCP tools over stdio. Replies are short plain text to save agents' tokens.++use std::path::PathBuf;+use std::process::Command;+use std::sync::Arc;++use anyhow::Result;+use rmcp::handler::server::router::tool::ToolRouter;+use rmcp::handler::server::wrapper::Parameters;+use rmcp::model::{CallToolResult, ContentBlock, Implementation, ServerCapabilities, ServerConfig};+use rmcp::{ErrorData, Peer, RoleServer, ServerHandler, ServiceExt, tool, tool_handler, tool_router};+use schemars::JsonSchema;+use serde::Deserialize;++use crate::home::Home;+use crate::store::{self, Comment, Error, Project, Store, Task, TaskPatch};++const INSTRUCTIONS: &str = "Kanzo is the user's kanban board, shared by all their projects. \+Tasks are written project#id, like api#12. When you leave out `project`, Kanzo uses the project \+linked to the GitHub repo of the folder you are working in. A good loop: next_task to pick up work, \+add_comment to report what you did, then update_task to move it to review.";++pub async fn serve(home: Home) -> Result<()> {+ let cwd = std::env::current_dir().unwrap_or_default();+ let repos = git_repos(&cwd);+ let server = Kanzo { ctx: Arc::new(Ctx { home, cwd, repos }), tool_router: Kanzo::tool_router() };+ let service = server.serve(rmcp::transport::stdio()).await?;+ service.waiting().await?;+ Ok(())+}++struct Ctx {+ home: Home,+ cwd: PathBuf,+ /// GitHub repos (`owner/repo`) of the git remotes of `cwd`.+ repos: Vec<String>,+}++impl Ctx {+ /// The named project, or the one linked to this folder's git remote.+ fn project(&self, store: &Store, name: Option<&str>) -> store::Result<Project> {+ if let Some(name) = name.map(str::trim).filter(|n| !n.is_empty()) {+ return store.find_project(name);+ }+ for repo in &self.repos {+ if let Some(p) = store.project_by_repo(repo)? {+ return Ok(p);+ }+ }+ let known: Vec<String> = store.list_projects()?.into_iter().map(|p| p.slug).collect();+ let known = known.join(", ");+ let cwd = self.cwd.display();+ let msg = match (self.repos.first(), known.is_empty()) {+ (Some(repo), false) => format!(+ "No project is linked to {repo} (the git remote of {cwd}). Pass `project` (one of: {known}), \+ or link this repo by calling create_project with repo \"{repo}\"."+ ),+ (Some(repo), true) => format!(+ "No project is linked to {repo} (the git remote of {cwd}), and there are no projects yet. \+ Create one with create_project and repo \"{repo}\"."+ ),+ (None, false) => {+ format!("Cannot tell the project: {cwd} has no git remote. Pass `project` (one of: {known}).")+ }+ (None, true) => "There are no projects yet. Create one with create_project.".to_string(),+ };+ Err(Error::NotFound(msg))+ }+}++fn git_repos(dir: &std::path::Path) -> Vec<String> {+ let Ok(out) = Command::new("git").arg("-C").arg(dir).args(["remote", "-v"]).output() else {+ return Vec::new();+ };+ let text = String::from_utf8_lossy(&out.stdout);+ // `origin` first, so it wins when several remotes are linked to different projects.+ let mut lines: Vec<&str> = text.lines().collect();+ lines.sort_by_key(|l| !l.starts_with("origin\t"));+ let mut repos = Vec::new();+ for line in lines {+ if let Some(repo) = line.split_whitespace().nth(1).and_then(store::repo_from_url)+ && !repos.contains(&repo)+ {+ repos.push(repo);+ }+ }+ repos+}++#[derive(Clone)]+pub struct Kanzo {+ ctx: Arc<Ctx>,+ #[allow(dead_code, reason = "used by the tool_handler macro")]+ tool_router: ToolRouter<Self>,+}++/// A task, as `api#12` or just `12`.+#[derive(Deserialize, JsonSchema)]+#[serde(untagged)]+enum TaskKey {+ Number(i64),+ Text(String),+}++impl TaskKey {+ fn find(&self, store: &Store) -> store::Result<Task> {+ match self {+ TaskKey::Number(n) => store.get_task(*n),+ TaskKey::Text(s) => store.find_task(s),+ }+ }+}++#[derive(Deserialize, JsonSchema)]+struct CreateProjectArgs {+ /// Short lowercase name used in task ids, like `api` for api#12.+ slug: String,+ /// Display name. Defaults to the slug.+ name: Option<String>,+ /// GitHub repo to link, as owner/repo. Agents working in that repo then find the project on their own.+ repo: Option<String>,+}++#[derive(Deserialize, JsonSchema)]+struct ListTasksArgs {+ /// Project slug, or "all" for every project. Defaults to the project of the current repo.+ project: Option<String>,+ /// Only this column. Without it, done tasks are left out; "all" includes them.+ status: Option<String>,+}++#[derive(Deserialize, JsonSchema)]+struct TaskArgs {+ /// Task id, like api#12 or 12.+ id: TaskKey,+}++#[derive(Deserialize, JsonSchema)]+struct CreateTaskArgs {+ title: String,+ /// Markdown.+ description: Option<String>,+ /// Project slug. Defaults to the project of the current repo.+ project: Option<String>,+}++#[derive(Deserialize, JsonSchema)]+struct UpdateTaskArgs {+ /// Task id, like api#12 or 12.+ id: TaskKey,+ title: Option<String>,+ /// Markdown; replaces the whole description.+ description: Option<String>,+ /// New column, like doing, review or done. The task goes to the bottom of it.+ status: Option<String>,+}++#[derive(Deserialize, JsonSchema)]+struct AddCommentArgs {+ /// Task id, like api#12 or 12.+ id: TaskKey,+ /// Markdown.+ body: String,+ /// Who is writing. Defaults to the name of your MCP client, like claude-code.+ author: Option<String>,+}++#[derive(Deserialize, JsonSchema)]+struct NextTaskArgs {+ /// Project slug, or "all" for any project. Defaults to the project of the current repo.+ project: Option<String>,+}++#[tool_router]+impl Kanzo {+ /// Runs `f` with a fresh connection on a blocking thread and turns the+ /// outcome into text; errors go back to the agent as tool errors it can read.+ async fn run(&self, f: impl FnOnce(&Ctx, &Store) -> store::Result<String> + Send + 'static) -> CallToolResult {+ let ctx = self.ctx.clone();+ let outcome = tokio::task::spawn_blocking(move || {+ let store = ctx.home.store().map_err(|e| e.to_string())?;+ f(&ctx, &store).map_err(|e| e.to_string())+ })+ .await+ .unwrap_or_else(|e| Err(format!("internal error: {e}")));+ match outcome {+ Ok(text) => CallToolResult::success(vec![ContentBlock::text(text)]),+ Err(text) => CallToolResult::error(vec![ContentBlock::text(text)]),+ }+ }++ #[tool(description = "List all projects with their linked repo and open task counts.")]+ async fn list_projects(&self) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(|ctx, store| {+ let projects = store.list_projects()?;+ if projects.is_empty() {+ return Ok("No projects yet. Create one with create_project.".into());+ }+ let here = projects.iter().find(|p| p.repo.as_ref().is_some_and(|r| ctx.repos.contains(r)));+ Ok(projects+ .iter()+ .map(|p| {+ let repo = p.repo.as_deref().map(|r| format!(" ({r})")).unwrap_or_default();+ let mark = if here.is_some_and(|h| h.id == p.id) { " <- current repo" } else { "" };+ format!("{}: {}{repo}, {} open of {}{mark}", p.slug, p.name, p.open, p.total)+ })+ .collect::<Vec<_>>()+ .join("\n"))+ })+ .await)+ }++ #[tool(description = "Create a project, optionally linked to a GitHub repo (owner/repo).")]+ async fn create_project(+ &self,+ Parameters(args): Parameters<CreateProjectArgs>,+ ) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |_, store| {+ let p = store.create_project(&args.slug, args.name.as_deref().unwrap_or(""), args.repo.as_deref())?;+ let repo = p.repo.as_deref().map(|r| format!(", linked to {r}")).unwrap_or_default();+ Ok(format!("Created project {} ({}){repo}.", p.slug, p.name))+ })+ .await)+ }++ #[tool(description = "List tasks one per line, in board order. Leaves out done tasks unless `status` is given.")]+ async fn list_tasks(&self, Parameters(args): Parameters<ListTasksArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |ctx, store| {+ let all = args.project.as_deref().is_some_and(|p| p.trim().eq_ignore_ascii_case("all"));+ let project = if all { None } else { Some(ctx.project(store, args.project.as_deref())?) };+ let status = args.status.as_deref().map(str::trim).filter(|s| !s.is_empty());+ let mut tasks = match status {+ Some("all") => store.list_tasks(project.as_ref().map(|p| p.id), None)?,+ Some(s) => {+ if !store.statuses().iter().any(|x| x == s) {+ return Err(Error::Invalid(format!(+ "unknown status {s:?}; use one of: {}, or all",+ store.statuses().join(", ")+ )));+ }+ store.list_tasks(project.as_ref().map(|p| p.id), Some(s))?+ }+ None => store.list_tasks(project.as_ref().map(|p| p.id), None)?,+ };+ let done = store.statuses().last().cloned().unwrap_or_default();+ let hidden = if status.is_none() {+ let before = tasks.len();+ tasks.retain(|t| t.status != done);+ before - tasks.len()+ } else {+ 0+ };+ let scope = project.as_ref().map_or("any project".to_string(), |p| p.slug.clone());+ let mut out: Vec<String> = tasks.iter().map(task_line).collect();+ if out.is_empty() {+ out.push(format!("No tasks in {scope}."));+ }+ if hidden > 0 {+ out.push(format!("({hidden} {done} not shown; pass status \"{done}\" or \"all\")"));+ }+ Ok(out.join("\n"))+ })+ .await)+ }++ #[tool(description = "Show a task with its description and comments.")]+ async fn get_task(&self, Parameters(args): Parameters<TaskArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |_, store| {+ let task = args.id.find(store)?;+ let comments = store.list_comments(task.id)?;+ Ok(task_detail(&task, &comments))+ })+ .await)+ }++ #[tool(description = "Add a task to the first column (todo) of a project.")]+ async fn create_task(&self, Parameters(args): Parameters<CreateTaskArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |ctx, store| {+ let project = ctx.project(store, args.project.as_deref())?;+ let t = store.create_task(project.id, &args.title, args.description.as_deref().unwrap_or(""))?;+ Ok(format!("Created {} in {}: {}", t.key(), t.status, t.title))+ })+ .await)+ }++ #[tool(description = "Change a task's title, description or status. Only the fields you pass change.")]+ async fn update_task(&self, Parameters(args): Parameters<UpdateTaskArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |_, store| {+ let before = args.id.find(store)?;+ let status = args.status.map(|s| s.trim().to_ascii_lowercase());+ let after = store+ .update_task(before.id, TaskPatch { title: args.title, description: args.description, status })?;+ let moved = if before.status != after.status {+ format!(", {} -> {}", before.status, after.status)+ } else {+ String::new()+ };+ Ok(format!("Updated {}{moved}: {}", after.key(), after.title))+ })+ .await)+ }++ #[tool(description = "Add a comment to a task, for example to report progress or a result.")]+ async fn add_comment(+ &self,+ Parameters(args): Parameters<AddCommentArgs>,+ peer: Peer<RoleServer>,+ ) -> Result<CallToolResult, ErrorData> {+ let client = peer.peer_info().map(|i| i.client_info.name.clone()).filter(|n| !n.is_empty());+ let author = args.author.filter(|a| !a.trim().is_empty()).or(client).unwrap_or_else(|| "agent".into());+ Ok(self+ .run(move |_, store| {+ let task = args.id.find(store)?;+ store.add_comment(task.id, &author, &args.body)?;+ Ok(format!("Comment added to {} as {author}.", task.key()))+ })+ .await)+ }++ #[tool(+ description = "Take the top task of the todo column, move it to doing and show it. Use this to pick up the next piece of work."+ )]+ async fn next_task(&self, Parameters(args): Parameters<NextTaskArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |ctx, store| {+ let all = args.project.as_deref().is_some_and(|p| p.trim().eq_ignore_ascii_case("all"));+ let project = if all { None } else { Some(ctx.project(store, args.project.as_deref())?) };+ match store.next_task(project.as_ref().map(|p| p.id))? {+ Some(task) => {+ let comments = store.list_comments(task.id)?;+ Ok(format!("Moved {} to {}.\n\n{}", task.key(), task.status, task_detail(&task, &comments)))+ }+ None => {+ let scope = project.map_or("any project".into(), |p| p.slug);+ Ok(format!("Nothing in {} for {scope}.", store.statuses()[0]))+ }+ }+ })+ .await)+ }++ #[tool(description = "Delete a task and its comments. This cannot be undone.")]+ async fn delete_task(&self, Parameters(args): Parameters<TaskArgs>) -> Result<CallToolResult, ErrorData> {+ Ok(self+ .run(move |_, store| {+ let task = args.id.find(store)?;+ store.delete_task(task.id)?;+ let comments = match task.comments {+ 0 => String::new(),+ 1 => " and its comment".into(),+ n => format!(" and its {n} comments"),+ };+ Ok(format!("Deleted {}{comments}: {}", task.key(), task.title))+ })+ .await)+ }+}++#[tool_handler]+impl ServerHandler for Kanzo {+ fn get_info(&self) -> ServerConfig {+ ServerConfig::new(ServerCapabilities::builder().enable_tools().build())+ .with_server_info(Implementation::new("kanzo", env!("CARGO_PKG_VERSION")))+ .with_instructions(INSTRUCTIONS)+ }+}++/// `2026-10-25T09:30:00Z` -> `2026-10-25 09:30 UTC`.+fn short_time(ts: &str) -> String {+ match (ts.get(..10), ts.get(11..16)) {+ (Some(d), Some(t)) => format!("{d} {t} UTC"),+ _ => ts.to_string(),+ }+}++fn task_line(t: &Task) -> String {+ let comments = match t.comments {+ 0 => String::new(),+ 1 => " (1 comment)".into(),+ n => format!(" ({n} comments)"),+ };+ format!("{} [{}] {}{comments}", t.key(), t.status, t.title)+}++fn task_detail(t: &Task, comments: &[Comment]) -> String {+ let mut out = format!(+ "{} {}\nstatus: {}, created {}, updated {}\n",+ t.key(),+ t.title,+ t.status,+ short_time(&t.created_at),+ short_time(&t.updated_at)+ );+ if !t.description.is_empty() {+ out.push('\n');+ out.push_str(&t.description);+ out.push('\n');+ }+ if !comments.is_empty() {+ out.push_str(&format!("\nComments ({}):\n", comments.len()));+ for c in comments {+ out.push_str(&format!("- {}, {}: {}\n", c.author, short_time(&c.created_at), c.body));+ }+ }+ out.trim_end().to_string()+}