Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ members = [
"app/buck2_grpc",
"app/buck2_health_check",
"app/buck2_health_check_proto",
"app/buck2_mcp",
"app/buck2_http",
"app/buck2_install_proto",
"app/buck2_interpreter",
Expand Down Expand Up @@ -434,6 +435,7 @@ buck2_host_sharing_proto = { path = "app/buck2_host_sharing_proto" }
buck2_http = { path = "app/buck2_http" }
buck2_install_proto = { path = "app/buck2_install_proto" }
buck2_interpreter = { path = "app/buck2_interpreter" }
buck2_mcp = { path = "app/buck2_mcp" }
buck2_interpreter_for_build = { path = "app/buck2_interpreter_for_build" }
buck2_interpreter_for_build_tests = { path = "app/buck2_interpreter_for_build_tests" }
buck2_miniperf = { path = "app/buck2_miniperf" }
Expand Down
44 changes: 44 additions & 0 deletions app/buck2_mcp/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("@fbcode//buck2:buck_rust_binary.bzl", "buck_rust_binary")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("build_infra")

rust_library(
name = "buck2_mcp",
srcs = glob([
"src/**/*.rs",
]),
test_deps = [
"fbsource//third-party/rust:tempfile",
],
deps = [
"fbsource//third-party/rust:async-trait",
"fbsource//third-party/rust:chrono",
"fbsource//third-party/rust:dirs",
"fbsource//third-party/rust:futures",
"fbsource//third-party/rust:serde",
"fbsource//third-party/rust:serde_json",
"fbsource//third-party/rust:tokio",
"fbsource//third-party/rust:tonic-0-12-3",
"fbsource//third-party/rust:tracing",
"fbsource//third-party/rust:uuid",
"//buck2/app/buck2_cli_proto:buck2_cli_proto",
"//buck2/app/buck2_common:buck2_common",
"//buck2/app/buck2_error:buck2_error",
],
)

buck_rust_binary(
name = "buck2-mcp",
srcs = ["src/bin/buck2-mcp.rs"],
crate = "buck2_mcp_bin",
crate_root = "src/bin/buck2-mcp.rs",
deps = [
":buck2_mcp",
"fbsource//third-party/rust:tokio",
"fbsource//third-party/rust:tracing",
"fbsource//third-party/rust:tracing-subscriber",
"//buck2/app/buck2_error:buck2_error",
"//buck2/app/buck2_fs:buck2_fs",
],
)
35 changes: 35 additions & 0 deletions app/buck2_mcp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "buck2_mcp"
description = "Buck2 MCP (Model Context Protocol) server for AI agent integration"
edition = "2024"
license = { workspace = true }
repository = { workspace = true }
version = "0.1.0"

[[bin]]
name = "buck2-mcp"
path = "src/bin/buck2-mcp.rs"

[dependencies]
async-trait = { workspace = true }
chrono = { workspace = true }
dirs = { workspace = true }
futures = { workspace = true }
prost = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
uuid = { workspace = true }

buck2_cli_proto = { workspace = true }
buck2_common = { workspace = true }
buck2_core = { workspace = true }
buck2_error = { workspace = true }
buck2_fs = { workspace = true }
buck2_util = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
43 changes: 43 additions & 0 deletions app/buck2_mcp/src/bin/buck2-mcp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*/

//! Buck2 MCP server binary entry point.

use std::env;

use tracing::info;
use tracing_subscriber::EnvFilter;

#[tokio::main]
async fn main() -> buck2_error::Result<()> {
// Initialize tracing to stderr (stdout is used for MCP protocol)
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(std::io::stderr)
.init();

info!("Starting Buck2 MCP server");

let working_dir = env::current_dir()
.map_err(|e| {
buck2_error::buck2_error!(
buck2_error::ErrorTag::Environment,
"Failed to get current directory: {}",
e
)
})?
.to_string_lossy()
.to_string();

info!("Working directory: {}", working_dir);

let mut server = buck2_mcp::mcp::server::McpServer::new(working_dir);
server.run().await
}
13 changes: 13 additions & 0 deletions app/buck2_mcp/src/daemon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is dual-licensed under either the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree or the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree. You may select, at your option, one of the
* above-listed licenses.
*/

//! Buck2 daemon client wrapper.

pub mod client;
Loading