1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! # tmcp
//!
//! A complete Rust implementation of the Model Context Protocol (MCP), providing both
//! client and server capabilities for building AI-integrated applications.
//!
//! ## Overview
//!
//! tmcp offers an ergonomic API for implementing MCP servers and clients with
//! support for tools, resources, and prompts. The library uses async/await patterns
//! with Tokio and provides procedural macros to eliminate boilerplate.
//!
//! ## Features
//!
//! - **Derive Macros**: Simple `#[mcp_server]` attribute for automatic implementation
//! - **Multiple Transports**: TCP, HTTP (with SSE), and stdio support
//! - **Type Safety**: Strongly typed protocol messages with serde
//! - **Async-First**: Built on Tokio for high-performance async I/O
//!
//! ## Transport Options
//!
//! - **TCP**: `server.listen_tcp("127.0.0.1:3000")`
//! - **HTTP**: `server.listen_http("127.0.0.1:3000")` (uses SSE for server->client)
//! - **Stdio**: `server.listen_stdio()` for subprocess integration
//!
//! ## Building Servers: Macro vs Trait
//!
//! tmcp provides two approaches for implementing MCP servers:
//!
//! ### The `#[mcp_server]` Macro
//!
//! Best for simple servers that primarily expose tools. The macro automatically:
//! - Generates [`ServerHandler`] trait implementation
//! - Derives tool schemas from function signatures using `schemars`
//! - Registers tools in `list_tools` and routes calls in `call_tool`
//! - Provides sensible defaults for `initialize`
//!
//! ```ignore
//! use schemars::JsonSchema;
//! use serde::Deserialize;
//! use tmcp::{mcp_server, schema::CallToolResult, tool, ServerCtx, ToolResult};
//!
//! #[derive(Debug, Deserialize, JsonSchema)]
//! struct GreetParams {
//! name: String,
//! }
//!
//! #[mcp_server]
//! impl MyServer {
//! #[tool]
//! async fn greet(&self, _ctx: &ServerCtx, params: GreetParams) -> ToolResult {
//! Ok(CallToolResult::new().with_text_content(format!(
//! "Hello, {}!",
//! params.name
//! )))
//! }
//! }
//! ```
//!
//! ### The [`ServerHandler`] Trait
//!
//! Use the trait directly when you need:
//! - **Custom initialization**: Validate clients, negotiate capabilities, or reject connections
//! - **Per-connection state**: Access to `ServerCtx` in all methods for client-specific data
//! - **Resources and prompts**: Full access to MCP features beyond tools
//! - **Fine-grained error handling**: Custom error responses and logging
//!
//! ```ignore
//! use tmcp::{ServerHandler, ServerCtx, Result};
//! use async_trait::async_trait;
//!
//! struct MyServer;
//!
//! #[async_trait]
//! impl ServerHandler for MyServer {
//! async fn initialize(&self, ctx: &ServerCtx, ...) -> Result<InitializeResult> {
//! // Custom capability negotiation
//! }
//!
//! async fn list_tools(&self, ctx: &ServerCtx, ...) -> Result<ListToolsResult> {
//! // Dynamic tool registration
//! }
//! }
//! ```
//!
//! See [`ServerHandler`] documentation for the default behavior philosophy.
/// Argument envelope used by tool calls and prompt arguments.
/// Client implementation and transport orchestration.
/// JSON-RPC codec for stream framing.
/// Connection traits for clients and servers.
/// Client/server context types.
/// Error types and Result alias.
/// HTTP transport implementation.
/// JSON-RPC message definitions.
/// Request/response routing and tracking.
/// Server implementation and handle types.
/// Tool registration and progressive discovery support.
/// Transport traits and adapters.
/// OAuth and authorization helpers.
/// Public schema types for MCP messages.
/// Test utilities for building tmcp integration tests.
pub use Arguments;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ToolResponse;
pub use ;
// Export user-facing macros directly from the crate root
pub use ;
pub use ;
pub use ;
// Keep the full macros module available for internal use
/// Re-exported macros module for internal use.