Skip to main content

Parameters

Struct Parameters 

Source
pub struct Parameters(/* private fields */);
Expand description

JSON schema parameters with metadata stripped

Implementations§

Source§

impl Parameters

Source

pub fn from_object(obj: Map<String, Value>) -> Self

Create Parameters from a Json object (map)

Examples found in repository?
examples/mcp.rs (line 39)
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18    // Connect to a server running as a child process
19    let service = ()
20        .serve(TokioChildProcess::new(Command::new("npx").configure(
21            |cmd| {
22                cmd.args(&["-y", "@modelcontextprotocol/server-filesystem", "."]);
23            },
24        ))?)
25        .await?;
26    println!("Connected to MCP server");
27
28    // List available tools and convert to tool definitions
29    let tools = service.list_tools(Default::default()).await?.tools;
30    let names = tools.iter().map(|t| t.name.to_string()).collect::<Vec<_>>();
31    println!("Available tools: {names:#?}");
32    let mcp_tool_defs = tools
33        .iter()
34        .map(|t| ToolDefinition {
35            tool_type: "function".into(),
36            function: ToolFunction {
37                name: t.name.to_string(),
38                description: t.description.as_deref().unwrap_or_default().to_string(),
39                parameters: Parameters::from_object(t.input_schema.as_ref().clone()),
40            },
41        })
42        .collect();
43
44    let mcp_tool_executor = {
45        let peer = service.clone();
46        move |name: String, args: String| {
47            let peer = peer.clone();
48            async move {
49                peer.call_tool(CallToolRequestParams {
50                    meta: None,
51                    name: name.into(),
52                    arguments: serde_json::from_str(&args).unwrap(),
53                    task: None,
54                })
55                .await
56                .unwrap()
57                .content[0]
58                    .as_text()
59                    .unwrap()
60                    .text
61                    .clone()
62            }
63        }
64    };
65
66    let api_key = std::env::var("LLM_API_KEY").expect("LLM_API_KEY not set");
67
68    let llm = OpenAIProvider::new()
69        .api_key(api_key)
70        .base_url("https://openrouter.ai/api/v1")
71        .model("google/gemini-3-flash-preview");
72
73    let agent = Agent::new(llm)
74        .system("You are a helpful assistant")
75        .external(mcp_tool_defs, mcp_tool_executor);
76
77    run_cli_loop(agent).await;
78
79    // Gracefully close the connection
80    service.cancel().await?;
81    Ok(())
82}
Source

pub fn from_schema(schema: Schema) -> Self

Create Parameters from a JsonSchema

Source

pub fn from_type<T: JsonSchema>() -> Self

Create Parameters from a type implementing JsonSchema

Trait Implementations§

Source§

impl Clone for Parameters

Source§

fn clone(&self) -> Parameters

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 Debug for Parameters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Parameters

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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