Skip to main content

McpService

Trait McpService 

Source
pub trait McpService<Counterpart: Role>:
    Send
    + Sync
    + 'static {
    // Required method
    fn execute(
        &self,
        request: McpRequest,
        context: McpRequestContext<Counterpart>,
    ) -> BoxFuture<'static, Result<McpOutcome, Error>>;

    // Provided method
    fn admit(
        &self,
        request: McpAdmission,
    ) -> BoxFuture<'static, Result<(), McpRejection>> { ... }
}
Available on crate feature unstable_mcp_over_acp only.
Expand description

Reusable MCP application state with owned invocation futures.

Required Methods§

Source

fn execute( &self, request: McpRequest, context: McpRequestContext<Counterpart>, ) -> BoxFuture<'static, Result<McpOutcome, Error>>

Execute one invocation, including backend teardown.

On operation cancellation, stop user work and complete owned cleanup before returning. The binding drives this future through cancellation; dropping it is not used as a substitute for joining cleanup.

§Errors

An Err from an operation that ran to its end is reported to the Agent as an MCP backend failure (-33002) with the error’s text as data, whatever the error’s own code is. To answer Invalid params (-32602) for a missing or refused session, reject the request before it runs, in admit or with McpServer::with_admission.

Provided Methods§

Source

fn admit( &self, request: McpAdmission, ) -> BoxFuture<'static, Result<(), McpRejection>>

Decides, before execute is called, whether a request is admitted. The default admits every request.

The SDK awaits it after the checks the server was given with McpServer::with_admission, and answers a rejection the same way: with the outer ACP error Invalid params (-32602), without calling execute. A service built from a tool registry uses it to apply the rule of the tool a tools/call request names.

The SDK drops the returned future when the request is cancelled, its server registration is removed, or the connection shuts down. It must not own work that needs cleanup.

§Errors

The future returns the McpRejection that answers a request the service does not admit.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§