From 51bd6ea9547fc78c2f5bd98d3b882c3e199d60ec Mon Sep 17 00:00:00 2001 From: Adolfo Delorenzo Date: Fri, 18 Jul 2025 21:42:59 -0300 Subject: [PATCH] Fix: Update stack creation endpoint for Git repositories - Use correct endpoint /api/stacks/create/standalone/repository - Fix field names to lowercase for this endpoint - Add proper authentication handling - Remove incorrect query parameters --- portainer_stacks_server.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/portainer_stacks_server.py b/portainer_stacks_server.py index 9089955..917819d 100755 --- a/portainer_stacks_server.py +++ b/portainer_stacks_server.py @@ -568,29 +568,30 @@ async def handle_call_tool( elif name == "create_compose_stack_from_git": env_id = arguments["environment_id"] - # Build request data + # Build request data with lowercase field names for this endpoint data = { - "Name": arguments["name"], - "EndpointId": int(env_id), - "GitConfig": { - "URL": arguments["repository_url"], - "ReferenceName": arguments.get("repository_ref", "main"), - "ComposeFilePathInRepository": arguments.get("compose_path", "docker-compose.yml") - } + "name": arguments["name"], + "repositoryURL": arguments["repository_url"], + "repositoryReferenceName": arguments.get("repository_ref", "main"), + "composeFilePathInRepository": arguments.get("compose_path", "docker-compose.yml") } # Add authentication if provided if arguments.get("repository_auth") and arguments.get("repository_username"): - data["GitConfig"]["Authentication"] = { - "Username": arguments["repository_username"], - "Password": arguments.get("repository_password", "") - } + data["repositoryAuthentication"] = True + data["repositoryUsername"] = arguments["repository_username"] + data["repositoryPassword"] = arguments.get("repository_password", "") + else: + data["repositoryAuthentication"] = False # Add environment variables if provided if arguments.get("env_vars"): - data["Env"] = arguments["env_vars"] + data["env"] = arguments["env_vars"] - result = await make_request("POST", "/api/stacks", json_data=data) + # Use the correct endpoint for standalone Docker stack creation from Git + endpoint = f"/api/stacks/create/standalone/repository?endpointId={env_id}" + + result = await make_request("POST", endpoint, json_data=data) if "error" in result: return [types.TextContent(type="text", text=f"Error: {result['error']}")]