Move whole rmcp crate to offcial rust sdk (#44)
* get rid of async-trait * move rmcp to official-rust-sdk * replace master with main * update readme, change license * fix typo * Update README.md Co-authored-by: Jefry Dewangga <jefrydco@gmail.com> * fix typos --------- Co-authored-by: = <=> Co-authored-by: Jefry Dewangga <jefrydco@gmail.com>
This commit is contained in:
parent
31493cfbcc
commit
0be6067326
1 changed files with 8676 additions and 4466 deletions
63
crates/rmcp/tests/test_complex_schema.rs
Normal file
63
crates/rmcp/tests/test_complex_schema.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use rmcp::{Error as McpError, model::*, schemars, tool};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
pub enum ChatRole {
|
||||
System,
|
||||
User,
|
||||
Assistant,
|
||||
Tool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
pub struct ChatMessage {
|
||||
pub role: ChatRole,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
pub struct ChatRequest {
|
||||
pub system: Option<String>,
|
||||
pub messages: Vec<ChatMessage>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Demo;
|
||||
|
||||
#[tool(tool_box)]
|
||||
impl Demo {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
#[tool(description = "LLM")]
|
||||
async fn chat(
|
||||
&self,
|
||||
#[tool(aggr)] chat_request: ChatRequest,
|
||||
) -> Result<CallToolResult, McpError> {
|
||||
let content = Content::json(chat_request)?;
|
||||
Ok(CallToolResult::success(vec![content]))
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complex_schema() {
|
||||
let attr = Demo::chat_tool_attr();
|
||||
let input_schema = attr.input_schema;
|
||||
let enum_numer = input_schema
|
||||
.get("definitions")
|
||||
.unwrap()
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.get("ChatRole")
|
||||
.unwrap()
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.get("enum")
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.len();
|
||||
assert_eq!(enum_numer, 4);
|
||||
println!("{}", serde_json::to_string_pretty(&input_schema).unwrap());
|
||||
}
|
||||
Loading…
Reference in a new issue