Expand description
§Types Module
Core type definitions for the Model Context Protocol (MCP).
This module provides all the fundamental types used throughout the MCP ecosystem, including tools, resources, prompts, and various request/response structures. These types are designed to be type-safe, serializable, and fully compliant with the MCP 2025-06-18 specification.
§Overview
The types module serves as the foundation for all MCP data structures and provides:
- Tool Types: Tool definitions, calls, and results
- Resource Types: Resource management and content handling
- Prompt Types: Prompt generation and management
- Client/Server Types: Information and capability structures
- Notification Types: Progress, logging, and status updates
- Utility Types: Common patterns like pagination and cursors
§Core Concepts
§Tools
Tools are the primary mechanism for extending MCP functionality:
- Tool Definition: Schema, description, and metadata
- Tool Call: Request to execute a tool with parameters
- Tool Result: Response from tool execution
§Resources
Resources provide access to external data and content:
- Resource Definition: URI, content type, and metadata
- Resource Content: Actual data with MIME type information
- Resource Templates: Reusable resource definitions
§Prompts
Prompts enable dynamic content generation:
- Prompt Definition: Template with arguments and metadata
- Prompt Content: Generated content with role information
- Prompt Arguments: Parameters for prompt generation
§Modules
tools: Tool-related types including definitions, calls, and resultsresources: Resource management types and content handlingprompts: Prompt generation and template managementclient: Client information and capability structuresserver: Server information and capability structuresnotifications: Progress, logging, and status notification typescompletion: Autocompletion and suggestion typeselicitation: User input collection and validation typessampling: LLM sampling and message generation typesroots: Filesystem root and boundary management types
§Usage Examples
§Tool Definition and Usage
use ultrafast_mcp_core::types::{
Tool, ToolCall, ToolResult, ToolContent,
ListToolsRequest, ListToolsResponse
};
use ultrafast_mcp_core::types::prompts::{PromptArgument, PromptMessage};
use ultrafast_mcp_core::types::{PromptContent};
// Define a tool
let tool = Tool {
name: "greet".to_string(),
description: "Greet a person by name".to_string(),
input_schema: serde_json::json!({
"type": "object",
"properties": {
"name": {"type": "string"},
"greeting": {"type": "string", "default": "Hello"}
},
"required": ["name"]
}),
output_schema: None,
annotations: None,
};
// Create a tool call
let tool_call = ToolCall {
name: "greet".to_string(),
arguments: Some(serde_json::json!({
"name": "Alice",
"greeting": "Hello there"
})),
};
// Create a tool result
let tool_result = ToolResult {
content: vec![ToolContent::text("Hello there, Alice!".to_string())],
is_error: Some(false),
};§Resource Management
use ultrafast_mcp_core::types::{
Resource, ResourceContent, ReadResourceRequest, ReadResourceResponse
};
// Define a resource
let resource = Resource {
uri: "file:///path/to/document.txt".to_string(),
name: "Document".to_string(),
description: Some("A text document".to_string()),
mime_type: Some("text/plain".to_string()),
};
// Create a read request
let read_request = ReadResourceRequest {
uri: "file:///path/to/document.txt".to_string(),
};
// Create a read response
let read_response = ReadResourceResponse {
contents: vec![ResourceContent::text("file:///path/to/document.txt".to_string(), "Document content".to_string())],
};§Prompt Generation
use ultrafast_mcp_core::types::{
Prompt, PromptContent, PromptRole, GetPromptRequest, GetPromptResponse
};
// Define a prompt
let prompt = Prompt {
name: "summarize".to_string(),
description: Some("Summarize text content".to_string()),
arguments: Some(vec![
ultrafast_mcp_core::types::prompts::PromptArgument::new("text".to_string()).required(true),
ultrafast_mcp_core::types::prompts::PromptArgument::new("max_length".to_string()).required(false),
]),
};
// Create a prompt request
let prompt_request = GetPromptRequest {
name: "summarize".to_string(),
arguments: Some(serde_json::json!({
"text": "Long text to summarize...",
"max_length": 50
})),
};
// Create a prompt response
let prompt_response = GetPromptResponse {
messages: vec![ultrafast_mcp_core::types::prompts::PromptMessage::system(PromptContent::text("Summarize this text...".to_string()))],
description: None,
};§Client/Server Information
use ultrafast_mcp_core::types::{
ClientInfo, ServerInfo, ServerCapabilities
};
// Client information
let client_info = ClientInfo {
name: "example-client".to_string(),
version: "1.0.0".to_string(),
description: Some("An example MCP client".to_string()),
authors: None,
homepage: None,
license: None,
repository: None,
};
// Server information
let server_info = ServerInfo {
name: "example-server".to_string(),
version: "1.0.0".to_string(),
description: Some("An example MCP server".to_string()),
authors: None,
homepage: None,
license: None,
repository: None,
};
// Capabilities
let server_capabilities = ServerCapabilities::default();§Serialization
All types in this module support serialization and deserialization:
- JSON Serialization: All types implement
SerializeandDeserialize - Schema Generation: Automatic JSON Schema generation for validation
- Type Safety: Compile-time guarantees for data structure correctness
- Validation: Runtime validation of data against schemas
§Type Safety
The type system provides several safety guarantees:
- Compile-time Validation: Type checking prevents many runtime errors
- Schema Validation: Runtime validation ensures data correctness
- Error Handling: Comprehensive error types for all failure modes
- Null Safety: Optional fields are properly handled
§Performance Considerations
- Efficient Serialization: Optimized JSON serialization/deserialization
- Minimal Allocations: Smart use of references and owned data
- Lazy Validation: Validation only when necessary
- Memory Efficiency: Compact data structures where possible
§Thread Safety
All types are designed to be thread-safe:
- Types implement
Send + Syncwhere appropriate - Immutable by default for safety
- Interior mutability where needed
§Extensibility
The type system is designed to be extensible:
- New types can be added without breaking changes
- Optional fields allow for backward compatibility
- Schema evolution is supported
- Custom validation rules can be added
Modules§
- client
- completion
- Completion types for MCP 2025-06-18 protocol
- elicitation
- Elicitation types for MCP
- notifications
- Notification types for MCP 2025-06-18 protocol
- prompts
- resources
- roots
- Roots types for MCP
- sampling
- server
- tools
Structs§
- Alternative
Model - Alternative model that was considered
- Cancelled
Notification - Cancellation notification for MCP 2025-06-18 protocol
- Client
Capabilities - Client capabilities that can be negotiated during initialization
- Client
Capability Notification - Client capability notification - sent when client capabilities change
- Client
Info - Client information
- Complete
Request - Completion request (MCP 2025-06-18 compliant)
- Complete
Response - Completion response
- Completion
- Completion result set
- Completion
Argument - Completion argument (MCP 2025-06-18 compliant)
- Completion
Capability - Completion capability for argument autocompletion
- Completion
Context - Context for completion requests
- Completion
Documentation - Completion documentation
- Completion
Filter - Filter criteria for completions
- Completion
Metadata - Completion metadata
- Completion
Range - Completion range
- Completion
Reference - Completion reference (MCP 2025-06-18 compliant)
- Completion
Statistics - Completion statistics
- Completion
Value - Individual completion value
- Connection
Status Notification - Connection status notification
- Cost
Info - Cost information for the sampling request
- Elicitation
Capability - Elicitation capability for user input collection
- Elicitation
Request - Server-initiated request for user input
- Elicitation
Response - User response to elicitation request
- Embedded
Resource Reference - Enhanced embedded resource reference for prompts
- Embedded
Resource Validator - Prompt embedded resource validator
- GetPrompt
Request - Get prompt request
- GetPrompt
Response - Get prompt response
- Human
Feedback - Human feedback for sampling requests
- Human
InThe Loop Settings - Human-in-the-loop settings
- Implementation
- Information about the implementation
- List
Prompts Request - List prompts request
- List
Prompts Response - List prompts response
- List
Resource Templates Request - List
Resource Templates Response - List resource templates response
- List
Resources Request - List
Resources Response - List resources response
- List
Roots Request - Request to list available roots
- List
Roots Response - Response containing available roots
- List
Tools Request - List tools request
- List
Tools Response - List tools response
- LogLevel
SetRequest - Log level set request - MCP 2025-06-18 compliant
- LogLevel
SetResponse - Log level set response - MCP 2025-06-18 compliant
- Logging
Capability - Logging capability
- Logging
Message Notification - Logging message notification - MCP 2025-06-18 compliant
- Model
Capability - Model capability information for intelligent selection
- Model
Hint - Model hint for sampling
- Model
Performance Record - Historical performance data for a model
- Model
Preferences - Model preferences for sampling
- Model
Selection Context - Model selection context for intelligent choice
- Model
Selection Result - Result of model selection with reasoning
- Model
Selector - Intelligent model selector that considers preferences and context
- Notification
Settings - Notification settings for human-in-the-loop
- Ping
Request - Ping request for connection health monitoring
- Ping
Response - Ping response for connection health monitoring
- Priority
Scores - Calculated priority scores
- Progress
Notification - Progress notification for MCP 2025-06-18 protocol
- Prompt
- Prompt definition
- Prompt
Argument - Prompt argument definition
- Prompt
Message - Prompt message
- Prompt
Messages - Helper for building prompt messages
- Prompts
Capability - Prompts capability
- Prompts
List Changed Notification - Prompts list changed notification
- Rate
Limit Notification - Rate limit notification
- Read
Resource Request - Read
Resource Response - Read resource response
- Request
Context - Context information about the current request
- Request
Timeout Notification - Request timeout notification
- Resolution
Metadata - Resource resolution metadata
- Resource
- Resource definition
- Resource
Context Info - Resource context information
- Resource
Inclusion Options - Resource inclusion options
- Resource
Reference - Reference to a resource
- Resource
Resolution - Resource resolution result
- Resource
Security Policy - Security policy for embedded resources
- Resource
Template - Resource template definition (for parameterized resources)
- Resource
Updated Notification - Resource updated notification
- Resources
Capability - Resources capability
- Resources
List Changed Notification - Resources list changed notification
- Root
- A filesystem root that defines boundary for file operations
- Root
List Changed Notification - Notification sent when the list of roots changes
- Root
Security Config - Security configuration for a root
- Root
Security Validator - Comprehensive security validator for roots
- Roots
Capability - Roots capability for filesystem boundary management
- Roots
List Changed Notification - Notification sent when the list of roots changes
- Sampling
Capability - Sampling capability for LLM completions
- Sampling
Context - Context information for sampling requests
- Sampling
Message - Sampling message
- Sampling
Request - Enhanced sampling request with context and human-in-the-loop support
- Sampling
Response - Enhanced sampling response with human-in-the-loop support
- Selection
Factor - Factors that influenced model selection
- Selection
Reasoning - Detailed reasoning for model selection
- Server
Capabilities - Server capabilities that can be advertised during initialization
- Server
Capability Notification - Server capability notification - sent when server capabilities change
- Server
Context Info - Server context information
- Server
Info - Information about the server
- SetRoots
Request - Request to set/update the list of roots
- SetRoots
Response - Response to a set roots request
- Subscribe
Request - Subscribe to resource request
- Subscribe
Response - Response to a resource subscription request
- Template
Expansion Options - Template expansion options
- Template
Metadata - Template metadata
- Template
Security Policy - Template security policy
- Tool
- Tool definition
- Tool
Annotations - Tool annotations provide metadata about tool behavior
- Tool
Call Request - Tool call request
- Tool
Call Response - Tool call response
- Tool
Context Info - Tool context information
- Tools
Capability - Tools capability
- Tools
List Changed Notification - Tools list changed notification
- Unsubscribe
Request - Unsubscribe from resource request
- User
Preferences - User preferences for sampling
- Variable
Name Policy - Variable name policy
- _Old
Roots List Changed Notification - Roots list changed notification
Enums§
- Approval
Status - Human-in-the-loop approval status
- Completion
Kind - Completion kind
- Connection
Status - Connection status enum
- Documentation
Kind - Documentation kind
- Elicitation
Action - User response actions
- Include
Context - Context inclusion options for sampling requests
- LogLevel
- Log level - RFC 5424 compliant levels
- Modality
- Supported input/output modalities
- Prompt
Content - Prompt content
- Prompt
Role - Prompt message role
- Rate
Limit Type - Rate limit type
- Resource
Content - Resource content
- Resource
Resolution Error - Resource resolution errors
- Root
Operation - Operation type for security validation
- Root
Security Error - Sampling
Content - Sampling content
- Sampling
Role - Sampling message role
- Scoring
Strategy - Strategy for scoring and ranking models
- Stop
Reason - Stop reason for sampling responses
- Template
Error - Template expansion errors
- Tool
Content - Tool content (result of tool execution)
Functions§
- validate_
path_ within_ root - Legacy function for backward compatibility
Type Aliases§
- Create
Message Request - Type aliases for consistency
- Create
Message Response - Tool
Call - Type aliases for consistency
- Tool
Result