1#![allow(clippy::field_reassign_with_default)]
2#![allow(clippy::result_large_err)]
3
4pub mod auth;
5pub mod client;
6pub mod config;
7pub mod convert;
8pub mod error;
9pub mod oauth;
10pub mod prompts;
11pub mod resources;
12pub mod server;
13pub mod tools;
14pub mod transport;
15
16use config::{AppConfig, Transport};
17
18pub async fn run_server(config: AppConfig) -> error::Result<()> {
20 match config.transport {
21 Transport::Stdio => {
22 tracing::info!("Building Google Drive authenticator...");
24 let hub = auth::build_drive_hub(&config, true).await?;
25 let drive_client = client::DriveClient::new(hub);
26 let server = server::GDriveServer::new(drive_client);
27 transport::serve_stdio(server).await
28 }
29 Transport::Http => {
30 tracing::info!("Building Google Drive MCP server (multi-user mode)...");
33
34 let creds_content = tokio::fs::read_to_string(&config.credentials_file)
36 .await
37 .map_err(|e| {
38 error::GDriveError::OAuth2(format!("Cannot read credentials file: {e}"))
39 })?;
40 let google_config = oauth::parse_google_oauth_config(&creds_content).map_err(
41 |e| {
42 error::GDriveError::OAuth2(format!(
43 "Failed to parse Google OAuth config: {e}"
44 ))
45 },
46 )?;
47 let base_url = format!("http://{}", config.http_addr);
48 let oauth_server = oauth::OAuthServer::new(&base_url, google_config);
49
50 let hyper_client = auth::build_shared_hyper_client()?;
52
53 let placeholder_hub =
55 google_drive3::DriveHub::new(hyper_client.clone(), String::new());
56 let template_server =
57 server::GDriveServer::new(client::DriveClient::new(placeholder_hub));
58
59 transport::serve_http(template_server, hyper_client, oauth_server, &config)
60 .await
61 }
62 }
63}