Split
This commit is contained in:
@@ -15,6 +15,8 @@ use types::{Implementation, InitializeRequestParams, InitializeResult};
|
|||||||
use crate::types::{CallToolRequestParams, ClientCapabilities, ListToolsRequestParams, ListToolsResult};
|
use crate::types::{CallToolRequestParams, ClientCapabilities, ListToolsRequestParams, ListToolsResult};
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
|
mod rpc_helpers;
|
||||||
|
use rpc_helpers::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct StdioTransport {
|
struct StdioTransport {
|
||||||
@@ -58,33 +60,6 @@ impl TransportReceiverT for StdioTransport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RpcArg<T>(T);
|
|
||||||
|
|
||||||
impl<T: Serialize> ToRpcParams for RpcArg<T> {
|
|
||||||
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
|
|
||||||
let s = String::from_utf8(serde_json::to_vec(&self.0)?).expect("Valid UTF8 format");
|
|
||||||
RawValue::from_string(s).map(Some)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use magnus::{function, Error, Ruby};
|
use magnus::{function, Error, Ruby};
|
||||||
|
mod mcp_client;
|
||||||
|
mod types;
|
||||||
|
mod rpc_helpers;
|
||||||
|
|
||||||
fn distance(a: (f64, f64), b: (f64, f64)) -> f64 {
|
fn distance(a: (f64, f64), b: (f64, f64)) -> f64 {
|
||||||
((b.0 - a.0).powi(2) + (b.1 - a.1).powi(2)).sqrt()
|
((b.0 - a.0).powi(2) + (b.1 - a.1).powi(2)).sqrt()
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
use jsonrpsee::async_client::Client;
|
||||||
|
use jsonrpsee::core::client::ClientT;
|
||||||
|
use crate::rpc_helpers::{NoParams, ToRpcArg};
|
||||||
|
use crate::types::{InitializeRequestParams, InitializeResult};
|
||||||
|
|
||||||
|
struct McpClient {
|
||||||
|
client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McpClient {
|
||||||
|
async fn initialize(&self, params: InitializeRequestParams) -> Result<InitializeResult, anyhow::Error> {
|
||||||
|
let result: InitializeResult = self.client.request("initialize", params.to_rpc()).await?;
|
||||||
|
self.client.notification("notifications/initialized", NoParams).await?;
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
use jsonrpsee::core::traits::ToRpcParams;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde_json::Error;
|
||||||
|
use serde_json::value::RawValue;
|
||||||
|
|
||||||
|
pub struct RpcArg<T>(T);
|
||||||
|
|
||||||
|
impl<T: Serialize> ToRpcParams for RpcArg<T> {
|
||||||
|
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
|
||||||
|
let s = String::from_utf8(serde_json::to_vec(&self.0)?).expect("Valid UTF8 format");
|
||||||
|
RawValue::from_string(s).map(Some)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToRpcArg: Sized {
|
||||||
|
fn to_rpc(self) -> RpcArg<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Serialize> ToRpcArg for &T {
|
||||||
|
fn to_rpc(self) -> RpcArg<Self> {
|
||||||
|
RpcArg(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NoParams;
|
||||||
|
|
||||||
|
impl ToRpcParams for NoParams {
|
||||||
|
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user