|
1 | 1 | use axum::{ |
2 | | - extract::State, |
| 2 | + extract::{Query, State}, |
3 | 3 | http::{header, HeaderMap, StatusCode}, |
4 | 4 | response::IntoResponse, |
5 | 5 | routing::{get, post}, |
6 | 6 | Json, Router, |
7 | 7 | }; |
8 | 8 | use serde_json::{json, Value}; |
| 9 | +use std::collections::HashMap; |
| 10 | + |
| 11 | +/// Coordinate-bearing commands that take a provider-tuned default size when the |
| 12 | +/// connection set ?model= and the caller gave no max_width/max_height. |
| 13 | +const MODEL_COORD_TOOLS: &[&str] = &[ |
| 14 | + "screenshot", "screenshot_region", "screenshot_window", "ui_tree", |
| 15 | + "get_screen_size", "click", "long_click", "drag", "scroll", |
| 16 | + "double_click", "right_click", "middle_click", "mouse_move", "mouse_scroll", |
| 17 | +]; |
9 | 18 | use std::sync::Arc; |
10 | 19 | use tokio::sync::RwLock; |
11 | 20 | use tracing::{error, info}; |
@@ -502,6 +511,7 @@ fn mcp_tool_definitions() -> Vec<Value> { |
502 | 511 |
|
503 | 512 | async fn handle_mcp_post( |
504 | 513 | State(state): State<AppState>, |
| 514 | + Query(query): Query<HashMap<String, String>>, |
505 | 515 | headers: HeaderMap, |
506 | 516 | Json(body): Json<Value>, |
507 | 517 | ) -> impl IntoResponse { |
@@ -562,7 +572,23 @@ async fn handle_mcp_post( |
562 | 572 | .and_then(|v| v.as_str()) |
563 | 573 | .unwrap_or("") |
564 | 574 | .to_string(); |
565 | | - let tool_args = params.get("arguments").cloned().unwrap_or(json!({})); |
| 575 | + let mut tool_args = params.get("arguments").cloned().unwrap_or(json!({})); |
| 576 | + |
| 577 | + // Inject the connection's model (from ?model=) so coordinate tools pick a |
| 578 | + // provider-tuned default size when the caller gave no max_width/max_height. |
| 579 | + if let Some(model) = query |
| 580 | + .get("model") |
| 581 | + .map(|s| s.as_str()) |
| 582 | + .filter(|m| matches!(*m, "claude" | "gemini" | "chatgpt")) |
| 583 | + { |
| 584 | + if MODEL_COORD_TOOLS.contains(&tool_name.as_str()) { |
| 585 | + if let Some(obj) = tool_args.as_object_mut() { |
| 586 | + if !obj.contains_key("max_width") && !obj.contains_key("max_height") { |
| 587 | + obj.insert("model".to_string(), json!(model)); |
| 588 | + } |
| 589 | + } |
| 590 | + } |
| 591 | + } |
566 | 592 |
|
567 | 593 | let config_clone = config.clone(); |
568 | 594 | drop(config); |
|
0 commit comments