MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/codesearch.rs:91–175  ·  view source on GitHub ↗
(
        &self,
        args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

89 }
90
91 async fn execute(
92 &self,
93 args: serde_json::Value,
94 ctx: ToolContext,
95 ) -> Result<ToolResult, ToolError> {
96 let params: CodeSearchParams = serde_json::from_value(args)
97 .map_err(|e| ToolError::InvalidArguments(format!("Invalid parameters: {}", e)))?;
98
99 ctx.ask_permission(
100 PermissionRequest::new("codesearch")
101 .with_pattern(&params.query)
102 .always_allow(),
103 )
104 .await?;
105
106 let tokens_num = params.tokens_num.clamp(1000, 50000);
107 let query = params.query.clone();
108
109 let client = Client::builder()
110 .timeout(std::time::Duration::from_secs(30))
111 .build()
112 .map_err(|e| {
113 ToolError::ExecutionError(format!("Failed to create HTTP client: {}", e))
114 })?;
115
116 let request = McpRequest {
117 jsonrpc: "2.0".to_string(),
118 id: 1,
119 method: "tools/call".to_string(),
120 params: McpParams {
121 name: "get_code_context_exa".to_string(),
122 arguments: McpArguments {
123 query: query.clone(),
124 tokens_num,
125 },
126 },
127 };
128
129 let abort_token = ctx.abort.clone();
130
131 let request_future = async {
132 client
133 .post(EXA_MCP_URL)
134 .header("Content-Type", "application/json")
135 .header("Accept", "application/json, text/event-stream")
136 .json(&request)
137 .send()
138 .await
139 .map_err(|e| ToolError::ExecutionError(format!("HTTP request failed: {}", e)))
140 };
141
142 tokio::select! {
143 result = request_future => {
144 let response = result?;
145
146 if !response.status().is_success() {
147 let status = response.status();
148 let error_text = response.text().await.unwrap_or_default();

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
ask_permissionMethod · 0.80
always_allowMethod · 0.80
with_patternMethod · 0.80
buildMethod · 0.80
cloneMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected