It can call tools!
This commit is contained in:
parent
212de0524e
commit
24a1ae6ef9
@ -9,12 +9,12 @@ use jsonrpsee::core::traits::ToRpcParams;
|
||||
use tokio::process::{Child, ChildStdin, ChildStdout};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Error;
|
||||
use serde_json::{json, Error};
|
||||
use serde_json::value::RawValue;
|
||||
use tokio::time::sleep;
|
||||
use tracing::debug;
|
||||
use types::{Implementation, InitializeRequestParams, InitializeResult};
|
||||
use crate::types::{ClientCapabilities, ListToolsRequestParams, ListToolsResult};
|
||||
use crate::types::{CallToolRequestParams, ClientCapabilities, ListToolsRequestParams, ListToolsResult};
|
||||
|
||||
mod types;
|
||||
|
||||
@ -69,6 +69,16 @@ impl<T: Serialize> ToRpcParams for RpcArg<T> {
|
||||
}
|
||||
}
|
||||
|
||||
trait ToRpcArg: Sized {
|
||||
fn to_rpc(self) -> RpcArg<Self>;
|
||||
}
|
||||
|
||||
impl<T: Serialize> ToRpcArg for &T {
|
||||
fn to_rpc(self) -> RpcArg<Self> {
|
||||
RpcArg(self)
|
||||
}
|
||||
}
|
||||
|
||||
struct NoParams;
|
||||
|
||||
impl ToRpcParams for NoParams {
|
||||
@ -101,17 +111,21 @@ async fn main() -> anyhow::Result<()> {
|
||||
transport.clone(),
|
||||
);
|
||||
|
||||
let response: InitializeResult = client.request("initialize", RpcArg(InitializeRequestParams {
|
||||
let response: InitializeResult = client.request("initialize", InitializeRequestParams {
|
||||
capabilities: ClientCapabilities::default(),
|
||||
client_info: Implementation { name: "Rust MCP".to_string(), version: "0.1.0".to_string() },
|
||||
protocol_version: "2024-11-05".to_string(),
|
||||
})).await?;
|
||||
|
||||
println!("Response: {:?}", response);
|
||||
}.to_rpc()).await?;
|
||||
|
||||
client.notification("notifications/initialized", NoParams).await?;
|
||||
|
||||
let response: ListToolsResult = client.request("tools/list", RpcArg(ListToolsRequestParams::default())).await?;
|
||||
let response: ListToolsResult = client.request("tools/list", ListToolsRequestParams::default().to_rpc()).await?;
|
||||
|
||||
let response: serde_json::Value = client.request("tools/call", CallToolRequestParams {
|
||||
arguments: json!({ "url": "http://example.com" }).as_object().unwrap().clone(),
|
||||
name: "fetch".to_string(),
|
||||
}.to_rpc()).await?;
|
||||
|
||||
println!("Response: {:#?}", response);
|
||||
|
||||
Ok(())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user