pub struct TestServerBuilder { /* private fields */ }Expand description
Builder for creating test servers with real handlers.
Creates servers that communicate via MemoryTransport for
in-process testing without subprocess spawning.
§Example
ⓘ
use fastmcp_rust::testing::prelude::*;
// Create a simple test server
let (router, client_transport, server_transport) = TestServer::builder()
.with_name("test-server")
.build();
// Use client_transport to communicate with serverImplementations§
Source§impl TestServerBuilder
impl TestServerBuilder
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Sets the server version.
Sourcepub fn with_request_timeout(self, secs: u64) -> Self
pub fn with_request_timeout(self, secs: u64) -> Self
Sets the request timeout in seconds.
Sourcepub fn build(self) -> (Router, MemoryTransport, MemoryTransport)
pub fn build(self) -> (Router, MemoryTransport, MemoryTransport)
Builds the test server and returns it with a client transport.
Returns a tuple of:
Router: The configured router (use with server run loop)MemoryTransport: Client-side transport for sending requestsMemoryTransport: Server-side transport for the server run loop
§Example
ⓘ
let (router, client_transport, server_transport) = TestServer::builder()
.build();
// Run server in a background thread (omitted here). Prefer using the
// higher-level E2E harness helpers in this crate which join threads on drop.
// Use client_transport for testingSourcepub fn build_server_builder(
self,
) -> (ServerBuilder, MemoryTransport, MemoryTransport)
pub fn build_server_builder( self, ) -> (ServerBuilder, MemoryTransport, MemoryTransport)
Builds a full ServerBuilder for more control.
Use this when you need access to the full server builder API.
§Example
ⓘ
let (builder, client_transport, server_transport) = TestServer::builder()
.build_server_builder();
// Customize further with the real server builder
let server = builder
.instructions("Test server")
.build();Trait Implementations§
Auto Trait Implementations§
impl Freeze for TestServerBuilder
impl RefUnwindSafe for TestServerBuilder
impl Send for TestServerBuilder
impl Sync for TestServerBuilder
impl Unpin for TestServerBuilder
impl UnwindSafe for TestServerBuilder
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).