pub struct GrokTool {
pub tool_type: GrokToolType,
pub allowed_domains: Option<Vec<String>>,
pub from_date: Option<String>,
pub to_date: Option<String>,
pub collection_ids: Option<Vec<String>>,
pub server_url: Option<String>,
}Expand description
Represents a server-side tool available in xAI’s Agent Tools API.
xAI provides agentic server-side tool calling where the model autonomously explores, searches, and executes code. The server handles the entire reasoning and tool-execution loop.
§Supported Models
grok-4-1-fast(recommended for agentic tool calling)grok-4-1-fast-non-reasoninggrok-4,grok-4-fast,grok-4-fast-non-reasoning
§Example
use openai_rust2::chat::GrokTool;
let tools = vec![
GrokTool::web_search(),
GrokTool::x_search(),
GrokTool::code_execution(),
GrokTool::collections_search(vec!["collection-id-1".into()]),
GrokTool::mcp("https://my-mcp-server.com".into()),
];Fields§
§tool_type: GrokToolTypeThe type of tool: “web_search”, “x_search”, “code_execution”, “collections_search”, “mcp”
allowed_domains: Option<Vec<String>>Restrict web search to specific domains (max 5). Only applies to web_search.
from_date: Option<String>Inclusive start date for search results (ISO8601: YYYY-MM-DD). Applies to web_search and x_search.
to_date: Option<String>Inclusive end date for search results (ISO8601: YYYY-MM-DD). Applies to web_search and x_search.
collection_ids: Option<Vec<String>>Collection IDs to search. Required for collections_search tool.
server_url: Option<String>MCP server URL. Required for mcp tool.
Implementations§
Source§impl GrokTool
impl GrokTool
Sourcepub fn web_search() -> Self
pub fn web_search() -> Self
Create a web_search tool with default settings. Allows the agent to search the web and browse pages.
Sourcepub fn x_search() -> Self
pub fn x_search() -> Self
Create an x_search tool with default settings. Allows the agent to search X posts, users, and threads.
Sourcepub fn code_execution() -> Self
pub fn code_execution() -> Self
Create a code_execution tool. Allows the agent to execute Python code for calculations and data analysis.
Sourcepub fn collections_search(collection_ids: Vec<String>) -> Self
pub fn collections_search(collection_ids: Vec<String>) -> Self
Create a collections_search tool with the specified collection IDs. Allows the agent to search through uploaded knowledge bases.
Sourcepub fn mcp(server_url: String) -> Self
pub fn mcp(server_url: String) -> Self
Create an MCP tool connecting to an external MCP server. Allows the agent to access custom tools from the specified server.
Sourcepub fn with_allowed_domains(self, domains: Vec<String>) -> Self
pub fn with_allowed_domains(self, domains: Vec<String>) -> Self
Restrict web search to specific domains (max 5). Only applies to web_search tool.