pub struct ServerBuilder { /* private fields */ }server only.Expand description
Builder for constructing an ADK server with custom routes.
ServerBuilder allows registering additional Axum routers alongside the
built-in REST, A2A, and UI routes. Custom routes benefit from the same
middleware stack (auth, CORS, tracing, timeout, security headers) as the
built-in routes.
§Example
use adk_server::{ServerBuilder, ServerConfig};
use axum::{Router, routing::get};
let config = ServerConfig::new(agent, session_service);
let app = ServerBuilder::new(config)
.add_api_routes(
Router::new()
.route("/projects", get(list_projects))
.route("/projects/{id}", get(get_project))
)
.add_api_routes(
Router::new()
.route("/automations", get(list_automations))
)
.with_a2a("http://localhost:8080")
.build();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
axum::serve(listener, app).await?;Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn new(config: ServerConfig) -> ServerBuilder
pub fn new(config: ServerConfig) -> ServerBuilder
Create a new server builder with the given configuration.
Sourcepub fn add_api_routes(self, routes: Router) -> ServerBuilder
pub fn add_api_routes(self, routes: Router) -> ServerBuilder
Sourcepub fn add_root_routes(self, routes: Router) -> ServerBuilder
pub fn add_root_routes(self, routes: Router) -> ServerBuilder
Add custom routes at the root level (not nested under /api).
These routes are merged at the top level of the application, alongside the UI and A2A routes. They receive the full middleware stack (CORS, tracing, timeout, security headers) but NOT the auth middleware.
Use this for routes that need their own auth handling or public endpoints.
Sourcepub fn with_a2a(self, base_url: impl Into<String>) -> ServerBuilder
pub fn with_a2a(self, base_url: impl Into<String>) -> ServerBuilder
Enable A2A protocol support at the specified base URL.
The base URL is used to construct the agent card’s endpoint URL.
Sourcepub fn enable_shutdown_endpoint(self) -> ServerBuilder
pub fn enable_shutdown_endpoint(self) -> ServerBuilder
Enable the POST /api/shutdown endpoint for graceful shutdown.
When enabled, the server exposes a shutdown endpoint that triggers
graceful shutdown: stops accepting new connections, completes in-flight
requests, and then exits. Use build_with_shutdown
to get the ShutdownHandle for wiring into axum::serve().with_graceful_shutdown().
The endpoint is protected by the auth middleware when a
RequestContextExtractor is configured.
Sourcepub fn build(self) -> Router
pub fn build(self) -> Router
Build the final Axum router with all routes and middleware applied.
Sourcepub fn build_with_shutdown(self) -> (Router, ShutdownHandle)
pub fn build_with_shutdown(self) -> (Router, ShutdownHandle)
Build the final Axum router and return a ShutdownHandle.
Use this when enable_shutdown_endpoint() is set.
Pass the handle’s signal to axum::serve().with_graceful_shutdown().
§Example
let (app, shutdown_handle) = ServerBuilder::new(config)
.enable_shutdown_endpoint()
.build_with_shutdown();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
axum::serve(listener, app)
.with_graceful_shutdown(shutdown_handle.signal())
.await?;Auto Trait Implementations§
impl Freeze for ServerBuilder
impl !RefUnwindSafe for ServerBuilder
impl Send for ServerBuilder
impl Sync for ServerBuilder
impl Unpin for ServerBuilder
impl UnsafeUnpin for ServerBuilder
impl !UnwindSafe for ServerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request