Skip to main content

turbomcp_types/
lib.rs

1//! # TurboMCP Types
2//!
3//! Core types for the TurboMCP SDK - the foundation of MCP server development.
4//!
5//! This crate provides all shared types used across the TurboMCP ecosystem:
6//!
7//! - **Content types**: `Content`, `TextContent`, `ImageContent`, etc.
8//! - **Result types**: `ToolResult`, `ResourceResult`, `PromptResult`
9//! - **Definition types**: `Tool`, `Resource`, `Prompt`, `ServerInfo`
10//! - **Conversion traits**: `IntoToolResult`, `IntoResourceResult`, `IntoPromptResult`
11//!
12//! For error handling, use `turbomcp_core::error::{McpError, McpResult}`.
13//!
14//! ## Design Principles
15//!
16//! 1. **Single Source of Truth**: These types are the canonical definitions
17//! 2. **Ergonomic by Default**: Common operations are one-liners
18//! 3. **MCP 2025-11-25 Compliant**: Full spec support
19//! 4. **no_std Compatible**: Works in WASM and embedded environments
20//!
21//! ## Quick Start
22//!
23//! ```rust
24//! use turbomcp_types::*;
25//!
26//! // Create a tool result
27//! let result = ToolResult::text("Hello, world!");
28//!
29//! // Create an error result
30//! let error = ToolResult::error("Something went wrong");
31//!
32//! // Create a JSON result with structured content
33//! let json_result = ToolResult::json(&serde_json::json!({"key": "value"})).unwrap();
34//!
35//! // Create a resource result
36//! let resource = ResourceResult::text("file:///example.txt", "File contents here");
37//!
38//! // Create a prompt result
39//! let prompt = PromptResult::user("Hello!")
40//!     .add_assistant("How can I help?")
41//!     .with_description("A greeting prompt");
42//! ```
43
44#![cfg_attr(not(feature = "std"), no_std)]
45#![deny(unsafe_code)]
46#![warn(missing_docs)]
47
48extern crate alloc;
49
50pub mod component;
51pub mod content;
52pub mod definitions;
53pub mod protocol;
54pub mod results;
55pub mod traits;
56
57// Re-export everything at the crate root for convenience
58pub use component::*;
59pub use content::*;
60pub use definitions::*;
61pub use protocol::*;
62pub use results::*;
63pub use traits::*;
64
65/// Version of the TurboMCP types crate
66pub const VERSION: &str = env!("CARGO_PKG_VERSION");