Skip to content

Commit dd74425

Browse files
authored
Mcp enablement squashed (#1327)
1 parent acdf605 commit dd74425

File tree

28 files changed

+4055
-137
lines changed

28 files changed

+4055
-137
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ indicatif = "0.17.11"
8686
indoc = "2.0.6"
8787
insta = "1.42.2"
8888
libc = "0.2.171"
89+
mcp_client = { path = "crates/mcp_client" }
8990
mimalloc = "0.1.46"
9091
nix = { version = "0.29.0", features = [
9192
"feature",
@@ -123,6 +124,7 @@ reqwest = { version = "0.12.14", default-features = false, features = [
123124
] }
124125
ring = "0.17.14"
125126
rusqlite = { version = "0.32.1", features = ["bundled", "serde_json"] }
127+
shellexpand = "3.0.0"
126128
shell-color = { path = "crates/shell-color" }
127129
semver = { version = "1.0.26", features = ["serde"] }
128130
serde = { version = "1.0.219", features = ["derive", "rc"] }

crates/fig_desktop/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ rfd = "0.15.1"
7575
semver.workspace = true
7676
serde.workspace = true
7777
serde_json.workspace = true
78-
shellexpand = "3.1.1"
78+
shellexpand.workspace = true
7979
sysinfo.workspace = true
8080
tao = { version = "0.31.1", features = ["serde"] }
8181
tempfile.workspace = true

crates/fig_desktop_api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fig_util.workspace = true
3030
fnv = "1.0.7"
3131
serde.workspace = true
3232
serde_json.workspace = true
33-
shellexpand = "3.1.1"
33+
shellexpand.workspace = true
3434
thiserror.workspace = true
3535
tokio.workspace = true
3636
tracing.workspace = true

crates/fig_log/src/lib.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct LogArgs<T: AsRef<Path>> {
5353
pub struct LogGuard {
5454
_file_guard: Option<WorkerGuard>,
5555
_stdout_guard: Option<WorkerGuard>,
56+
_mcp_file_guard: Option<WorkerGuard>,
5657
}
5758

5859
/// Initialize our application level logging using the given LogArgs.
@@ -65,6 +66,7 @@ pub fn initialize_logging<T: AsRef<Path>>(args: LogArgs<T>) -> Result<LogGuard,
6566
let filter_layer = create_filter_layer();
6667
let (reloadable_filter_layer, reloadable_handle) = tracing_subscriber::reload::Layer::new(filter_layer);
6768
ENV_FILTER_RELOADABLE_HANDLE.lock().unwrap().replace(reloadable_handle);
69+
let mut mcp_path = None;
6870

6971
// First we construct the file logging layer if a file name was provided.
7072
let (file_layer, _file_guard) = match args.log_file_path {
@@ -73,6 +75,9 @@ pub fn initialize_logging<T: AsRef<Path>>(args: LogArgs<T>) -> Result<LogGuard,
7375

7476
// Make the log path parent directory if it doesn't exist.
7577
if let Some(parent) = log_path.parent() {
78+
if log_path.ends_with("chat.log") {
79+
mcp_path = Some(parent.to_path_buf());
80+
}
7681
std::fs::create_dir_all(parent)?;
7782
}
7883

@@ -119,20 +124,63 @@ pub fn initialize_logging<T: AsRef<Path>>(args: LogArgs<T>) -> Result<LogGuard,
119124
(None, None)
120125
};
121126

127+
// Set up for mcp servers layer if we are in chat
128+
let (mcp_server_layer, _mcp_file_guard) = if let Some(parent) = mcp_path {
129+
let mcp_path = parent.join("mcp.log");
130+
if args.delete_old_log_file {
131+
std::fs::remove_file(&mcp_path).ok();
132+
} else if mcp_path.exists() && std::fs::metadata(&mcp_path)?.len() > MAX_FILE_SIZE {
133+
std::fs::remove_file(&mcp_path)?;
134+
}
135+
let file = if args.delete_old_log_file {
136+
File::create(&mcp_path)?
137+
} else {
138+
File::options().append(true).create(true).open(&mcp_path)?
139+
};
140+
#[cfg(unix)]
141+
{
142+
use std::os::unix::fs::PermissionsExt;
143+
if let Ok(metadata) = file.metadata() {
144+
let mut permissions = metadata.permissions();
145+
permissions.set_mode(0o600);
146+
file.set_permissions(permissions).ok();
147+
}
148+
}
149+
let (non_blocking, guard) = tracing_appender::non_blocking(file);
150+
let file_layer = fmt::layer()
151+
.with_line_number(true)
152+
.with_writer(non_blocking)
153+
.with_filter(EnvFilter::new("mcp=trace"));
154+
(Some(file_layer), Some(guard))
155+
} else {
156+
(None, None)
157+
};
158+
122159
if let Some(level) = args.log_level {
123160
set_log_level(level)?;
124161
}
125162

126163
// Finally, initialize our logging
127-
tracing_subscriber::registry()
164+
let subscriber = tracing_subscriber::registry()
128165
.with(reloadable_filter_layer)
129166
.with(file_layer)
130-
.with(stdout_layer)
131-
.init();
167+
.with(stdout_layer);
168+
169+
if let Some(mcp_server_layer) = mcp_server_layer {
170+
subscriber.with(mcp_server_layer).init();
171+
return Ok(LogGuard {
172+
_file_guard,
173+
_stdout_guard,
174+
_mcp_file_guard,
175+
});
176+
}
177+
178+
subscriber.init();
132179

133180
Ok(LogGuard {
134181
_file_guard,
135182
_stdout_guard,
183+
_mcp_file_guard,
136184
})
137185
}
138186

crates/figterm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ semver.workspace = true
5555
serde.workspace = true
5656
serde_json.workspace = true
5757
shell-color.workspace = true
58-
shellexpand = "3.1.1"
58+
shell-words = "1.1"
59+
shellexpand.workspace = true
5960
shlex.workspace = true
6061
sysinfo.workspace = true
6162
time.workspace = true

crates/mcp_client/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "mcp_client"
3+
authors.workspace = true
4+
edition.workspace = true
5+
homepage.workspace = true
6+
publish.workspace = true
7+
version.workspace = true
8+
license.workspace = true
9+
10+
[lints]
11+
workspace = true
12+
13+
[features]
14+
default = []
15+
16+
[[bin]]
17+
name = "test_mcp_server"
18+
path = "test_mcp_server/test_server.rs"
19+
test = true
20+
doc = false
21+
22+
[dependencies]
23+
tokio.workspace = true
24+
serde.workspace = true
25+
serde_json.workspace = true
26+
async-trait.workspace = true
27+
tracing.workspace = true
28+
thiserror.workspace = true
29+
uuid.workspace = true
30+
nix.workspace = true

0 commit comments

Comments
 (0)