Skip to content

Commit 71ffa5b

Browse files
committed
fix: Glama docker
1 parent 43eb9c1 commit 71ffa5b

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ build:
55
CGO_ENABLE=0 go build -o ./bin/server cmd/server/main.go
66
CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o ./bin/server-linux cmd/server/main.go
77

8+
build-multidb:
9+
CGO_ENABLE=0 go build -o ./multidb cmd/server/main.go
810
# Build the example stdio server
911
build-example:
1012
cd examples && go build -o mcp-example mcp_stdio_example.go

cmd/server/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"flag"
1111
"fmt"
12+
"log"
1213
"os"
1314
"os/signal"
1415
"path/filepath"
@@ -271,8 +272,15 @@ func main() {
271272
os.Setenv("MCP_DISABLE_LOGGING", "true")
272273
os.Setenv("DISABLE_LOGGING", "true")
273274

274-
// The logger initialization will handle file-based logging
275-
// Here we just ensure we don't introduce any printing to stdout
275+
// Ensure standard logger doesn't output to stdout for any imported libraries
276+
// that use the standard log package
277+
logFile, err := os.OpenFile(filepath.Join(logsDir, "stdio-server.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
278+
if err != nil {
279+
fmt.Fprintf(os.Stderr, "Failed to create stdio server log file: %v\n", err)
280+
} else {
281+
// Redirect all standard logging to the file
282+
log.SetOutput(logFile)
283+
}
276284

277285
// Critical: Use ServeStdio WITHOUT any console output to stdout
278286
if err := mcpServer.ServeStdio(); err != nil {

docker-wrapper.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# This wrapper script ensures proper STDIO handling for the MCP server in Docker
4+
5+
# Export required environment variables
6+
export MCP_DISABLE_LOGGING=true
7+
export DISABLE_LOGGING=true
8+
export TRANSPORT_MODE=stdio
9+
10+
# Create a log directory
11+
mkdir -p /tmp/logs
12+
13+
# Run the server with proper redirection
14+
# All stdout goes to the MCP proxy, while stderr goes to a file
15+
exec /app/multidb-linux -t stdio 2>/tmp/logs/server.log

multidb renamed to multidb-linux

11.1 MB
Binary file not shown.

test.Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ USER service-user
1010

1111
WORKDIR /app
1212

13-
# RUN git clone https://github.com/FreePeak/db-mcp-server . && git checkout 01bc85c8c93dbea90c1a2be729d7fd71b4d40f47
14-
COPY . .
13+
# RUN git clone https://github.com/FreePeak/db-mcp-server . && git checkout 43eb9c1247a0495952b45ac6223af1a9a207edbf
1514

16-
# Add -no-log flag to prevent non-JSON log messages from causing parse errors in mcp-proxy
17-
# This fixes errors like: SyntaxError: Unexpected token 'N', "No active "... is not valid JSON
18-
# Redirect stderr to /dev/null to ensure no log messages interfere with JSON-RPC communication
19-
# CMD ["sh", "-c", "exec mcp-proxy /app/server-linux -t stdio -no-log --stdio 2>/dev/null"]
15+
COPY ./multidb-linux /app/multidb-linux
16+
COPY ./docker-wrapper.sh /app/docker-wrapper.sh
2017

21-
CMD ["mcp-proxy", "/app/server-linux", "-t", "stdio", "-no-log", "--stdio"]
18+
# Setting environment variables to disable logging in the container
19+
ENV MCP_DISABLE_LOGGING=true \
20+
DISABLE_LOGGING=true \
21+
TRANSPORT_MODE=stdio
22+
23+
CMD ["mcp-proxy", "/app/docker-wrapper.sh"]

0 commit comments

Comments
 (0)