Skip to main content

McpServerConnect

Trait McpServerConnect 

Source
pub trait McpServerConnect<Counterpart: Role>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> String;
    fn connect(&self, cx: McpConnectionTo<Counterpart>) -> DynConnectTo<Client>;
}
Expand description

Trait for types that can create MCP server connections.

Implement this trait to create custom MCP servers. Each call to connect should return a new ConnectTo that serves MCP requests for a single connection.

§Example

ⓘ
use agent_client_protocol::mcp_server::{McpServerConnect, McpConnectionTo};
use agent_client_protocol::{DynConnectTo, role::Role};

struct MyMcpServer {
    name: String,
}

impl<R: Role> McpServerConnect<R> for MyMcpServer {
    fn name(&self) -> String {
        self.name.clone()
    }

    fn connect(&self, cx: McpConnectionTo<R>) -> DynConnectTo<role::mcp::Client> {
        // Create and return a component that handles MCP requests
        DynConnectTo::new(MyMcpComponent::new(cx))
    }
}

Required Methods§

Source

fn name(&self) -> String

The name of the MCP server, used in ACP declarations when attached.

Source

fn connect(&self, cx: McpConnectionTo<Counterpart>) -> DynConnectTo<Client>

Create a component to service a standalone connection or a native operation.

Standalone serving invokes this factory once per connection. Native ACP invokes it independently for each mcp/message operation. A native component receives an MCP 2026-07-28 request directly; it must not wait for initialize or share protocol state with a previous operation. Prefer McpService for reusable native application services.

Any communication primitives shared with the server’s RunWithConnectionTo task must be created before the McpServer is returned. The runner has no separate readiness protocol and may continue asynchronous initialization while connections and their messages are queued.

McpConnectionTo distinguishes a direct MCP connection from an ACP-attached operation and provides the corresponding host connection.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<Counterpart: Role, S: ?Sized + McpServerConnect<Counterpart>> McpServerConnect<Counterpart> for Arc<S>

Source§

fn name(&self) -> String

Source§

fn connect(&self, cx: McpConnectionTo<Counterpart>) -> DynConnectTo<Client>

Source§

impl<Counterpart: Role, S: ?Sized + McpServerConnect<Counterpart>> McpServerConnect<Counterpart> for Box<S>

Source§

fn name(&self) -> String

Source§

fn connect(&self, cx: McpConnectionTo<Counterpart>) -> DynConnectTo<Client>

Implementors§