Skip to content

Commit 2c4a0e1

Browse files
authored
Merge pull request QuantGeekDev#1 from QuantGeekDev/experimental
Experimental
2 parents d86b471 + c0fe715 commit 2c4a0e1

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ wheels/
1010
.venv
1111
conf
1212
work
13-
README_PRIVATE.md
13+
README_PRIVATE.md
14+
docker_compose_files

src/docker_mcp/server.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def __init__(self, compose_file: str, project_name: str):
4747

4848
async def run_command(self, command: str, *args) -> Tuple[int, str, str]:
4949
if platform.system() == 'Windows':
50-
compose_file = self.compose_file.replace(
51-
'\\', '/')
50+
compose_file = self.compose_file.replace('\\', '/')
5251
cmd = f'cd "{os.path.dirname(compose_file)}" && docker compose -f "{os.path.basename(
5352
compose_file)}" -p {self.project_name} {command} {" ".join(args)}'
5453

@@ -134,7 +133,12 @@ async def handle_get_prompt(name: str, arguments: dict[str, str] | None) -> type
134133
if not arguments or "requirements" not in arguments or "project_name" not in arguments:
135134
raise ValueError("Missing required arguments")
136135

137-
system_message = "You are a Docker deployment specialist. Generate appropriate Docker Compose YAML or container configurations based on user requirements. For simple single-container deployments, use the create-container tool. For multi-container deployments, generate a docker-compose.yml and use the deploy-compose tool."
136+
system_message = (
137+
"You are a Docker deployment specialist. Generate appropriate Docker Compose YAML or "
138+
"container configurations based on user requirements. For simple single-container "
139+
"deployments, use the create-container tool. For multi-container deployments, generate "
140+
"a docker-compose.yml and use the deploy-compose tool."
141+
)
138142
user_message = f"""Please help me deploy the following stack:
139143
Requirements: {arguments['requirements']}
140144
Project name: {arguments['project_name']}
@@ -157,10 +161,20 @@ async def handle_get_prompt(name: str, arguments: dict[str, str] | None) -> type
157161
return types.GetPromptResult(
158162
description="Generate and deploy a Docker stack",
159163
messages=[
160-
types.PromptMessage(role="system", content=types.TextContent(
161-
type="text", text=system_message)),
162-
types.PromptMessage(role="user", content=types.TextContent(
163-
type="text", text=user_message))
164+
types.PromptMessage(
165+
role="system",
166+
content=types.TextContent(
167+
type="text",
168+
text=system_message
169+
)
170+
),
171+
types.PromptMessage(
172+
role="user",
173+
content=types.TextContent(
174+
type="text",
175+
text=user_message
176+
)
177+
)
164178
]
165179
)
166180

@@ -248,28 +262,31 @@ async def pull_and_run():
248262
)
249263
return container
250264

251-
container = await asyncio.wait_for(pull_and_run(), timeout=30)
265+
TIMEOUT_AMOUNT = 200
266+
container = await asyncio.wait_for(pull_and_run(), timeout=TIMEOUT_AMOUNT)
252267
return [types.TextContent(type="text", text=f"Created container '{container.name}' (ID: {container.id})")]
253268
except asyncio.TimeoutError:
254-
return [types.TextContent(type="text", text="Operation timed out after 30 seconds")]
269+
return [types.TextContent(type="text", text="Operation timed out after 200 seconds")]
255270
except Exception as e:
256271
return [types.TextContent(type="text", text=f"Error creating container: {str(e)} | Arguments: {arguments}")]
257272

258273

259274
async def handle_deploy_compose(arguments: dict) -> list[types.TextContent]:
275+
debug_info = []
260276
try:
261277
compose_yaml = arguments.get("compose_yaml")
262278
project_name = arguments.get("project_name")
263279

264280
if not compose_yaml or not project_name:
265281
raise ValueError("Missing required compose_yaml or project_name")
266282

267-
debug_info = ["=== Original YAML ===", compose_yaml]
283+
debug_info.append("=== Original YAML ===")
284+
debug_info.append(compose_yaml)
268285

269286
try:
270287
yaml_content = yaml.safe_load(compose_yaml)
271-
debug_info.extend(
272-
["\n=== Loaded YAML Structure ===", str(yaml_content)])
288+
debug_info.append("\n=== Loaded YAML Structure ===")
289+
debug_info.append(str(yaml_content))
273290
compose_yaml = yaml.safe_dump(
274291
yaml_content, default_flow_style=False, sort_keys=False)
275292
except yaml.YAMLError as e:
@@ -290,7 +307,7 @@ async def handle_deploy_compose(arguments: dict) -> list[types.TextContent]:
290307
debug_info.append(f"\n=== Compose File Path ===\n{compose_path}")
291308

292309
if platform.system() == 'Windows':
293-
debug_info.append(f"\n=== PowerShell Command ===")
310+
debug_info.append("\n=== PowerShell Command ===")
294311
cmd_parts = [
295312
"docker compose",
296313
f"-f \"{compose_path}\"",
@@ -340,8 +357,11 @@ async def handle_deploy_compose(arguments: dict) -> list[types.TextContent]:
340357

341358
return [types.TextContent(
342359
type="text",
343-
text=f"Successfully deployed compose stack '{project_name}'\nRunning services:\n{
344-
service_info}\n\nDebug Info:\n{chr(10).join(debug_info)}"
360+
text=(
361+
f"Successfully deployed compose stack '{project_name}'\n"
362+
f"Running services:\n{service_info}\n\n"
363+
f"Debug Info:\n{chr(10).join(debug_info)}"
364+
)
345365
)]
346366

347367
finally:
@@ -357,8 +377,10 @@ async def handle_deploy_compose(arguments: dict) -> list[types.TextContent]:
357377
debug_output = "\n".join(debug_info)
358378
return [types.TextContent(
359379
type="text",
360-
text=f"Error deploying compose stack: {
361-
str(e)}\n\nDebug Information:\n{debug_output}"
380+
text=(
381+
f"Error deploying compose stack: {str(e)}\n\n"
382+
f"Debug Information:\n{debug_output}"
383+
)
362384
)]
363385

364386

@@ -400,3 +422,7 @@ async def main():
400422
),
401423
),
402424
)
425+
426+
427+
if __name__ == "__main__":
428+
asyncio.run(main())

0 commit comments

Comments
 (0)