cleanup
This commit is contained in:
+9
-8
@@ -3,15 +3,13 @@ mod tools;
|
||||
|
||||
use crate::{api::auth::MaybeBearerToken, app::state::AppState};
|
||||
use protocol::{
|
||||
ApiResponse, InitializeResult, JSONRPC_VERSION, jsonrpc_error, jsonrpc_notification_ok,
|
||||
jsonrpc_ok,
|
||||
ApiResponse, InitializeResult, JSONRPC_VERSION, JsonRpcRequest, jsonrpc_error,
|
||||
jsonrpc_notification_ok, jsonrpc_ok,
|
||||
};
|
||||
use rocket::{State, http::Status, post, serde::json::Json};
|
||||
use serde_json::Value;
|
||||
use tools::{handle_tool_call, tool_definitions};
|
||||
|
||||
pub use protocol::JsonRpcRequest;
|
||||
|
||||
#[post("/mcp", data = "<body>")]
|
||||
pub async fn route(
|
||||
body: Json<JsonRpcRequest>,
|
||||
@@ -32,10 +30,13 @@ pub async fn route(
|
||||
match request.method.as_str() {
|
||||
"initialize" => jsonrpc_ok(request.id, InitializeResult::new()),
|
||||
"notifications/initialized" => jsonrpc_notification_ok(),
|
||||
"tools/list" => match token.0 {
|
||||
Some(_) => jsonrpc_ok(request.id, tool_definitions()),
|
||||
None => missing_authorization(request.id),
|
||||
},
|
||||
"tools/list" => {
|
||||
if token.0.is_some() {
|
||||
jsonrpc_ok(request.id, tool_definitions())
|
||||
} else {
|
||||
missing_authorization(request.id)
|
||||
}
|
||||
}
|
||||
"tools/call" => {
|
||||
handle_tool_call(request.id, request.params, token.0.as_deref(), state).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user