2 unstable releases
new 0.2.0 | May 12, 2025 |
---|---|
0.1.0 | Apr 17, 2025 |
#2103 in Web programming
163 downloads per month
Used in kuri
54KB
1K
SLoC
kuri_mcp_protocol
provides Rust types for the Model Context Protocol (MCP).
This crate is intended to be independent of Kuri's implementation and usage of these types, so you
may use kuri_mcp_protocol
by itself in your project, if you only want the protocol types and not the
kuri
server framework.
Organisation
The crate is organised into several modules:
content
- Content types for communication (text, images, etc.)jsonrpc
- JSON-RPC protocol implementationmessages
- MCP message typesprompt
- Prompt typesresource
- Resource typestool
- Tool types
Basic Usage
Prompts
use kuri_mcp_protocol::prompt::{Prompt, PromptMessage, PromptMessageRole};
// Describe a prompt
let prompt = Prompt::new(
"simple_greeting",
Some("A simple greeting prompt"),
None,
);
// Describe a prompt message
let message = PromptMessage::new_text(
PromptMessageRole::User,
"Hello, how are you today?",
);
Resources
use kuri_mcp_protocol::resource::Resource;
// Describe a resource
let resource = Resource::new(
"file:///example.txt",
Some("text/plain".to_string()),
Some("Example File".to_string()),
None,
).expect("Failed to create resource");
Tools
use kuri_mcp_protocol::tool::{Tool, generate_tool_schema};
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct CalculatorParameters {
#[schemars(description = "First number")]
x: i32,
#[schemars(description = "Second number")]
y: i32,
#[schemars(description = "Operation to perform")]
operation: String,
}
// Generate schema for the tool parameters
let schema = generate_tool_schema::<CalculatorParameters>()
.expect("Failed to generate schema");
// Describe a tool
let tool = Tool::new(
"calculator",
"Perform basic arithmetic operations",
schema,
);
kuri_mcp_protocol
This crate contains types for the MCP protocol, and handlers to enable serde serialisation/deserialisation from these types.
This crate is intended to be independent of kuri's implementation and usage of these types, so you
may use kuri_mcp_protocol
by itself in your project, if you only want the types and not the kuri
server framework.
Dependencies
~3–4.5MB
~82K SLoC