From 0f7cedc07110adf3c1fdbabcf7e26c2f1964a7c3 Mon Sep 17 00:00:00 2001 From: Alex Weng Date: Tue, 4 Nov 2025 16:30:01 -0500 Subject: [PATCH 1/2] updated with debug info --- server/src/agents/jenkins-agent.js | 42 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/server/src/agents/jenkins-agent.js b/server/src/agents/jenkins-agent.js index 9ced09c..bd26774 100644 --- a/server/src/agents/jenkins-agent.js +++ b/server/src/agents/jenkins-agent.js @@ -3,14 +3,20 @@ import { Agent, run, MCPServerStreamableHttp } from "@openai/agents"; export async function askJenkins(question) { + const user = process.env.JENKINS_USER; + const token = process.env.JENKINS_TOKEN; // construct Basic Auth const authToken = Buffer.from( `${process.env.JENKINS_USER}:${process.env.JENKINS_TOKEN}` ).toString("base64"); + if (!user || !token) { + throw new Error("JENKINS_USER or JENKINS_TOKEN is not set in the environment"); + } // 1. URL change /mcp-server/mcp // 2. use requestInit.headers pass Authorization + console.log(authToken); const jenkinsMcp = new MCPServerStreamableHttp({ name: "jenkins-mcp", url: "https://jenkins.ilessai.com/mcp-server/mcp", @@ -24,30 +30,42 @@ export async function askJenkins(question) { await jenkinsMcp.connect(); + try { + console.log("[askJenkins] connecting to Jenkins MCP…"); + await jenkinsMcp.connect(); + console.log("[askJenkins] connected. Listing tools…"); + + const tools = await jenkinsMcp.listTools(); + console.log("[askJenkins] Jenkins MCP tools:", JSON.stringify(tools, null, 2)); + const agent = new Agent({ name: "Jenkins Assistant", instructions: ` You are an intelligent Jenkins assistant that can manage and query Jenkins jobs through the Model Context Protocol (MCP). - You have access to MCP tools provided by a Jenkins MCP server. - Use these tools whenever the user asks about: - - Job status, build history, build results - - Triggering builds - - Getting logs or console output - - Listing jobs or checking recent failures - Always use the appropriate MCP tool instead of making up an answer. - If the MCP response includes structured data (like JSON or status codes), summarize it clearly and naturally in plain English. - When the user asks something unrelated to Jenkins, politely clarify that you specialize in Jenkins automation and can help with jobs, builds, or logs. - If a tool call fails (for example, connection timeout or authentication error), provide a short diagnostic message like: - > “I wasn’t able to reach the Jenkins MCP server. Please verify your Jenkins URL or token.” - Keep answers short, factual, and professional. Use bullet points for lists or multiple jobs. + You have access to MCP tools provided by a Jenkins MCP server. + + When asked things like "what jobs exist" or "list jobs", you MUST call the getJobs tool. + Do not guess job names or statuses — always call a tool. + + If a tool call returns an error object like {"status":"FAILED","message":"..."}, + briefly summarize that message to the user instead of hiding it. `, mcpServers: [jenkinsMcp], }); + console.log("[askJenkins] running agent with question:", question); const result = await run(agent, question); + + // Inspect the full result for debugging: + console.dir(result, { depth: 5 }); + return result.finalOutput; + } catch (err) { + console.error("[askJenkins] ERROR:", err); + throw err; } finally { await jenkinsMcp.close(); + console.log("[askJenkins] MCP connection closed."); } } \ No newline at end of file From f5c8259b0ded80e845a1a25a5d7cd35ed3fd0276 Mon Sep 17 00:00:00 2001 From: Alex Weng Date: Tue, 4 Nov 2025 21:50:54 -0500 Subject: [PATCH 2/2] move jenkins endpoint before global err handler --- server/server.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/server.js b/server/server.js index 0fd36cc..12d0de4 100644 --- a/server/server.js +++ b/server/server.js @@ -135,6 +135,10 @@ app.use('/mcp/v1', mcpRoutes); // Mount GitHub OAuth routes at /auth/github app.use('/auth/github', githubAuthRouter); +app.use('/jenkins', jenkinsRouter); +// // Mount GitHub OAuth routes at /auth/github +// app.use('/auth/github', githubAuthRouter); + // --- Global Error Handler --- app.use((err, req, res, next) => { console.error('Global Error:', err); @@ -145,9 +149,7 @@ app.use((err, req, res, next) => { }); }); -app.use('/jenkins', jenkinsRouter); -// // Mount GitHub OAuth routes at /auth/github -// app.use('/auth/github', githubAuthRouter); + const port = process.env.PORT || 4000; app.listen(port, () => console.log(`API on http://localhost:${port}`));