#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate alloc;
pub mod auth;
pub mod context;
pub mod error;
pub mod handler;
pub mod jsonrpc;
pub mod marker;
pub mod response;
pub mod router;
pub mod security;
pub mod types;
#[cfg(feature = "zero-copy")]
#[cfg_attr(docsrs, doc(cfg(feature = "zero-copy")))]
pub mod rkyv_types;
pub use error::{ErrorKind, McpError, McpResult};
pub use jsonrpc::{
JSONRPC_VERSION,
JsonRpcError,
JsonRpcErrorCode,
JsonRpcIncoming,
JsonRpcNotification,
JsonRpcOutgoing,
JsonRpcRequest,
JsonRpcResponse,
JsonRpcVersion,
RequestId,
ResponseId,
};
pub use response::{Image, IntoToolError, IntoToolResponse, Json, Text, ToolError};
pub use security::{
ALLOWED_URI_SCHEMES, DEFAULT_MAX_STRING_LENGTH, DEFAULT_MAX_URI_LENGTH, InputLimits,
InputValidationError, sanitize_error_message, validate_uri_scheme,
};
pub use auth::{
AuthError, Authenticator, Credential, CredentialExtractor, HeaderExtractor, JwtAlgorithm,
JwtConfig, Principal, StandardClaims,
};
pub use context::{RequestContext, TransportType};
pub use handler::McpHandler;
pub use marker::{MaybeSend, MaybeSync};
pub use turbomcp_types::{
Annotations,
AudioContent,
Content,
EmbeddedResource,
Icon,
ImageContent,
IntoPromptResult,
IntoResourceResult,
IntoToolResult,
Message,
Prompt,
PromptArgument,
PromptResult,
Resource,
ResourceAnnotations,
ResourceContents,
ResourceResult,
ResourceTemplate,
Role,
ServerInfo,
TextContent,
Tool,
ToolAnnotations,
ToolInputSchema,
ToolResult,
};
pub const PROTOCOL_VERSION: &str = "2025-11-25";
pub const SUPPORTED_VERSIONS: &[&str] = &["2025-06-18", "2025-11-25"];
pub const MAX_MESSAGE_SIZE: usize = 1024 * 1024;
pub const DEFAULT_TIMEOUT_MS: u64 = 30_000;
pub const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const SDK_NAME: &str = "turbomcp";
pub mod features {
pub const TOOLS: &str = "tools";
pub const PROMPTS: &str = "prompts";
pub const RESOURCES: &str = "resources";
pub const LOGGING: &str = "logging";
pub const PROGRESS: &str = "progress";
pub const SAMPLING: &str = "sampling";
pub const ROOTS: &str = "roots";
}
pub mod methods {
pub const INITIALIZE: &str = "initialize";
pub const INITIALIZED: &str = "notifications/initialized";
pub const LIST_TOOLS: &str = "tools/list";
pub const CALL_TOOL: &str = "tools/call";
pub const LIST_PROMPTS: &str = "prompts/list";
pub const GET_PROMPT: &str = "prompts/get";
pub const LIST_RESOURCES: &str = "resources/list";
pub const READ_RESOURCE: &str = "resources/read";
pub const SUBSCRIBE: &str = "resources/subscribe";
pub const UNSUBSCRIBE: &str = "resources/unsubscribe";
pub const RESOURCE_UPDATED: &str = "notifications/resources/updated";
pub const RESOURCE_LIST_CHANGED: &str = "notifications/resources/list_changed";
pub const SET_LEVEL: &str = "logging/setLevel";
pub const LOG_MESSAGE: &str = "notifications/message";
pub const PROGRESS: &str = "notifications/progress";
pub const CREATE_MESSAGE: &str = "sampling/createMessage";
pub const LIST_ROOTS: &str = "roots/list";
pub const ROOTS_LIST_CHANGED: &str = "notifications/roots/list_changed";
}
pub mod error_codes {
pub const PARSE_ERROR: i32 = -32700;
pub const INVALID_REQUEST: i32 = -32600;
pub const METHOD_NOT_FOUND: i32 = -32601;
pub const INVALID_PARAMS: i32 = -32602;
pub const INTERNAL_ERROR: i32 = -32603;
pub const URL_ELICITATION_REQUIRED: i32 = -32042;
pub const TOOL_NOT_FOUND: i32 = -32001;
pub const TOOL_EXECUTION_ERROR: i32 = -32002;
pub const PROMPT_NOT_FOUND: i32 = -32003;
pub const RESOURCE_NOT_FOUND: i32 = -32004;
pub const RESOURCE_ACCESS_DENIED: i32 = -32005;
pub const CAPABILITY_NOT_SUPPORTED: i32 = -32006;
pub const PROTOCOL_VERSION_MISMATCH: i32 = -32007;
pub const AUTHENTICATION_REQUIRED: i32 = -32008;
pub const RATE_LIMITED: i32 = -32009;
pub const SERVER_OVERLOADED: i32 = -32010;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version_constants() {
assert_eq!(PROTOCOL_VERSION, "2025-11-25");
assert!(SUPPORTED_VERSIONS.contains(&PROTOCOL_VERSION));
assert_eq!(
SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.len() - 1],
PROTOCOL_VERSION
);
}
#[test]
fn test_size_constants() {
assert_eq!(MAX_MESSAGE_SIZE, 1024 * 1024);
assert_eq!(DEFAULT_TIMEOUT_MS, 30_000);
}
}