Skip to content

Commit 39701f4

Browse files
authored
feat: add tracing and logging option (#8)
* fix: listing resource templates error when not supported * feat: add tracing * feat: add logger * chore: cleanup * chore: clippy * chore: update tests
1 parent 38c1b25 commit 39701f4

File tree

7 files changed

+295
-10
lines changed

7 files changed

+295
-10
lines changed

Cargo.lock

Lines changed: 159 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ thiserror = { version = "2.0" }
3030
handlebars = "6.3"
3131
html-escape = "0.2"
3232
regex = "1.1"
33-
path-clean = "1.0.1"
34-
33+
path-clean = "1.0"
34+
tracing = "0.1"
35+
tracing-subscriber = { version = "0.3", features = [
36+
"env-filter",
37+
"std",
38+
"fmt",
39+
] }
3540
[dev-dependencies]
3641
tempfile = "3"
3742

src/cli.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
fmt::Display,
23
io::{self, ErrorKind},
34
path::PathBuf,
45
};
@@ -15,6 +16,28 @@ pub enum Template {
1516
Txt,
1617
}
1718

19+
#[derive(Debug, Clone, ValueEnum, PartialEq)]
20+
#[allow(non_camel_case_types)]
21+
pub enum LogLevel {
22+
error,
23+
warn,
24+
info,
25+
debug,
26+
trace,
27+
}
28+
29+
impl Display for LogLevel {
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31+
match self {
32+
LogLevel::error => write!(f, "error"),
33+
LogLevel::warn => write!(f, "warn"),
34+
LogLevel::info => write!(f, "info"),
35+
LogLevel::debug => write!(f, "debug"),
36+
LogLevel::trace => write!(f, "trace"),
37+
}
38+
}
39+
}
40+
1841
#[derive(Subcommand, Debug)]
1942
pub enum DiscoveryCommand {
2043
/// Displays MCP server capability details in the terminal.
@@ -47,6 +70,9 @@ pub struct WriteOptions {
4770
)]
4871
pub template_string: Option<String>,
4972

73+
/// Specifies the logging level for the application (default: info)
74+
#[arg(long, short)]
75+
pub log_level: Option<LogLevel>,
5076
/// Command and arguments to launch the MCP server.
5177
#[arg(
5278
value_name = "MCP Launch Command",
@@ -98,6 +124,10 @@ conflicts_with_all = ["template", "template_string"])]
98124
)]
99125
pub template_string: Option<String>,
100126

127+
/// Specifies the logging level for the application (default: info)
128+
#[arg(long, short)]
129+
pub log_level: Option<LogLevel>,
130+
101131
/// Command and arguments to launch the MCP server.
102132
#[arg(
103133
value_name = "MCP Launch Command",
@@ -127,6 +157,14 @@ impl DiscoveryCommand {
127157
DiscoveryCommand::Print(print_args) => &print_args.mcp_server_cmd,
128158
}
129159
}
160+
161+
pub fn log_level(&self) -> &Option<LogLevel> {
162+
match self {
163+
DiscoveryCommand::Create(create_options) => &create_options.log_level,
164+
DiscoveryCommand::Update(update_options) => &update_options.log_level,
165+
DiscoveryCommand::Print(print_args) => &print_args.log_level,
166+
}
167+
}
130168
}
131169

132170
#[derive(Parser, Debug)]
@@ -156,6 +194,10 @@ pub struct CommandArguments {
156194
)]
157195
pub template_string: Option<String>,
158196

197+
/// Specifies the logging level for the application (default: info)
198+
#[arg(long, short)]
199+
pub log_level: Option<LogLevel>,
200+
159201
/// Command and arguments to launch the MCP server.
160202
#[arg(
161203
value_name = "MCP Launch Command",

0 commit comments

Comments
 (0)