Use as a Rust library
Embed Maple Proxy in your own Rust application with the maple-proxy crate. Build a Config, create the axum router, and serve it alongside your code.
The proxy is also a Rust crate, maple-proxy. Embed it when you want the proxy to run inside your own Rust service instead of as a separate process. The Maple desktop app embeds it this way.
Add the crate
[dependencies]
maple-proxy = "0.3.2"
axum = "0.8"
tracing-subscriber = "0.3"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net"] } 0.3.2 is the latest version on crates.io. The proxy source is ahead of it, at 0.4.1, and crate releases are published separately from Maple app releases.
with_cache_namespace_root and the Transport V2 types it uses need 0.4. To use 0.4 before it reaches crates.io, depend on a Maple release tag from git. Cargo finds the maple-proxy package inside the repository:
[dependencies]
maple-proxy = { git = "https://github.com/MaplePrivacyLabs/Maple", tag = "v3.4.3" } Tags are Maple app releases; v3.4.3 contains proxy 0.4.1.
Run it
create_app returns an axum Router with every proxy route. Serve it like any other router:
use maple_proxy::{create_app, Config, Pcr0Environment};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let config = Config::new(
"127.0.0.1".to_string(),
8081,
"https://enclave.trymaple.ai".to_string(),
)
.with_pcr0_environment(Pcr0Environment::Production)
.with_api_key(std::env::var("MAPLE_API_KEY")?)
.with_debug(true);
let app = create_app(config.clone());
let addr = config.socket_addr()?;
let listener = TcpListener::bind(addr).await?;
println!("Maple proxy server running on http://{addr}");
axum::serve(listener, app).await?;
Ok(())
} The repository has this as a runnable example: cargo run --locked --example library_usage from the proxy/ folder.
Config builder
Config::new(host, port, backend_url) starts from the same defaults as the binary: production trust roots, no saved key, CORS off, and 300-second timeouts. Then chain:
| Method | Same as |
|---|---|
with_pcr0_environment(Pcr0Environment::…) | MAPLE_PCR0_ENVIRONMENT |
with_api_key(String) | MAPLE_API_KEY |
with_cors(bool) | MAPLE_ENABLE_CORS |
with_debug(bool) | MAPLE_DEBUG |
with_request_timeout_secs(u64) | MAPLE_REQUEST_TIMEOUT_SECS |
with_stream_idle_timeout_secs(u64) | MAPLE_STREAM_IDLE_TIMEOUT_SECS |
with_cache_namespace_root(…) | MAPLE_CACHE_NAMESPACE_ROOT (0.4 and later) |
Config::load() reads the same environment variables, .env file and flags as the binary.
See configuration for what each setting does.
Keep the SDK versions in step
The proxy’s public API uses types from Maple’s Rust SDK, such as Pcr0Environment. The SDK crate is opensecret for proxy 0.3 and maple-sdk from 0.4. If your application also depends on the SDK directly, use the same crate and version as the proxy, or the types won’t match.