Spaces:
Sleeping
Sleeping
kabudadada commited on
Commit ·
97961e2
1
Parent(s): bf433c8
revert(mcp_service): restore file to 05544d4 version
Browse files
esm/mcp_output/mcp_plugin/mcp_service.py
CHANGED
|
@@ -253,65 +253,6 @@ def validate_protein_sequence(sequence: str):
|
|
| 253 |
}
|
| 254 |
|
| 255 |
|
| 256 |
-
@mcp.tool(name="get_prediction_pdb", description="Download saved PDB by filename or latest; optionally re-save on server")
|
| 257 |
-
def get_prediction_pdb(filename: str, save_to_path: str | None = None):
|
| 258 |
-
"""Return PDB content saved under predictions directory.
|
| 259 |
-
|
| 260 |
-
Parameters:
|
| 261 |
-
filename (str): Filename in predictions directory. Use "latest" to fetch the most recent file.
|
| 262 |
-
|
| 263 |
-
Returns:
|
| 264 |
-
dict: success/result/error. result contains { filename, pdb_content, path }
|
| 265 |
-
"""
|
| 266 |
-
try:
|
| 267 |
-
import glob
|
| 268 |
-
predictions_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "predictions")
|
| 269 |
-
if not os.path.isdir(predictions_dir):
|
| 270 |
-
return {"success": False, "result": None, "error": f"Predictions dir not found: {predictions_dir}"}
|
| 271 |
-
|
| 272 |
-
target_path: str
|
| 273 |
-
if filename.strip().lower() == "latest":
|
| 274 |
-
files = sorted(
|
| 275 |
-
glob.glob(os.path.join(predictions_dir, "*.pdb")),
|
| 276 |
-
key=lambda p: os.path.getmtime(p),
|
| 277 |
-
reverse=True,
|
| 278 |
-
)
|
| 279 |
-
if not files:
|
| 280 |
-
return {"success": False, "result": None, "error": "No PDB files found"}
|
| 281 |
-
target_path = files[0]
|
| 282 |
-
filename = os.path.basename(target_path)
|
| 283 |
-
else:
|
| 284 |
-
# prevent path traversal
|
| 285 |
-
safe_name = os.path.basename(filename)
|
| 286 |
-
target_path = os.path.join(predictions_dir, safe_name)
|
| 287 |
-
if not os.path.isfile(target_path):
|
| 288 |
-
return {"success": False, "result": None, "error": f"File not found: {safe_name}"}
|
| 289 |
-
|
| 290 |
-
with open(target_path, "r") as f:
|
| 291 |
-
content = f.read()
|
| 292 |
-
|
| 293 |
-
# Optionally save a copy to a given path (inside container)
|
| 294 |
-
saved_to: str | None = None
|
| 295 |
-
if save_to_path:
|
| 296 |
-
try:
|
| 297 |
-
save_dir = os.path.dirname(save_to_path)
|
| 298 |
-
if save_dir and not os.path.isdir(save_dir):
|
| 299 |
-
os.makedirs(save_dir, exist_ok=True)
|
| 300 |
-
with open(save_to_path, "w") as out_f:
|
| 301 |
-
out_f.write(content)
|
| 302 |
-
saved_to = save_to_path
|
| 303 |
-
except Exception as save_err:
|
| 304 |
-
return {"success": False, "result": None, "error": f"Save failed: {save_err}"}
|
| 305 |
-
|
| 306 |
-
return {
|
| 307 |
-
"success": True,
|
| 308 |
-
"result": {"filename": filename, "pdb_content": content, "path": target_path, "saved_copy_path": saved_to},
|
| 309 |
-
"error": None,
|
| 310 |
-
}
|
| 311 |
-
except Exception as e:
|
| 312 |
-
return {"success": False, "result": None, "error": str(e)}
|
| 313 |
-
|
| 314 |
-
|
| 315 |
def create_app():
|
| 316 |
"""
|
| 317 |
Create and return a FastMCP instance.
|
|
|
|
| 253 |
}
|
| 254 |
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
def create_app():
|
| 257 |
"""
|
| 258 |
Create and return a FastMCP instance.
|