Skip to content

Commit 02c92f5

Browse files
committed
feat: add ureq dependency and implement Qdrant Docker management in main function. This update includes a new function to ensure Qdrant is running via Docker, checking its status and starting the container if necessary, enhancing the application's setup process.
1 parent 4fe869c commit 02c92f5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ serial_test = "3.1.1"
4646
mockall = "0.12"
4747
flate2 = "1.1.1"
4848
reqwest = { version = "0.11", features = ["blocking"] }
49+
ureq = "2"
4950

5051
[dev-dependencies]
5152
# From application

src/main.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ use qdrant_client::qdrant::{ScoredPoint, PointStruct};
3838
// Import BoxFuture for mock impl signature
3939
use futures::future::BoxFuture;
4040

41+
use std::time::Duration;
42+
use std::thread::sleep;
43+
4144
const PREBUILT_INDEX_URL: &str = "https://github.com/metacontract/mc-mcp/releases/latest/download/prebuilt_index.jsonl.gz";
4245
const PREBUILT_INDEX_DEST: &str = "artifacts/prebuilt_index.jsonl.gz";
4346

4447
#[tokio::main]
4548
async fn main() -> Result<()> {
49+
// Qdrant起動確認(Docker経由)
50+
if let Err(e) = ensure_qdrant_via_docker() {
51+
eprintln!("{e}");
52+
std::process::exit(1);
53+
}
4654
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
4755
log::info!("mc-mcp server (MCP over stdio) started.");
4856

@@ -475,3 +483,48 @@ mod tests {
475483
};
476484
}
477485
}
486+
487+
fn ensure_qdrant_via_docker() -> Result<(), String> {
488+
// 1. Check if Docker is installed
489+
let docker_check = std::process::Command::new("docker").arg("--version").output();
490+
if docker_check.is_err() {
491+
return Err("Docker is not installed".to_string());
492+
}
493+
494+
// 2. Check if Qdrant container is already running
495+
let ps = std::process::Command::new("docker")
496+
.args(["ps", "--filter", "name=qdrant", "--format", "{{.Names}}"])
497+
.output()
498+
.map_err(|e| format!("Failed to execute docker ps: {e}"))?;
499+
let ps_stdout = String::from_utf8_lossy(&ps.stdout);
500+
if ps_stdout.contains("qdrant") {
501+
println!("✅ Qdrant is already running in Docker.");
502+
} else {
503+
// 3. Start Qdrant container
504+
println!("Qdrant container not found. Starting Qdrant in Docker...");
505+
let run = std::process::Command::new("docker")
506+
.args(["run", "-d", "--name", "qdrant", "-p", "6333:6333", "-p", "6334:6334", "qdrant/qdrant"])
507+
.output()
508+
.map_err(|e| format!("Failed to execute docker run: {e}"))?;
509+
if !run.status.success() {
510+
return Err(format!("Failed to start Qdrant container: {}", String::from_utf8_lossy(&run.stderr)));
511+
}
512+
println!("Qdrant container started.");
513+
}
514+
515+
// 4. Health check (HTTP endpoint retry)
516+
let endpoint = "http://localhost:6333/collections";
517+
for i in 1..=5 {
518+
match ureq::get(endpoint).timeout(std::time::Duration::from_millis(1000)).call() {
519+
Ok(resp) if resp.status() == 200 => {
520+
println!("✅ Qdrant is running and connected!");
521+
return Ok(());
522+
}
523+
_ => {
524+
println!("Waiting for Qdrant to start... (Retry {i}/5)");
525+
sleep(Duration::from_secs(2));
526+
}
527+
}
528+
}
529+
Err("Failed to connect to Qdrant. Check Docker and network settings.".to_string())
530+
}

0 commit comments

Comments
 (0)