github_mcp/tools/call_tool.rs
1// GitHub v3 REST API MCP server โ generated by mcpify. Do not hand-edit.
2
3use crate::auth::auth_manager::AuthManager;
4use crate::auth::request_credentials::RequestCredentials;
5use crate::core::config_schema::Config;
6use crate::data::store::EndpointRecord;
7use crate::services::api_client::ApiClient;
8use crate::validation::validator::{validate_input, validate_output};
9
10/// Validates arguments against the input schema, injects the active auth
11/// strategy's credentials, executes the live HTTP request, and validates
12/// the response against the output schema before returning it โ PRD
13/// ยง1.5's `call` pipeline (architecture.md's 4-step `call` pipeline),
14/// protecting the calling agent from upstream API drift.
15///
16/// Takes an already-looked-up `EndpointRecord` rather than a `Connection`
17/// and an `operation_id` to look up itself: `rusqlite::Connection` isn't
18/// `Sync`, so a `&Connection` held across this function's `.await` points
19/// (the HTTP call) would make the caller's future non-`Send` โ a hard
20/// requirement for `#[tool]` methods (Story R6). Callers look the
21/// endpoint up (a synchronous, `Connection`-scoped step) before calling
22/// this function, not inside it.
23pub async fn call_operation(
24 endpoint: &EndpointRecord,
25 config: &Config,
26 auth_manager: &mut AuthManager,
27 operation_id: &str,
28 args: serde_json::Value,
29 request_override: Option<&RequestCredentials>,
30) -> anyhow::Result<serde_json::Value> {
31 validate_input(&config.api_version, operation_id, &args)?;
32
33 let client = ApiClient::new(config.clone());
34 let response = client
35 .execute(endpoint, &args, auth_manager, request_override)
36 .await?;
37
38 validate_output(&config.api_version, operation_id, &response)?;
39 Ok(response)
40}