Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mcp_server_docker/input_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class FetchContainerLogsInput(JSONParsingModel):
tail: int | Literal["all"] = Field(
100, description="Number of lines to show from the end"
)
filter_string: str | None = Field(
None, description="Optional string to filter log lines by"
)


class ListContainersFilters(JSONParsingModel):
Expand Down
8 changes: 5 additions & 3 deletions src/mcp_server_docker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async def list_tools() -> list[types.Tool]:
),
types.Tool(
name="fetch_container_logs",
description="Fetch logs for a Docker container",
description="Fetch logs for a Docker container, with an optional string to filter logs by.",
inputSchema=FetchContainerLogsInput.model_json_schema(),
),
types.Tool(
Expand Down Expand Up @@ -396,8 +396,10 @@ async def call_tool(
elif name == "fetch_container_logs":
args = FetchContainerLogsInput(**arguments)
container = _docker.containers.get(args.container_id)
logs = container.logs(tail=args.tail).decode("utf-8")
result = {"logs": logs.split("\n")}
logs = container.logs(tail=args.tail).decode("utf-8").split("\n")
if args.filter_string:
logs = [line for line in logs if args.filter_string in line]
result = {"logs": logs}

elif name == "list_images":
args = ListImagesInput(**arguments)
Expand Down