@@ -9,7 +9,7 @@ use std::net::SocketAddr;
99use tokio:: io:: { stdin, stdout} ;
1010use tracing_appender:: rolling:: { RollingFileAppender , Rotation } ;
1111use tracing_subscriber:: { self , EnvFilter , layer:: SubscriberExt , util:: SubscriberInitExt } ;
12- use regex :: Regex ;
12+ use cratedocs_mcp :: tools :: tldr ;
1313
1414#[ derive( Parser ) ]
1515#[ command( author, version = "0.2.0" , about, long_about = None ) ]
@@ -29,6 +29,9 @@ enum Commands {
2929 /// Enable debug logging
3030 #[ arg( short, long) ]
3131 debug : bool ,
32+ /// Summarize output by stripping LICENSE and VERSION sections (TL;DR mode)
33+ #[ arg( long) ]
34+ tldr : bool ,
3235 } ,
3336 /// Run the server with HTTP/SSE interface
3437 Http {
@@ -109,7 +112,7 @@ async fn main() -> Result<()> {
109112 println ! ( "{}" , env!( "CARGO_PKG_VERSION" ) ) ;
110113 Ok ( ( ) )
111114 } ,
112- Commands :: Stdio { debug } => run_stdio_server ( debug) . await ,
115+ Commands :: Stdio { debug, tldr } => run_stdio_server ( debug, tldr ) . await ,
113116 Commands :: Http { address, debug } => run_http_server ( address, debug) . await ,
114117 Commands :: Test {
115118 tool,
@@ -145,7 +148,7 @@ async fn main() -> Result<()> {
145148 }
146149}
147150
148- async fn run_stdio_server ( debug : bool ) -> Result < ( ) > {
151+ async fn run_stdio_server ( debug : bool , tldr : bool ) -> Result < ( ) > {
149152 // Set up file appender for logging
150153 let file_appender = RollingFileAppender :: new ( Rotation :: DAILY , "logs" , "stdio-server.log" ) ;
151154
@@ -164,13 +167,16 @@ async fn run_stdio_server(debug: bool) -> Result<()> {
164167 tracing:: info!( "Starting MCP documentation server in STDIN/STDOUT mode" ) ;
165168
166169 // Create an instance of our documentation router
167- let router = RouterService ( DocRouter :: new ( ) ) ;
170+ // If tldr is needed globally, you may want to pass it to DocRouter or handle it in tool output
171+ let router = RouterService ( DocRouter :: new_with_tldr ( tldr) ) ;
168172
169173 // Create and run the server
170174 let server = Server :: new ( router) ;
171175 let transport = ByteTransport :: new ( stdin ( ) , stdout ( ) ) ;
172176
173177 tracing:: info!( "Documentation server initialized and ready to handle requests" ) ;
178+ // Note: tldr is parsed and available, but not yet used in stdio mode.
179+ // If you want to apply TLDR globally, you would need to modify DocRouter or Server to use it.
174180 Ok ( server. run ( transport) . await ?)
175181}
176182
@@ -201,36 +207,6 @@ async fn run_http_server(address: String, debug: bool) -> Result<()> {
201207}
202208
203209// --- TLDR Helper Function ---
204- fn apply_tldr ( input : & str ) -> String {
205- // Remove LICENSE and VERSION(S) sections by skipping lines between those headings and the next heading or EOF.
206- let mut output = Vec :: new ( ) ;
207- let mut skip = false ;
208-
209- // Match any heading (with or without space) for LICENSE or VERSION(S)
210- let tldr_section_re = Regex :: new ( r"(?i)^\s*#+\s*license\b|^\s*#+\s*version(s)?\b|^\s*#+license\b|^\s*#+version(s)?\b" ) . unwrap ( ) ;
211- // Match any heading (for ending the skip)
212- let heading_re = Regex :: new ( r"^\s*#+" ) . unwrap ( ) ;
213- // Match <detail> tags including start, end, and inline attributes
214- let detail_tag_re = Regex :: new ( r"<[/]?detail.*?>" ) . unwrap ( ) ;
215-
216- for line in input. lines ( ) {
217- // Start skipping if we hit a LICENSE or VERSION(S) heading
218- if !skip && tldr_section_re. is_match ( line) {
219- skip = true ;
220- continue ; // skip the heading line itself
221- }
222- // Stop skipping at the next heading (but do not skip the heading itself)
223- if skip && heading_re. is_match ( line) && !tldr_section_re. is_match ( line) {
224- skip = false ;
225- }
226- if !skip {
227- // Remove <detail> tags from the line
228- let cleaned_line = detail_tag_re. replace_all ( line, "" ) . to_string ( ) ;
229- output. push ( cleaned_line. to_string ( ) ) ;
230- }
231- }
232- output. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) . join ( "\n " )
233- }
234210
235211/// Configuration for the test tool
236212struct TestToolConfig {
@@ -407,7 +383,7 @@ async fn run_test_tool(config: TestToolConfig) -> Result<()> {
407383
408384 // TL;DR processing: strip LICENSE and VERSION(S) sections if --tldr is set
409385 if tldr {
410- content_str = apply_tldr ( & content_str) ;
386+ content_str = tldr :: apply_tldr ( & content_str) ;
411387 }
412388
413389 let formatted_output = match format. as_str ( ) {
@@ -507,7 +483,7 @@ async fn run_test_tool(config: TestToolConfig) -> Result<()> {
507483}
508484#[ cfg( test) ]
509485mod tldr_tests {
510- use super :: apply_tldr;
486+ use cratedocs_mcp :: tools :: tldr :: apply_tldr;
511487
512488 #[ test]
513489 fn test_apply_tldr_removes_license_and_versions ( ) {
0 commit comments