MCPcopy Create free account
hub / github.com/AI45Lab/Code / write_file

Method write_file

sdk/python/src/lib.rs:2054–2070  ·  view source on GitHub ↗

Write a file in the workspace.

(&self, py: Python<'_>, path: String, content: String)

Source from the content-addressed store, hash-verified

2052
2053 /// Write a file in the workspace.
2054 fn write_file(&self, py: Python<'_>, path: String, content: String) -> PyResult<PyToolResult> {
2055 let session = self.inner.clone();
2056 let result = py
2057 .allow_threads(move || get_runtime().block_on(session.write_file(&path, &content)))
2058 .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
2059
2060 Ok(PyToolResult {
2061 name: result.name,
2062 output: result.output,
2063 exit_code: result.exit_code,
2064 metadata_json: result.metadata.as_ref().map(serde_json::Value::to_string),
2065 error_kind_json: result
2066 .error_kind
2067 .as_ref()
2068 .and_then(|k| serde_json::to_string(k).ok()),
2069 })
2070 }
2071
2072 /// List a directory in the workspace.
2073 #[pyo3(signature = (path=None))]

Callers 1

Calls 3

block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected