Skip to content

Commit 10d57d2

Browse files
committed
Simplify logging configuration and cleanup unused code.
Removed redundant logging configuration logic and updated `logback.xml` to use environment variable defaults. Eliminated unused methods and test cases to streamline the `DockerMcpServer` implementation.
1 parent c228736 commit 10d57d2

File tree

3 files changed

+5
-41
lines changed

3 files changed

+5
-41
lines changed

src/main/java/io/github/makbn/mcp/mediator/docker/server/DockerMcpServer.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class DockerMcpServer {
1919
private static final String DOCKER_MCP_SERVER_VER = "1.0.0.0";
2020
private static final String DEFAULT_DOCKER_HOST = "unix:///var/run/docker.sock";
2121
private static final int DEFAULT_MAX_CONNECTIONS = 100;
22+
public static final String HEADER = "'DOCKER_MCP_LOG_FILE' and 'DOCKER_MCP_LOG_LEVEL' can be set as env variables to modify logging config";
2223

2324
public static void main(String[] args) {
2425
Options options = buildOptions();
2526
CommandLine cmd = parseOptions(args, options);
2627
try {
27-
configureLogging(cmd);
2828
String dockerHost = cmd.getOptionValue("docker-host", DEFAULT_DOCKER_HOST);
2929
String serverName = cmd.getOptionValue("server-name", DOCKER_MCP_SERVER);
3030
String serverVersion = cmd.getOptionValue("server-version", DOCKER_MCP_SERVER_VER);
@@ -53,25 +53,6 @@ public static void main(String[] args) {
5353
}
5454
}
5555

56-
private static void configureLogging(CommandLine cmd) {
57-
System.setProperty("DOCKER_MCP_LOG_FILE", cmd.getOptionValue("log-file", "logs/mcp_docker_server.log"));
58-
System.setProperty("DOCKER_MCP_LOG_LEVEL", cmd.getOptionValue("log-level", "DEBUG"));
59-
}
60-
61-
private static DockerClient intitializeDockerClient() {
62-
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
63-
.withDockerHost("unix:///var/run/docker.sock")
64-
.build();
65-
66-
DockerHttpClient client = new ApacheDockerHttpClient.Builder()
67-
.dockerHost(config.getDockerHost())
68-
.sslConfig(config.getSSLConfig())
69-
.maxConnections(100)
70-
.build();
71-
72-
return DockerClientImpl.getInstance(config, client);
73-
}
74-
7556
private static DockerClient initializeDockerClient(String dockerHost, int maxConnections, boolean tlsVerify, String certPath, String dockerConfig) {
7657
DefaultDockerClientConfig.Builder builder = DefaultDockerClientConfig.createDefaultConfigBuilder()
7758
.withDockerHost(dockerHost);
@@ -132,7 +113,7 @@ private static CommandLine parseOptions(String[] args, Options options) {
132113

133114
private static void printHelp(Options options) {
134115
HelpFormatter formatter = new HelpFormatter();
135-
formatter.printHelp("DockerMcpServer", options);
116+
formatter.printHelp("java -jar [SERVER_JAR_FILE] ", HEADER, options, "");
136117
}
137118

138119
}

src/main/resources/logback.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<configuration debug="false">
22
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
3-
<property name="DOCKER_MCP_LOG_FILE" value="logs/docker_mcp_server.log" />
4-
<property name="DOCKER_MCP_LOG_LEVEL" value="DEBUG" />
53

64
<!--No logging to the stdout while the server is running on stdio mode-->
75
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
8-
<file>${DOCKER_MCP_LOG_FILE}</file>
6+
<file>${DOCKER_MCP_LOG_FILE:-logs/docker_mcp_server.log}</file>
97
<encoder>
108
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n</pattern>
119
</encoder>
1210
</appender>
1311

14-
<root level="${DOCKER_MCP_LOG_LEVEL}">
15-
<appender-ref ref="FILE" />
12+
<root level="${DOCKER_MCP_LOG_LEVEL:-DEBUG}">
13+
<appender-ref ref="FILE"/>
1614
</root>
1715
</configuration>
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
package io.github.makbn.mediator.docker.handler;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.github.dockerjava.api.model.SwarmNodeSpec;
6-
import io.github.makbn.mcp.mediator.core.internal.McpMethodSchemaGenerator;
7-
import io.github.makbn.mcp.mediator.docker.internal.DockerClientService;
8-
import org.junit.jupiter.api.Test;
9-
103
class DockerClientServiceTest {
114

12-
@Test
13-
void testDockerClientService() throws NoSuchMethodException, JsonProcessingException {
14-
String schema = McpMethodSchemaGenerator.of(new ObjectMapper())
15-
.generateSchemaForMethod(DockerClientService.class.getMethod("updateSwarmNodeCmd", String.class, SwarmNodeSpec.class));
16-
17-
System.out.println(schema);
18-
}
19-
205
}
216

227

0 commit comments

Comments
 (0)