Skip to content

Commit 580a9c9

Browse files
Add /llms.txt endpoint to serve LLM documentation file
Co-authored-by: 0xrinegade <[email protected]>
1 parent d21063b commit 580a9c9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/http_server.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl McpHttpServer {
6464
.route("/metrics", get(metrics_handler))
6565
.route("/health", get(health_handler))
6666
.route("/api/mcp", post(mcp_api_handler))
67+
.route("/llms.txt", get(llms_txt_handler))
6768
.with_state(state.clone())
6869
.layer(ServiceBuilder::new()
6970
.layer(TimeoutLayer::new(http_timeout))
@@ -73,6 +74,7 @@ impl McpHttpServer {
7374
Router::new()
7475
.route("/metrics", get(metrics_handler))
7576
.route("/health", get(health_handler))
77+
.route("/llms.txt", get(llms_txt_handler))
7678
.layer(ServiceBuilder::new()
7779
.layer(TimeoutLayer::new(http_timeout))
7880
)
@@ -181,6 +183,26 @@ async fn mcp_api_handler(
181183
}
182184
}
183185

186+
/// Handler for /llms.txt endpoint - serves the LLM documentation file
187+
async fn llms_txt_handler() -> Response {
188+
match tokio::fs::read_to_string("llms.txt").await {
189+
Ok(content) => {
190+
(
191+
StatusCode::OK,
192+
[("content-type", "text/plain; charset=utf-8")],
193+
content,
194+
).into_response()
195+
}
196+
Err(e) => {
197+
error!("Failed to read llms.txt: {}", e);
198+
(
199+
StatusCode::NOT_FOUND,
200+
"LLMs.txt file not found",
201+
).into_response()
202+
}
203+
}
204+
}
205+
184206
/// Parse and validate JSON-RPC 2.0 request according to MCP specification
185207
fn parse_json_rpc_request(request: &serde_json::Value) -> Result<JsonRpcRequest, Box<Response>> {
186208
// Validate required fields for JSON-RPC 2.0
@@ -315,4 +337,11 @@ mod tests {
315337
// This test ensures the function signature is correct and compiles
316338
// Real integration tests would be in a separate test file with proper setup
317339
}
340+
341+
#[tokio::test]
342+
async fn test_llms_txt_handler() {
343+
let response = llms_txt_handler().await;
344+
// The response should be either OK (if file exists) or NOT_FOUND (if file doesn't exist)
345+
// This test ensures the handler doesn't panic and returns a valid response
346+
}
318347
}

0 commit comments

Comments
 (0)