openagent-mcp · handler
Declared module signatures, types, configuration, and source documentation.
Source: openagent-sdk/integrations/mcp/rust/src/handler.rs. SHA-256: 90e5087e39d015e22b608bba0f1550506c76121634c4718f0b82463c42463243.
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.
handler::ToolCall
A single inbound tools/call request.
meta carries the request metadata pulled from the MCP envelope —
in particular meta["openagent"]["identity"] is where the auth
envelope lives. The middleware reads it and never modifies it in
place.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
/// The tool name (e.g., `"search_web"`).
pub name: String,
/// JSON arguments the caller supplied.
#[serde(default)]
pub arguments: serde_json::Value,
/// Request metadata. Identity envelope lives at
/// `meta["openagent"]["identity"]`.
#[serde(default)]
pub meta: serde_json::Value
}Source line: 32.
handler::ToolResult
A single outbound tool result. The middleware stamps audit metadata
onto meta after the handler returns.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
/// MCP content blocks (text, image, resource_link, etc).
#[serde(default)]
pub content: serde_json::Value,
/// Optional structured content (the new MCP 2025 field).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub structured_content: Option<serde_json::Value>,
/// Optional `isError` flag for error responses returned via the
/// happy-path channel.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_error: Option<bool>,
/// Result metadata. Audit metadata is stamped here on success.
#[serde(default)]
pub meta: serde_json::Value
}Source line: 47.
handler::ToolResult::text
Build a simple text result with no metadata.
pub fn text(message: impl Into<String>) -> Self;Source line: 65.
handler::RegisteredTool
Description of a registered tool, returned by
[ToolHandler::list_tools].
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisteredTool {
/// Tool name.
pub name: String,
/// Optional description for clients.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>
}Source line: 78.
handler::ToolHandler
The trait every concrete server handler implements. Two methods —
list_tools and call_tool — keep the surface narrow and stable
across MCP SDK versions.
#[async_trait]
pub trait ToolHandler: Send + Sync {
/// Return the tools this handler exposes.
async fn list_tools(&self) -> Vec<RegisteredTool>;
/// Execute a single tool call. Implementations should NOT do any
/// authentication or authorization — that runs in the middleware
/// before this is invoked.
async fn call_tool(&self, call: ToolCall) -> Result<ToolResult, McpAuthError>;
}Source line: 90.
handler::WithOpenAgent
Marker trait — anything that implements [ToolHandler] can be
wrapped via [WithOpenAgent::with_openagent].
pub trait WithOpenAgent: ToolHandler + Sized {
/// Wrap this handler with the OpenAgent middleware.
///
/// ```no_run
/// use openagent_mcp::{Config, InMemoryToolHandler, OpenAgentMiddleware, WithOpenAgent};
/// # use std::sync::Arc;
/// # async fn example(agent: std::sync::Arc<dyn openagent_mcp::Agent>) {
/// let handler = InMemoryToolHandler::new();
/// let middleware = OpenAgentMiddleware::new(Config::new(agent));
/// let authed = handler.with_openagent(middleware);
/// # let _ = authed;
/// # }
/// ```
fn with_openagent(self, middleware: OpenAgentMiddleware) -> WrappedHandler<Self> ;
}Source line: 102.
handler::WrappedHandler
Result of wrapping a [ToolHandler] with [OpenAgentMiddleware].
WrappedHandler itself implements [ToolHandler], so the wrapped
instance is a drop-in replacement for the original — the rest of
your server code keeps working unchanged.
pub struct WrappedHandler<T: ToolHandler + ?Sized> {
}Source line: 130.
handler::InMemoryToolHandler
In-memory test handler. Useful for unit and integration tests of the middleware (and as a tiny example of what a custom handler looks like).
#[derive(Default)]
pub struct InMemoryToolHandler {
}Source line: 173.
handler::InMemoryToolHandler::new
Create an empty handler.
pub fn new() -> Self;Source line: 199.
handler::InMemoryToolHandler::register
Register a tool. The handler closure receives the deserialized
arguments and returns a [ToolResult].
pub async fn register<F, Fut>(
&self,
name: impl Into<String>,
description: Option<&str>,
handler: F,
) where
F: Fn(serde_json::Value) -> Fut + Send + Sync + 'static,
Fut: std::future::Future<Output = Result<ToolResult, McpAuthError>> + Send + 'static,;Source line: 205.