Skip to content

Commit 069e152

Browse files
authored
Store safeinputs MCP server logs in artifact and add health endpoint (#5726)
1 parent f89757f commit 069e152

File tree

8 files changed

+178
-10
lines changed

8 files changed

+178
-10
lines changed

.github/workflows/copilot-pr-merged-report.lock.yml

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/daily-performance-summary.lock.yml

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dev.lock.yml

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/test-python-safe-input.lock.yml

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/workflow/compiler_yaml.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowDat
411411
// upload MCP logs (if any MCP tools were used)
412412
c.generateUploadMCPLogs(yaml)
413413

414+
// upload SafeInputs logs (if safe-inputs is enabled)
415+
if IsSafeInputsEnabled(data.SafeInputs, data) {
416+
c.generateUploadSafeInputsLogs(yaml)
417+
}
418+
414419
// parse agent logs for GITHUB_STEP_SUMMARY
415420
c.generateLogParsing(yaml, engine)
416421

@@ -653,6 +658,19 @@ func (c *Compiler) generateUploadMCPLogs(yaml *strings.Builder) {
653658
yaml.WriteString(" if-no-files-found: ignore\n")
654659
}
655660

661+
func (c *Compiler) generateUploadSafeInputsLogs(yaml *strings.Builder) {
662+
// Record artifact upload for validation
663+
c.stepOrderTracker.RecordArtifactUpload("Upload SafeInputs logs", []string{"/tmp/gh-aw/safe-inputs/logs/"})
664+
665+
yaml.WriteString(" - name: Upload SafeInputs logs\n")
666+
yaml.WriteString(" if: always()\n")
667+
yaml.WriteString(fmt.Sprintf(" uses: %s\n", GetActionPin("actions/upload-artifact")))
668+
yaml.WriteString(" with:\n")
669+
yaml.WriteString(" name: safeinputs\n")
670+
yaml.WriteString(" path: /tmp/gh-aw/safe-inputs/logs/\n")
671+
yaml.WriteString(" if-no-files-found: ignore\n")
672+
}
673+
656674
func splitContentIntoChunks(content string) []string {
657675
const maxChunkSize = 20900 // 21000 - 100 character buffer
658676
const indentSpaces = " " // 10 spaces added to each line

pkg/workflow/js/safe_inputs_mcp_server_http.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ async function startHttpServer(configPath, options = {}) {
178178
return;
179179
}
180180

181+
// Handle GET /health endpoint for health checks
182+
if (req.method === "GET" && req.url === "/health") {
183+
res.writeHead(200, { "Content-Type": "application/json" });
184+
res.end(
185+
JSON.stringify({
186+
status: "ok",
187+
server: config.serverName || "safeinputs",
188+
version: config.version || "1.0.0",
189+
tools: config.tools.length,
190+
})
191+
);
192+
return;
193+
}
194+
181195
// Only handle POST requests for MCP protocol
182196
if (req.method !== "POST") {
183197
res.writeHead(405, { "Content-Type": "application/json" });

pkg/workflow/js/safe_inputs_mcp_server_http.test.cjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,40 @@ describe("safe_inputs_mcp_server_http.cjs integration", () => {
171171
sessionId = response.headers["mcp-session-id"];
172172
});
173173

174+
it("should respond to GET /health endpoint", async () => {
175+
return new Promise((resolve, reject) => {
176+
const req = http.request(
177+
{
178+
hostname: "localhost",
179+
port: serverPort,
180+
path: "/health",
181+
method: "GET",
182+
},
183+
res => {
184+
let responseData = "";
185+
res.on("data", chunk => {
186+
responseData += chunk;
187+
});
188+
res.on("end", () => {
189+
try {
190+
expect(res.statusCode).toBe(200);
191+
const data = JSON.parse(responseData);
192+
expect(data.status).toBe("ok");
193+
expect(data.server).toBe("http-integration-test-server");
194+
expect(data.version).toBe("1.0.0");
195+
expect(data.tools).toBe(1);
196+
resolve();
197+
} catch (e) {
198+
reject(e);
199+
}
200+
});
201+
}
202+
);
203+
req.on("error", reject);
204+
req.end();
205+
});
206+
});
207+
174208
it("should list tools via HTTP", async () => {
175209
const headers = sessionId ? { "Mcp-Session-Id": sessionId } : {};
176210

pkg/workflow/sh/start_safe_inputs_server.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ echo " Working directory: $(pwd)"
2323
# Ensure logs directory exists
2424
mkdir -p /tmp/gh-aw/safe-inputs/logs
2525

26+
# Create initial server.log file for artifact upload
27+
echo "Safe Inputs MCP Server Log" > /tmp/gh-aw/safe-inputs/logs/server.log
28+
echo "Start time: $(date)" >> /tmp/gh-aw/safe-inputs/logs/server.log
29+
echo "===========================================" >> /tmp/gh-aw/safe-inputs/logs/server.log
30+
echo "" >> /tmp/gh-aw/safe-inputs/logs/server.log
31+
2632
# Start the HTTP server in the background
2733
echo "Starting safe-inputs MCP HTTP server..."
28-
node mcp-server.cjs > /tmp/gh-aw/safe-inputs/logs/server.log 2>&1 &
34+
node mcp-server.cjs >> /tmp/gh-aw/safe-inputs/logs/server.log 2>&1 &
2935
SERVER_PID=$!
3036
echo "Started safe-inputs MCP server with PID $SERVER_PID"
3137

@@ -41,7 +47,7 @@ for i in {1..10}; do
4147
fi
4248

4349
# Check if server is responding
44-
if curl -s -f -H "Authorization: Bearer $GH_AW_SAFE_INPUTS_API_KEY" http://localhost:$GH_AW_SAFE_INPUTS_PORT/ > /dev/null 2>&1; then
50+
if curl -s -f http://localhost:$GH_AW_SAFE_INPUTS_PORT/health > /dev/null 2>&1; then
4551
echo "Safe Inputs MCP server is ready (attempt $i/10)"
4652
break
4753
fi

0 commit comments

Comments
 (0)