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
179
180
181
182
183
184
185
186
187
188
189
190
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Built-in tools available only in the transit proxy.
//!
//! This module provides tools that are exclusive to the proxy application and are not
//! available in the target application. These tools enable the proxy to provide additional
//! functionality beyond what the target application offers, such as log inspection and
//! proxy-specific operations.
//!
//! # Overview
//!
//! The transit proxy sits between clients and target applications, intercepting and
//! augmenting the Model Context Protocol (MCP) communication. This module manages the
//! proxy's exclusive toolset, allowing it to provide additional functionality that
//! the target application doesn't offer.
//!
//! The proxy can augment the tool set available to clients by:
//! - Providing proxy-only tools (e.g., log inspection tools)
//! - Merging proxy tools with target application tools
//! - Intercepting and handling specific tool calls locally
//!
//! # Tool Categories
//!
//! ## Proxy-Only Tools
//! Tools that exist only in the proxy and handle proxy-specific functionality:
//! - `LogwiseRead`: Read captured logs from logwise
//! - `LogwiseGrep`: Search through captured logs using regular expressions
//!
//! ## Shared Tools
//! Tools that are available in both the proxy and target application. When invoked
//! through the proxy, the proxy's implementation is used.
//!
//! # Architecture
//!
//! The module uses lazy static initialization to register tools at startup. Tools are
//! stored in static collections that are accessed when handling tool discovery and
//! invocation requests.
//!
//! # Feature Flags
//!
//! Some tools are conditionally compiled based on feature flags:
//! - `logwise`: Enables log capture and inspection tools (`LogwiseRead`, `LogwiseGrep`)
//!
use crate;
use HashMap;
use LazyLock;
/// Static collection of tools that are only available in the proxy application.
///
/// These tools are NOT available in the target application; the proxy's version
/// is always used. This includes tools for log inspection and other proxy-specific
/// functionality.
static PROXY_ONLY_TOOLS: = new;
/// Returns a list of all tools available in the proxy application.
///
/// This function combines proxy-only tools with shared tools to provide the complete
/// set of tools available when using the proxy. The returned list represents all tools
/// that clients can invoke through the proxy, regardless of whether they're implemented
/// in the proxy, the target application, or both.
///
/// # Returns
///
/// A `ToolList` containing metadata for all available tools, including:
/// - Tool names
/// - Descriptions
/// - Input schemas
/// Returns a list of tools that are exclusive to the proxy application.
///
/// These tools are not available in the target application and provide
/// proxy-specific functionality such as log inspection and monitoring.
/// The availability of specific tools depends on compile-time feature flags.
///
/// # Returns
///
/// A `ToolList` containing only the proxy-exclusive tools. This may be empty
/// if no proxy-only tools are compiled in (e.g., when the `logwise` feature is disabled).
///
/// Calls a tool on the proxy application.
///
/// This function executes tools locally in the proxy, considering both proxy-only
/// tools and shared tools. It first checks proxy-only tools, then shared tools.
/// For shared tools, only the proxy's version is used, not the target application's version.
///
/// # Arguments
///
/// * `params` - The tool call parameters including:
/// - `name`: The name of the tool to invoke
/// - `arguments`: A HashMap of parameter names to JSON values
///
/// # Returns
///
/// * `Ok(ToolCallResponse)` - The successful response from the tool
/// * `Err(Error)` - A JSON-RPC error if the tool is not found
///
/// # Error Handling
///
/// Tool execution errors are converted to successful responses with the error flag set,
/// following the MCP protocol convention. Only missing tools result in JSON-RPC errors.
///
/// Calls a tool that is exclusively available in the proxy application.
///
/// This function only considers proxy-only tools and will fail if the requested
/// tool is not in the proxy-only tool set. This is useful when you want to ensure
/// that a tool is handled by the proxy and not delegated to the target application.
///
/// # Arguments
///
/// * `params` - The tool call parameters including:
/// - `name`: The name of the proxy-only tool to invoke
/// - `arguments`: A HashMap of parameter names to JSON values
///
/// # Returns
///
/// * `Ok(ToolCallResponse)` - The successful response from the proxy-only tool
/// * `Err(Error)` - A JSON-RPC error if the tool is not found in proxy-only tools