PegBoard

Struct PegBoard 

Source
pub struct PegBoard { /* private fields */ }
Expand description

PegBoard manages tool registration and their associated MCP services with namespace support.

§Namespace and Tool Name Prefixing

When MCP services are registered with a namespace, their tool names are automatically prefixed to avoid conflicts. For example:

  • Service “web_search” with tool “search” becomes “web_search-search”
  • Service “file_search” with tool “search” becomes “file_search-search”

The Tool’s name field is modified to include the prefix, so when tools are sent to the LLM, they have unique names. The PegBoard maintains the mapping between prefixed names and original names for routing tool calls back to the correct service.

§Thread Safety

PegBoard is designed for concurrent access and internally uses Arc for cheap cloning. It uses DashMap for all internal storage, providing lock-free concurrent access. All methods use &self and can be called concurrently from multiple threads/tasks. Simply clone the PegBoard to share it across async tasks.

§Example

let pegboard = PegBoard::new();
let pegboard_clone = pegboard.clone(); // Cheap Arc clone

Implementations§

Source§

impl PegBoard

Source

pub fn new() -> Self

Creates a new empty PegBoard

Source

pub async fn add_service( &self, mcp_id: String, namespace: Option<String>, service: RunningService<RoleClient, Box<dyn DynService<RoleClient>>>, ) -> Result<(), PegBoardError>

Registers a service and automatically discovers all its tools.

See InternalPegBoard::add_service for full documentation.

Source

pub fn register_tool( &self, namespace: Option<&str>, tool: Tool, service_id: &str, ) -> Result<(), PegBoardError>

Manually registers a tool with an optional namespace and service ID.

Source

pub fn get_tool(&self, tool_name: &str) -> Option<Tool>

Gets a tool by its name (prefixed if registered with namespace, original otherwise)

Source

pub fn select_tools(&self, tool_names: &[&str]) -> Option<Vec<Tool>>

Selects multiple tools by their names.

Source

pub fn get_tool_route(&self, tool_name: &str) -> Option<(String, String)>

Gets routing information for a tool by its name

Source

pub fn list_tools_in_namespace(&self, namespace: &str) -> Vec<String>

Gets all tool names in a namespace (prefixed if namespace was used)

Source

pub fn get_tools_in_namespace(&self, namespace: &str) -> Vec<Tool>

Gets all Tool objects in a namespace (with names as they appear to LLM)

Source

pub fn list_all_tools(&self) -> Vec<String>

Gets all registered tool names across all namespaces

Source

pub fn get_all_tools(&self) -> Vec<Tool>

Gets all tools as a Vec

Source

pub fn list_namespaces(&self) -> Vec<String>

Gets all registered namespaces

Source

pub fn unregister_tool(&self, prefixed_name: &str) -> Result<(), PegBoardError>

Removes a tool by its prefixed name

Source

pub fn unregister_namespace( &self, namespace: &str, ) -> Result<usize, PegBoardError>

Removes all tools in a namespace and the associated service

Source

pub fn unregister_service( &self, service_id: &str, ) -> Result<usize, PegBoardError>

Removes a service by its ID and all associated tools

Source

pub fn tool_count(&self) -> usize

Returns the number of registered tools

Source

pub fn service_count(&self) -> usize

Returns the number of registered services

Source

pub fn namespace_count(&self) -> usize

Returns the number of registered namespaces

Source

pub async fn call_tool( &self, tool_name: &str, arguments: Value, ) -> Result<CallToolResult, PegBoardError>

Calls a tool by its name (as seen by the LLM) with the given arguments.

Source

pub fn register_tool_discovery( &self, tool_name: &str, related_tools: Vec<String>, )

Registers a tool discovery relationship.

Source

pub fn discover_tool(&self, tool_name: &str) -> Vec<Tool>

Discovers related tools for a given tool name.

Source

pub fn register_mcp_discovery(&self, mcp_id: &str, related_mcps: Vec<String>)

Registers an MCP discovery relationship.

Source

pub fn discover_mcp(&self, mcp_id: &str) -> Vec<String>

Discovers related MCP IDs for a given MCP ID.

Trait Implementations§

Source§

impl Clone for PegBoard

Source§

fn clone(&self) -> PegBoard

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for PegBoard

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more