guohanghui commited on
Commit
6a4bb83
·
verified ·
1 Parent(s): 5098010

Update biopython/mcp_output/mcp_plugin/mcp_service.py

Browse files
biopython/mcp_output/mcp_plugin/mcp_service.py CHANGED
@@ -11,6 +11,25 @@ from Bio.Entrez import efetch, esearch
11
 
12
  mcp = FastMCP("biopython_service")
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  @mcp.tool(name="seqio_parse", description="Parse sequence data from a file.")
15
  def seqio_parse(file_path: str, format: str) -> dict:
16
  """
@@ -25,7 +44,9 @@ def seqio_parse(file_path: str, format: str) -> dict:
25
  """
26
  try:
27
  sequences = list(parse(file_path, format))
28
- return {"success": True, "result": sequences, "error": None}
 
 
29
  except Exception as e:
30
  return {"success": False, "result": None, "error": str(e)}
31
 
@@ -43,7 +64,9 @@ def seqio_read(file_path: str, format: str) -> dict:
43
  """
44
  try:
45
  sequence = read(file_path, format)
46
- return {"success": True, "result": sequence, "error": None}
 
 
47
  except Exception as e:
48
  return {"success": False, "result": None, "error": str(e)}
49
 
 
11
 
12
  mcp = FastMCP("biopython_service")
13
 
14
+ def seqrecord_to_dict(record):
15
+ """Convert a SeqRecord object to a serializable dictionary."""
16
+ return {
17
+ "id": str(record.id),
18
+ "name": str(record.name),
19
+ "description": str(record.description),
20
+ "sequence": str(record.seq),
21
+ "length": len(record.seq),
22
+ "annotations": dict(record.annotations) if record.annotations else {},
23
+ "features": [
24
+ {
25
+ "type": f.type,
26
+ "location": str(f.location),
27
+ "qualifiers": dict(f.qualifiers)
28
+ }
29
+ for f in record.features
30
+ ] if record.features else []
31
+ }
32
+
33
  @mcp.tool(name="seqio_parse", description="Parse sequence data from a file.")
34
  def seqio_parse(file_path: str, format: str) -> dict:
35
  """
 
44
  """
45
  try:
46
  sequences = list(parse(file_path, format))
47
+ # Convert SeqRecord objects to serializable dictionaries
48
+ result = [seqrecord_to_dict(seq) for seq in sequences]
49
+ return {"success": True, "result": result, "error": None}
50
  except Exception as e:
51
  return {"success": False, "result": None, "error": str(e)}
52
 
 
64
  """
65
  try:
66
  sequence = read(file_path, format)
67
+ # Convert SeqRecord object to serializable dictionary
68
+ result = seqrecord_to_dict(sequence)
69
+ return {"success": True, "result": result, "error": None}
70
  except Exception as e:
71
  return {"success": False, "result": None, "error": str(e)}
72