Skip to content

Commit fbbdc93

Browse files
committed
feat: add functions to update protocol title and description
1 parent 683db67 commit fbbdc93

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

src/protocols_io_mcp/tools/protocol.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,6 @@ async def get_protocol_steps(
197197
steps = [ProtocolStep.from_api_response(step) for step in response.get("payload", [])]
198198
return steps
199199

200-
@mcp.tool()
201-
async def delete_protocol_step(
202-
protocol_id: Annotated[int, Field(description="Unique identifier for the protocol")],
203-
step_id: Annotated[str, Field(description="Unique identifier for the step to be deleted")]
204-
) -> list[ProtocolStep] | ErrorMessage:
205-
"""Delete a specific step from a protocol."""
206-
response_delete_protocol_step = await helpers.access_protocols_io_resource("DELETE", f"/v4/protocols/{protocol_id}/steps", {"steps": [step_id]})
207-
if response_delete_protocol_step["status_code"] != 0:
208-
return ErrorMessage.from_string(response_delete_protocol_step["status_text"])
209-
response_get_protocol_steps = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}/steps?content_format=markdown")
210-
if response_get_protocol_steps["status_code"] != 0:
211-
return ErrorMessage.from_string(response_get_protocol_steps["status_text"])
212-
steps = [ProtocolStep.from_api_response(step) for step in response_get_protocol_steps.get("payload", [])]
213-
return steps
214-
215200
@mcp.tool()
216201
async def create_protocol(
217202
title: Annotated[str, Field(description="Title of the new protocol")],
@@ -232,6 +217,38 @@ async def create_protocol(
232217
protocol = Protocol.from_api_response(response_get_protocol["payload"])
233218
return protocol
234219

220+
@mcp.tool()
221+
async def update_protocol_title(
222+
protocol_id: Annotated[int, Field(description="Unique identifier for the protocol")],
223+
title: Annotated[str, Field(description="New title for the protocol")]
224+
) -> Protocol | ErrorMessage:
225+
"""Update the title of an existing protocol."""
226+
data = {"title": title}
227+
response_update_protocol = await helpers.access_protocols_io_resource("PUT", f"/v4/protocols/{protocol_id}", data)
228+
if response_update_protocol["status_code"] != 0:
229+
return ErrorMessage.from_string(response_update_protocol["status_text"])
230+
response_get_protocol = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}")
231+
if response_get_protocol["status_code"] != 0:
232+
return ErrorMessage.from_string(response_get_protocol["status_text"])
233+
protocol = Protocol.from_api_response(response_get_protocol["payload"])
234+
return protocol
235+
236+
@mcp.tool()
237+
async def update_protocol_description(
238+
protocol_id: Annotated[int, Field(description="Unique identifier for the protocol")],
239+
description: Annotated[str, Field(description="New description for the protocol")]
240+
) -> Protocol | ErrorMessage:
241+
"""Update the description of an existing protocol."""
242+
data = {"description": description}
243+
response_update_protocol = await helpers.access_protocols_io_resource("PUT", f"/v4/protocols/{protocol_id}", data)
244+
if response_update_protocol["status_code"] != 0:
245+
return ErrorMessage.from_string(response_update_protocol["status_text"])
246+
response_get_protocol = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}")
247+
if response_get_protocol["status_code"] != 0:
248+
return ErrorMessage.from_string(response_get_protocol["status_text"])
249+
protocol = Protocol.from_api_response(response_get_protocol["payload"])
250+
return protocol
251+
235252
@mcp.tool()
236253
async def set_protocol_steps(
237254
protocol_id: Annotated[int, Field(description="Unique identifier for the protocol")],
@@ -299,4 +316,19 @@ async def add_protocol_step(
299316
if response_get_steps["status_code"] != 0:
300317
return ErrorMessage.from_string(response_get_steps["status_text"])
301318
protocol_steps = [ProtocolStep.from_api_response(step) for step in response_get_steps.get("payload", [])]
302-
return protocol_steps
319+
return protocol_steps
320+
321+
@mcp.tool()
322+
async def delete_protocol_step(
323+
protocol_id: Annotated[int, Field(description="Unique identifier for the protocol")],
324+
step_id: Annotated[str, Field(description="Unique identifier for the step to be deleted")]
325+
) -> list[ProtocolStep] | ErrorMessage:
326+
"""Delete a specific step from a protocol."""
327+
response_delete_protocol_step = await helpers.access_protocols_io_resource("DELETE", f"/v4/protocols/{protocol_id}/steps", {"steps": [step_id]})
328+
if response_delete_protocol_step["status_code"] != 0:
329+
return ErrorMessage.from_string(response_delete_protocol_step["status_text"])
330+
response_get_protocol_steps = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}/steps?content_format=markdown")
331+
if response_get_protocol_steps["status_code"] != 0:
332+
return ErrorMessage.from_string(response_get_protocol_steps["status_text"])
333+
steps = [ProtocolStep.from_api_response(step) for step in response_get_protocol_steps.get("payload", [])]
334+
return steps

0 commit comments

Comments
 (0)