Skip to content

Commit fef13ab

Browse files
committed
refactor: simplify get_public_protocol_list_by_keyword and update create_or_update_protocol_step return type
1 parent f949f0c commit fef13ab

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/protocols_io_mcp/tools/protocol.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ async def get_user_protocol_list() -> list[Protocol] | ErrorResponse:
132132
return protocols
133133

134134
@mcp.tool()
135-
async def get_public_protocol_list_by_keyword(protocol_filter: Literal["public", "user_public", "user_private", "shared_with_user"], keyword: str, page_size: int = 10, page_id: int = 1) -> list[Protocol] | ErrorResponse:
136-
"""Get a list of public protocols on protocols.io by keyword."""
137-
response = await helpers.access_protocols_io_resource("GET", f"/v3/protocols?filter={protocol_filter}&key={keyword}&page_size={page_size}&page_id={page_id}")
135+
async def get_public_protocol_list_by_keyword(keyword: str, page_id: int = 1) -> list[Protocol] | ErrorResponse:
136+
"""Get a list of public protocols on protocols.io by keyword. Returns 3 protocols per page. Use page_id parameter for pagination (1-indexed)."""
137+
response = await helpers.access_protocols_io_resource("GET", f"/v3/protocols?filter=public&key={keyword}&page_size=3&page_id={page_id}")
138138
if response["status_code"] != 0:
139139
return ErrorResponse.from_api_response(response["error_message"])
140140
protocols = [await Protocol.from_api_response(protocol) for protocol in response.get("items", [])]
@@ -179,7 +179,7 @@ async def update_protocol(
179179
return protocol
180180

181181
@mcp.tool()
182-
async def create_or_update_protocol_step(protocol_id: int, steps: list[ProtocolStep]) -> Protocol | ErrorResponse:
182+
async def create_or_update_protocol_step(protocol_id: int, steps: list[ProtocolStep]) -> list[ProtocolStep] | ErrorResponse:
183183
"""Create or update the steps of a protocol on protocols.io, if the step already exists (identified by its ID), it will be updated, otherwise it will be created."""
184184
steps_data = []
185185
for step in steps:
@@ -198,11 +198,11 @@ async def create_or_update_protocol_step(protocol_id: int, steps: list[ProtocolS
198198
response = await helpers.access_protocols_io_resource("POST", f"/v4/protocols/{protocol_id}/steps", data)
199199
if response["status_code"] != 0:
200200
return ErrorResponse.from_api_response(response["status_text"])
201-
protocol_response = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}")
202-
if protocol_response["status_code"] != 0:
203-
return ErrorResponse.from_api_response(protocol_response["status_text"])
204-
protocol = await Protocol.from_api_response(protocol_response["payload"])
205-
return protocol
201+
response_steps = await helpers.access_protocols_io_resource("GET", f"/v4/protocols/{protocol_id}/steps")
202+
if response_steps["status_code"] != 0:
203+
return ErrorResponse.from_api_response(response_steps["status_text"])
204+
updated_steps = [ProtocolStep.from_api_response(step) for step in response_steps.get("payload", [])]
205+
return updated_steps
206206

207207
@mcp.tool()
208208
async def delete_protocol_step(protocol_id: int, step_ids: list[str]) -> Protocol | ErrorResponse:

0 commit comments

Comments
 (0)