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 cloneImplementations§
Source§impl PegBoard
impl PegBoard
Sourcepub async fn add_service(
&self,
mcp_id: String,
namespace: Option<String>,
service: RunningService<RoleClient, Box<dyn DynService<RoleClient>>>,
) -> Result<(), PegBoardError>
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.
Sourcepub fn register_tool(
&self,
namespace: Option<&str>,
tool: Tool,
service_id: &str,
) -> Result<(), PegBoardError>
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.
Sourcepub fn get_tool(&self, tool_name: &str) -> Option<Tool>
pub fn get_tool(&self, tool_name: &str) -> Option<Tool>
Gets a tool by its name (prefixed if registered with namespace, original otherwise)
Sourcepub fn select_tools(&self, tool_names: &[&str]) -> Option<Vec<Tool>>
pub fn select_tools(&self, tool_names: &[&str]) -> Option<Vec<Tool>>
Selects multiple tools by their names.
Sourcepub fn get_tool_route(&self, tool_name: &str) -> Option<(String, String)>
pub fn get_tool_route(&self, tool_name: &str) -> Option<(String, String)>
Gets routing information for a tool by its name
Sourcepub fn list_tools_in_namespace(&self, namespace: &str) -> Vec<String>
pub fn list_tools_in_namespace(&self, namespace: &str) -> Vec<String>
Gets all tool names in a namespace (prefixed if namespace was used)
Sourcepub fn get_tools_in_namespace(&self, namespace: &str) -> Vec<Tool>
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)
Sourcepub fn list_all_tools(&self) -> Vec<String>
pub fn list_all_tools(&self) -> Vec<String>
Gets all registered tool names across all namespaces
Sourcepub fn get_all_tools(&self) -> Vec<Tool>
pub fn get_all_tools(&self) -> Vec<Tool>
Gets all tools as a Vec
Sourcepub fn list_namespaces(&self) -> Vec<String>
pub fn list_namespaces(&self) -> Vec<String>
Gets all registered namespaces
Sourcepub fn unregister_tool(&self, prefixed_name: &str) -> Result<(), PegBoardError>
pub fn unregister_tool(&self, prefixed_name: &str) -> Result<(), PegBoardError>
Removes a tool by its prefixed name
Sourcepub fn unregister_namespace(
&self,
namespace: &str,
) -> Result<usize, PegBoardError>
pub fn unregister_namespace( &self, namespace: &str, ) -> Result<usize, PegBoardError>
Removes all tools in a namespace and the associated service
Sourcepub fn unregister_service(
&self,
service_id: &str,
) -> Result<usize, PegBoardError>
pub fn unregister_service( &self, service_id: &str, ) -> Result<usize, PegBoardError>
Removes a service by its ID and all associated tools
Sourcepub fn tool_count(&self) -> usize
pub fn tool_count(&self) -> usize
Returns the number of registered tools
Sourcepub fn service_count(&self) -> usize
pub fn service_count(&self) -> usize
Returns the number of registered services
Sourcepub fn namespace_count(&self) -> usize
pub fn namespace_count(&self) -> usize
Returns the number of registered namespaces
Sourcepub async fn call_tool(
&self,
tool_name: &str,
arguments: Value,
) -> Result<CallToolResult, PegBoardError>
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.
Sourcepub fn register_tool_discovery(
&self,
tool_name: &str,
related_tools: Vec<String>,
)
pub fn register_tool_discovery( &self, tool_name: &str, related_tools: Vec<String>, )
Registers a tool discovery relationship.
Sourcepub fn discover_tool(&self, tool_name: &str) -> Vec<Tool>
pub fn discover_tool(&self, tool_name: &str) -> Vec<Tool>
Discovers related tools for a given tool name.
Sourcepub fn register_mcp_discovery(&self, mcp_id: &str, related_mcps: Vec<String>)
pub fn register_mcp_discovery(&self, mcp_id: &str, related_mcps: Vec<String>)
Registers an MCP discovery relationship.
Sourcepub fn discover_mcp(&self, mcp_id: &str) -> Vec<String>
pub fn discover_mcp(&self, mcp_id: &str) -> Vec<String>
Discovers related MCP IDs for a given MCP ID.