openagent-mcp · types
Declared module signatures, types, configuration, and source documentation.
Source: openagent-sdk/integrations/mcp/rust/src/types.rs. SHA-256: b7bab88be56f0adcd317993328ebffa29830ff8ac0d6091c5a7baa116c42b086.
This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.
types::Did
A decentralized identifier — typically did:oas:<namespace>:..., but
any format the configured [IdentityVerifier] understands is allowed.
pub type Did = String;Source line: 18.
types::Identity
Identity envelope attached to an outbound MCP tools/call request.
The middleware extracts this from _meta.openagent.identity on the
inbound request. proof is opaque to the middleware — it can be a
signed challenge response, an Arsenal Agent Capability Token, or any
other format the verifier knows how to validate.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Identity {
/// Caller's DID.
pub did: Did,
/// Verifiable proof — opaque to the middleware.
pub proof: String,
/// Optional bearer-style nonce for replay protection.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub nonce: Option<String>,
/// Optional context fields the verifier may use (issuer DID,
/// audience, claimed scopes). Always validated against the verifier
/// policy — never trusted as input.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub context: Option<serde_json::Value>
}Source line: 27.
types::VerifiedIdentity
The result of a successful identity verification. Carries the audit id stamped onto the response, the held scopes, and any verifier claims.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifiedIdentity {
/// Verified DID.
pub did: Did,
/// Scopes the caller actually holds (post-verification).
pub scopes: Vec<String>,
/// Audit identifier echoed back to the caller in the response.
pub audit_id: String,
/// Verifier-issued claims about the caller.
pub claims: serde_json::Value
}Source line: 46.
types::AuditMeta
Audit metadata stamped onto the response _meta.openagent block.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditMeta {
/// Identifier for correlating logs end-to-end.
pub audit_id: String,
/// DID of the caller that was successfully verified.
pub verified_did: Did,
/// Scopes the caller exercised on this call.
pub scopes: Vec<String>
}Source line: 59.
types::IdentityVerifier
The trait every identity verifier implements. Production deployments
will use the verifier from openagent-sdk; tests use the
[crate::handler::InMemoryToolHandler]-friendly fake found in the
tests/ directory.
#[async_trait]
pub trait IdentityVerifier: Send + Sync {
/// Verify the supplied identity envelope and return the resulting
/// [`VerifiedIdentity`]. Implementations MUST be deterministic for a
/// given `(identity, required_scopes)` pair and MUST NOT mutate
/// either argument.
async fn verify(
&self,
identity: &Identity,
required_scopes: &[String],
) -> Result<VerifiedIdentity, McpAuthError>;
}Source line: 73.
types::Agent
Minimal Agent surface used by the middleware.
#[async_trait]
pub trait Agent: Send + Sync {
/// The agent's own DID.
fn did(&self) -> &str;
/// The verifier the agent's MCP server uses to authenticate
/// inbound calls.
fn verifier(&self) -> Arc<dyn IdentityVerifier>;
/// Sign an outbound call so the receiving server can authenticate
/// the agent. Returns the identity envelope to attach to the
/// request `_meta.openagent.identity` field.
async fn sign_request(
&self,
tool_name: &str,
audience: Option<&str>,
) -> Result<Identity, McpAuthError>;
}Source line: 87.
types::ScopeDeriver
Function type that derives the required scopes for a tool from the tool name and arguments.
pub type ScopeDeriver =
Arc<dyn Fn(&str, &serde_json::Value) -> Vec<String> + Send + Sync>;Source line: 107.
types::PreCallHook
Hook fired before the tool body executes.
pub type PreCallHook = Arc<
dyn Fn(&PreCallContext<'_>) -> futures_compat::BoxFuture<'static, ()> + Send + Sync,
>;Source line: 111.
types::PostCallHook
Hook fired after the tool body executes successfully.
pub type PostCallHook = Arc<
dyn Fn(&PostCallContext<'_>) -> futures_compat::BoxFuture<'static, ()> + Send + Sync,
>;Source line: 116.
types::ErrorHook
Hook fired when the auth pipeline or tool body errors.
pub type ErrorHook = Arc<
dyn Fn(&ErrorContext<'_>) -> futures_compat::BoxFuture<'static, ()> + Send + Sync,
>;Source line: 121.
types::PreCallContext
Context passed to a [PreCallHook].
#[derive(Debug)]
pub struct PreCallContext<'a> {
/// The tool name.
pub tool_name: &'a str,
/// Arguments the caller supplied.
pub args: &'a serde_json::Value,
/// The verified identity.
pub identity: &'a VerifiedIdentity
}Source line: 127.
types::PostCallContext
Context passed to a [PostCallHook].
#[derive(Debug)]
pub struct PostCallContext<'a> {
/// The tool name.
pub tool_name: &'a str,
/// Arguments the caller supplied.
pub args: &'a serde_json::Value,
/// The verified identity.
pub identity: &'a VerifiedIdentity,
/// Wall-clock duration of the call, in milliseconds.
pub duration_ms: u128,
/// The successful tool result, after audit metadata stamping.
pub result: &'a serde_json::Value
}Source line: 138.
types::ErrorContext
Context passed to an [ErrorHook].
#[derive(Debug)]
pub struct ErrorContext<'a> {
/// The tool name.
pub tool_name: &'a str,
/// Arguments the caller supplied.
pub args: &'a serde_json::Value,
/// The verified identity, if the auth pipeline got far enough to
/// produce one.
pub identity: Option<&'a VerifiedIdentity>,
/// The error that aborted the call.
pub error: &'a McpAuthError
}Source line: 153.
types::Config
Configuration for the [crate::OpenAgentMiddleware].
#[derive(Clone)]
pub struct Config {
}Source line: 167.
types::Config::new
Create a new config from the agent. All hooks default to none and identity is required.
pub fn new(agent: Arc<dyn Agent>) -> Self;Source line: 196.
types::Config::with_require_scopes
Override the per-tool scope deriver. Defaults to
["mcp:<tool>:invoke"].
pub fn with_require_scopes(mut self, deriver: ScopeDeriver) -> Self;Source line: 211.
types::Config::with_require_identity
Set whether the middleware should reject calls without an
identity envelope. Defaults to true.
pub fn with_require_identity(mut self, require: bool) -> Self;Source line: 218.
types::Config::with_skills_policy
Install a skills policy hook. See [crate::skills].
pub fn with_skills_policy(mut self, policy: SkillsPolicy) -> Self;Source line: 224.
types::Config::with_pre_call
Install a pre-call hook.
pub fn with_pre_call(mut self, hook: PreCallHook) -> Self;Source line: 230.
types::Config::with_post_call
Install a post-call hook.
pub fn with_post_call(mut self, hook: PostCallHook) -> Self;Source line: 236.
types::Config::with_on_error
Install an error hook.
pub fn with_on_error(mut self, hook: ErrorHook) -> Self;Source line: 242.
types::Config::with_extra
Attach an arbitrary metadata field to the config (for observability or custom adapters). Returns the new config.
pub fn with_extra(mut self, key: impl Into<String>, value: serde_json::Value) -> Self;Source line: 249.
types::Config::agent
Borrow the underlying agent.
pub fn agent(&self) -> &Arc<dyn Agent>;Source line: 255.
types::futures_compat
Tiny adapter module so the public API can use boxed futures without
pulling in the full futures crate. Keeping this in-tree avoids a
dependency that has historically caused version conflicts inside the
L1fe ecosystem.
pub mod futures_compat;Source line: 264.
types::futures_compat::BoxFuture
A future that has been boxed onto the heap with a 'static
lifetime. Used by hook signatures.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;Source line: 270.