Skip to content

Commit ef9309c

Browse files
committed
test: add impl of list/get prompt to main.rs and stdio_integration to
test both new methods
1 parent 7afab42 commit ef9309c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

crates/mcp-client/examples/stdio_integration.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,16 @@ async fn main() -> Result<(), ClientError> {
8282
let resource = client.read_resource("memo://insights").await?;
8383
println!("Resource: {resource:?}\n");
8484

85+
let prompts = client.list_prompts(None).await?;
86+
println!("Prompts: {prompts:?}\n");
87+
88+
let prompt = client
89+
.get_prompt(
90+
"example_prompt",
91+
serde_json::json!({"message": "hello there!"}),
92+
)
93+
.await?;
94+
println!("Prompt: {prompt:?}\n");
95+
8596
Ok(())
8697
}

crates/mcp-server/src/main.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Result;
22
use mcp_core::content::Content;
3-
use mcp_core::handler::ResourceError;
3+
use mcp_core::handler::{PromptError, ResourceError};
4+
use mcp_core::prompt::{Prompt, PromptArgument};
45
use mcp_core::{handler::ToolError, protocol::ServerCapabilities, resource::Resource, tool::Tool};
56
use mcp_server::router::{CapabilitiesBuilder, RouterService};
67
use mcp_server::{ByteTransport, Router, Server};
@@ -61,6 +62,7 @@ impl Router for CounterRouter {
6162
CapabilitiesBuilder::new()
6263
.with_tools(false)
6364
.with_resources(false, false)
65+
.with_prompts(false)
6466
.build()
6567
}
6668

@@ -153,6 +155,37 @@ impl Router for CounterRouter {
153155
}
154156
})
155157
}
158+
159+
fn list_prompts(&self) -> Vec<Prompt> {
160+
vec![Prompt::new(
161+
"example_prompt",
162+
Some("This is an example prompt that takes one required agrument, message"),
163+
Some(vec![PromptArgument {
164+
name: "message".to_string(),
165+
description: Some("A message to put in the prompt".to_string()),
166+
required: Some(true),
167+
}]),
168+
)]
169+
}
170+
171+
fn get_prompt(
172+
&self,
173+
prompt_name: &str,
174+
) -> Pin<Box<dyn Future<Output = Result<String, PromptError>> + Send + 'static>> {
175+
let prompt_name = prompt_name.to_string();
176+
Box::pin(async move {
177+
match prompt_name.as_str() {
178+
"example_prompt" => {
179+
let prompt = "This is an example prompt with your message here: '{message}'";
180+
Ok(prompt.to_string())
181+
}
182+
_ => Err(PromptError::NotFound(format!(
183+
"Prompt {} not found",
184+
prompt_name
185+
))),
186+
}
187+
})
188+
}
156189
}
157190

158191
#[tokio::main]

0 commit comments

Comments
 (0)