pub struct TestMcpToolContext {
pub auth: AuthContext,
pub request: RequestMetadata,
/* private fields */
}Expand description
Test context for MCP tool functions.
Provides an isolated testing environment for MCP tools with configurable authentication, mock HTTP, and mock job/workflow dispatch.
§Example
ⓘ
let ctx = TestMcpToolContext::builder()
.as_user(Uuid::new_v4())
.with_role("admin")
.build();
// Dispatch a job
ctx.dispatch_job("process_event", payload).await?;
// Verify job was dispatched
ctx.job_dispatch().assert_dispatched("process_event");Fields§
§auth: AuthContextAuthentication context.
request: RequestMetadataRequest metadata.
Implementations§
Source§impl TestMcpToolContext
impl TestMcpToolContext
Sourcepub fn builder() -> TestMcpToolContextBuilder
pub fn builder() -> TestMcpToolContextBuilder
Create a new builder.
Sourcepub fn minimal() -> TestMcpToolContext
pub fn minimal() -> TestMcpToolContext
Create a minimal unauthenticated context (no database).
Sourcepub fn authenticated(user_id: Uuid) -> TestMcpToolContext
pub fn authenticated(user_id: Uuid) -> TestMcpToolContext
Create an authenticated context with the given user ID (no database).
Sourcepub fn user_id(&self) -> Result<Uuid, ForgeError>
pub fn user_id(&self) -> Result<Uuid, ForgeError>
Get the authenticated user’s UUID. Returns 401 if not authenticated.
Sourcepub fn job_dispatch(&self) -> &MockJobDispatch
pub fn job_dispatch(&self) -> &MockJobDispatch
Get the mock job dispatch for verification.
Sourcepub fn workflow_dispatch(&self) -> &MockWorkflowDispatch
pub fn workflow_dispatch(&self) -> &MockWorkflowDispatch
Get the mock workflow dispatch for verification.
Sourcepub async fn dispatch_job<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
pub async fn dispatch_job<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
Dispatch a job (records for later verification).
Sourcepub async fn start_workflow<T>(
&self,
workflow_name: &str,
input: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
pub async fn start_workflow<T>(
&self,
workflow_name: &str,
input: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
Start a workflow (records for later verification).
Sourcepub fn env_mock(&self) -> &MockEnvProvider
pub fn env_mock(&self) -> &MockEnvProvider
Get the mock env provider for verification.
Trait Implementations§
Source§impl EnvAccess for TestMcpToolContext
impl EnvAccess for TestMcpToolContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Get the environment provider.
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Get an environment variable with a default value. Read more
Source§fn env_require(&self, key: &str) -> Result<String, ForgeError>
fn env_require(&self, key: &str) -> Result<String, ForgeError>
Get a required environment variable. Read more
Source§fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
Get an environment variable and parse it to the specified type. Read more
Source§fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
Get an environment variable and parse it, with a default. Read more
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
Check if an environment variable is set.
Auto Trait Implementations§
impl Freeze for TestMcpToolContext
impl !RefUnwindSafe for TestMcpToolContext
impl Send for TestMcpToolContext
impl Sync for TestMcpToolContext
impl Unpin for TestMcpToolContext
impl UnsafeUnpin for TestMcpToolContext
impl !UnwindSafe for TestMcpToolContext
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> 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>
Converts
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>
Converts
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 more