pub struct Server { /* private fields */ }Implementations§
Source§impl Server
impl Server
pub fn new() -> Self
Sourcepub fn register_prompt(&mut self, prompt: Prompt)
pub fn register_prompt(&mut self, prompt: Prompt)
Register a prompt with a callback to generate its messages.
// Register a simple prompt with no arguments
let prompt = Prompt::new(
"greeting",
Some("A simple greeting prompt"),
|| {
Ok(vec![PromptMessage::new_text(PromptMessageRole::Assistant, format!("Hello, world!"))])
});
server.register_prompt(prompt);
let prompt = Prompt::new_with_args(
"personalized_greeting",
Some("A personalized greeting prompt"),
vec![PromptArgument {
name: "person".to_string(),
description: Some("The name of the person to greet".to_string()),
required: Some(true),
}],
|args| {
let args = args.ok_or(Error::MissingArgument("name".to_string()))?;
let name = args
.get("name")
.and_then(Value::as_str)
.ok_or(Error::MissingArgument("name".to_string()))?;
Ok(vec![PromptMessage::new_text(
PromptMessageRole::Assistant,
format!("Hello, {}!", name),
)])
}
);
server.register_prompt(prompt);
Sourcepub fn register_resource(&mut self, resource: Resource)
pub fn register_resource(&mut self, resource: Resource)
Register a resource with a callback to provide its contents.
let resource = Resource::new(
"file:///foo/bar/baz.txt",
"baz.txt",
Some("An example file"),
Some("text/plain"),
None,
|| {
Ok(vec![ResourceContents::text(
"Hello, world!",
"file:///foo/bar/baz.txt",
)])
},
);
server.register_resource(resource);Sourcepub fn register_resource_template(&mut self, template: ResourceTemplate)
pub fn register_resource_template(&mut self, template: ResourceTemplate)
Register a resource template.
Sourcepub fn register_tool(&mut self, tool: Tool)
pub fn register_tool(&mut self, tool: Tool)
Register a tool with a callback to handle tool calls.
let tool = Tool::new("frobnicate", Some("Does some processing"), || {
std::thread::sleep(std::time::Duration::from_millis(10));
Ok(vec![Content::text("Processing is done")])
});
server.register_tool(tool);Trait Implementations§
Source§impl Provider for Server
impl Provider for Server
type Error = Error
fn protocol_version(&self) -> ProtocolVersion
fn capabilities(&self) -> ServerCapabilities
fn implementation(&self) -> Implementation
fn list_prompts<'life0, 'async_trait>(
&'life0 self,
_page: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Prompt>, Option<String>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_prompt<'life0, 'async_trait>(
&'life0 self,
name: String,
arguments: Option<Map<String, Value>>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<PromptMessage>, Option<String>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_resources<'life0, 'async_trait>(
&'life0 self,
_page: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Annotated<RawResource>>, Option<String>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_resource_templates<'life0, 'async_trait>(
&'life0 self,
_page: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<ResourceTemplate>, Option<String>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_resource<'life0, 'life1, 'async_trait>(
&'life0 self,
uri: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceContents>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_tools<'life0, 'async_trait>(
&'life0 self,
_page: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Tool>, Option<String>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
arguments: Option<Map<String, Value>>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Content>, Option<bool>), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more