Skip to main content

McpService

Trait McpService 

Source
pub trait McpService: Send + Sync {
    // Required methods
    fn list_tools(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ToolDefinition>, McpError>> + Send + '_>>;
    fn call_tool(
        &self,
        name: &str,
        args: Value,
    ) -> Pin<Box<dyn Future<Output = Result<String, McpError>> + Send + '_>>;
}
Expand description

Minimal contract for MCP-like tool sources.

Implement this trait to bridge any MCP client library with llm-core’s tool system. The trait requires only two operations:

  1. List available tools (with their schemas)
  2. Call a tool by name with JSON arguments

§Thread Safety

Implementations must be Send + Sync to allow use across async tasks. Typically achieved by wrapping the underlying client in Arc.

§Object Safety

This trait is object-safe (dyn McpService) to allow storing different MCP service implementations in the same registry.

Required Methods§

Source

fn list_tools( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ToolDefinition>, McpError>> + Send + '_>>

Lists all tools available from the MCP server.

Source

fn call_tool( &self, name: &str, args: Value, ) -> Pin<Box<dyn Future<Output = Result<String, McpError>> + Send + '_>>

Calls a tool on the MCP server.

§Arguments
  • name - The name of the tool to call
  • args - JSON arguments matching the tool’s input schema
§Returns

The tool’s text output, or an error if execution failed.

Implementors§