Skip to content

Commit fb93b07

Browse files
committed
mcp: Implement Smart Cache Engine stdio server
Replace the placeholder `sce mcp` implementation with a full MCP stdio server providing cache-aware file reads. The server persists per-repo cache state under <state_root>/sce/cache/ and tracks file visibility across sessions.
1 parent 2d5ba5f commit fb93b07

28 files changed

+2408
-1133
lines changed

cli/Cargo.lock

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ reqwest = { version = "0.12", default-features = false, features = ["json", "rus
2323
serde = { version = "1", features = ["derive"] }
2424
serde_json = "1"
2525
sha2 = "0.10"
26-
tokio = { version = "1", default-features = false, features = ["rt"] }
26+
tokio = { version = "1", default-features = false, features = ["rt", "io-util"] }
2727
tracing = "0.1"
28+
rmcp = { version = "1", features = ["server", "transport-io"] }
29+
schemars = "1"
2830
tracing-opentelemetry = "0.29"
2931
tracing-subscriber = { version = "0.3", features = ["registry"] }
3032
turso = "0"

cli/build.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
fs,
55
io::{self, Write as IoWrite},
66
path::{Path, PathBuf},
7+
process::Command,
78
};
89

910
const TARGETS: &[TargetSpec] = &[
@@ -34,6 +35,59 @@ fn main() {
3435
if let Err(error) = generate_embedded_asset_manifest() {
3536
panic!("failed to generate setup embedded asset manifest: {error}");
3637
}
38+
39+
emit_git_commit();
40+
}
41+
42+
fn emit_git_commit() {
43+
println!("cargo:rerun-if-env-changed=SCE_GIT_COMMIT");
44+
45+
if let Ok(commit) = env::var("SCE_GIT_COMMIT") {
46+
let commit = commit.trim();
47+
if !commit.is_empty() {
48+
println!("cargo:rustc-env=SCE_GIT_COMMIT={commit}");
49+
return;
50+
}
51+
}
52+
53+
let manifest_dir = match env::var("CARGO_MANIFEST_DIR") {
54+
Ok(value) => PathBuf::from(value),
55+
Err(_) => return,
56+
};
57+
58+
let repository_root = match manifest_dir.parent() {
59+
Some(path) => path.to_path_buf(),
60+
None => return,
61+
};
62+
63+
let git_dir = repository_root.join(".git");
64+
println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display());
65+
println!(
66+
"cargo:rerun-if-changed={}",
67+
git_dir.join("packed-refs").display()
68+
);
69+
70+
let output = Command::new("git")
71+
.args(["rev-parse", "--short=12", "HEAD"])
72+
.current_dir(&repository_root)
73+
.output();
74+
75+
let Ok(output) = output else {
76+
return;
77+
};
78+
79+
if !output.status.success() {
80+
return;
81+
}
82+
83+
let Ok(commit) = String::from_utf8(output.stdout) else {
84+
return;
85+
};
86+
87+
let commit = commit.trim();
88+
if !commit.is_empty() {
89+
println!("cargo:rustc-env=SCE_GIT_COMMIT={commit}");
90+
}
3791
}
3892

3993
fn generate_embedded_asset_manifest() -> io::Result<()> {

cli/flake.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
};
3030

3131
version = pkgs.lib.strings.trim (builtins.readFile "${src}/.version");
32+
gitCommit =
33+
if self ? rev then
34+
self.rev
35+
else if self ? dirtyRev then
36+
self.dirtyRev
37+
else
38+
"unknown";
39+
shortGitCommit = builtins.substring 0 12 gitCommit;
3240

3341
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
3442
extensions = [
@@ -47,6 +55,7 @@
4755
inherit version;
4856
inherit src;
4957
sourceRoot = "source/cli";
58+
SCE_GIT_COMMIT = shortGitCommit;
5059

5160
cargoLock = {
5261
lockFile = ./Cargo.lock;
@@ -80,6 +89,7 @@
8089
inherit version;
8190
inherit src;
8291
sourceRoot = "source/cli";
92+
SCE_GIT_COMMIT = shortGitCommit;
8393

8494
cargoLock = {
8595
lockFile = ./Cargo.lock;
@@ -111,6 +121,7 @@
111121
inherit version;
112122
inherit src;
113123
sourceRoot = "source/cli";
124+
SCE_GIT_COMMIT = shortGitCommit;
114125

115126
cargoLock = {
116127
lockFile = ./Cargo.lock;

0 commit comments

Comments
 (0)