-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - notification and request dispatch and handling
- Loading branch information
Showing
11 changed files
with
135 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "mcp-client-sse" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mcp-core = { path = "../mcp-core" } | ||
mcp-transport-sse = { path = "../mcp-transport-sse" } | ||
mcp-types = { path = "../mcp-types" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use mcp_core::protocol::Protocol; | ||
use mcp_transport_sse::{client::SSEClientTransport, error::SSETransportError}; | ||
|
||
pub struct SSEClient { | ||
protocol: Protocol<SSETransportError>, | ||
} | ||
|
||
impl SSEClient { | ||
pub fn new(transport: SSEClientTransport) -> Self { | ||
Self { | ||
protocol: Protocol::new(Box::new(transport)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use serde::de::DeserializeOwned; | ||
|
||
pub trait MessageSchema: DeserializeOwned { | ||
fn method(&self) -> String; | ||
fn params(&self) -> Option<serde_json::Map<String, serde_json::Value>>; | ||
} | ||
|
||
/// Macro for implementing the `MessageSchema` trait for a given type that has | ||
/// a `method` field and a `params` field. | ||
macro_rules! impl_message_schema { | ||
($type:ty) => { | ||
impl MessageSchema for $type { | ||
fn method(&self) -> String { | ||
self.method.clone() | ||
} | ||
|
||
fn params(&self) -> Option<serde_json::Map<String, serde_json::Value>> { | ||
serde_json::to_value(&self.params) | ||
.ok() | ||
.and_then(|v| v.as_object().cloned()) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
// Implement the `MessageSchema` trait for all generated message types | ||
use super::types::*; | ||
|
||
impl_message_schema!(CancelledNotification); | ||
impl_message_schema!(InitializedNotification); | ||
impl_message_schema!(LoggingMessageNotification); | ||
impl_message_schema!(ProgressNotification); | ||
impl_message_schema!(PromptListChangedNotification); | ||
impl_message_schema!(ResourceListChangedNotification); | ||
impl_message_schema!(ResourceUpdatedNotification); | ||
impl_message_schema!(ToolListChangedNotification); | ||
|
||
// Implement the `MessageSchema` trait for all generated request types | ||
impl_message_schema!(CallToolRequest); | ||
impl_message_schema!(CompleteRequest); | ||
impl_message_schema!(CreateMessageRequest); | ||
impl_message_schema!(GetPromptRequest); | ||
impl_message_schema!(InitializeRequest); | ||
impl_message_schema!(ListPromptsRequest); | ||
impl_message_schema!(ListResourcesRequest); | ||
impl_message_schema!(ListResourceTemplatesRequest); | ||
impl_message_schema!(ListRootsRequest); | ||
impl_message_schema!(ListToolsRequest); | ||
impl_message_schema!(PingRequest); | ||
impl_message_schema!(ReadResourceRequest); | ||
impl_message_schema!(SetLevelRequest); | ||
impl_message_schema!(SubscribeRequest); | ||
impl_message_schema!(UnsubscribeRequest); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{InitializeRequest, InitializeRequestParams, LATEST_PROTOCOL_VERSION}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_message_schema() { | ||
let request = InitializeRequest { | ||
method: "initialize".to_string(), | ||
params: InitializeRequestParams { | ||
capabilities: ClientCapabilities::default(), | ||
client_info: Implementation { | ||
name: "test".to_string(), | ||
version: "1.0.0".to_string(), | ||
}, | ||
protocol_version: LATEST_PROTOCOL_VERSION.to_string(), | ||
}, | ||
}; | ||
assert_eq!(request.method(), "initialize"); | ||
assert_eq!( | ||
request.params().unwrap().get("protocolVersion").unwrap(), | ||
LATEST_PROTOCOL_VERSION | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod messages; | ||
pub mod types; |
File renamed without changes.