improve mcp context initialization

This commit is contained in:
David Blass
2025-12-02 17:59:13 -05:00
parent 32f850d6ec
commit 23c18154ed
6 changed files with 54 additions and 111 deletions
+17 -44
View File
@@ -83859,7 +83859,7 @@ function query({
// package.json
var package_default = {
name: "@pullfrog/action",
version: "0.0.114",
version: "0.0.115",
type: "module",
files: [
"index.js",
@@ -121510,26 +121510,20 @@ var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRes
);
// mcp/shared.ts
function getPayload() {
const payloadEnv = process.env.PULLFROG_PAYLOAD;
if (!payloadEnv) {
throw new Error("PULLFROG_PAYLOAD environment variable is required");
}
try {
return JSON.parse(payloadEnv);
} catch (error41) {
throw new Error(
`Failed to parse PULLFROG_PAYLOAD: ${error41 instanceof Error ? error41.message : String(error41)}`
);
}
var mcpInitContext;
function initMcpContext(state) {
mcpInitContext = state;
}
function getMcpContext() {
if (!mcpInitContext) {
throw new Error("MCP context not initialized. Call initializeMcpContext first.");
}
return {
...mcpInitContext,
...parseRepoContext(),
octokit: new Octokit2({
auth: getGitHubInstallationToken()
}),
payload: getPayload()
})
};
}
var tool = (toolDef) => toolDef;
@@ -122299,17 +122293,6 @@ var ListPullRequestReviewsTool = tool({
});
// mcp/selectMode.ts
function getModes() {
const modesJson = process.env.PULLFROG_MODES;
if (modesJson) {
try {
return JSON.parse(modesJson);
} catch {
return [];
}
}
return [];
}
var SelectMode = type({
modeName: type.string.describe(
"the name of the mode to select (e.g., 'Plan', 'Build', 'Review', 'Prompt')"
@@ -122319,19 +122302,13 @@ var SelectModeTool = tool({
name: "select_mode",
description: "Select a mode and get its detailed prompt instructions. Call this first to determine which mode to use based on the request.",
parameters: SelectMode,
execute: contextualize(async ({ modeName }) => {
const allModes = getModes();
if (allModes.length === 0) {
return {
error: "No modes available. Modes must be provided via PULLFROG_MODES environment variable."
};
}
const selectedMode = allModes.find((m) => m.name.toLowerCase() === modeName.toLowerCase());
execute: contextualize(async ({ modeName }, ctx) => {
const selectedMode = ctx.modes.find((m) => m.name.toLowerCase() === modeName.toLowerCase());
if (!selectedMode) {
const availableModes = allModes.map((m) => m.name).join(", ");
const availableModes = ctx.modes.map((m) => m.name).join(", ");
return {
error: `Mode "${modeName}" not found. Available modes: ${availableModes}`,
availableModes: allModes.map((m) => ({ name: m.name, description: m.description }))
availableModes: ctx.modes.map((m) => ({ name: m.name, description: m.description }))
};
}
return {
@@ -122367,7 +122344,8 @@ async function findAvailablePort(startPort) {
}
throw new Error(`Could not find available port starting from ${startPort}`);
}
async function startMcpHttpServer() {
async function startMcpHttpServer(state) {
initMcpContext(state);
const server = new FastMCP({
name: ghPullfrogMcpName,
version: "0.0.1"
@@ -122711,12 +122689,6 @@ function parsePayload(inputs) {
}
}
async function startMcpServer(ctx) {
const repoContext = parseRepoContext();
const githubRepository = `${repoContext.owner}/${repoContext.name}`;
const allModes = [...modes, ...ctx.payload.modes || []];
process.env.GITHUB_REPOSITORY = githubRepository;
process.env.PULLFROG_MODES = JSON.stringify(allModes);
process.env.PULLFROG_PAYLOAD = JSON.stringify(ctx.payload);
const runId = process.env.GITHUB_RUN_ID;
if (runId) {
const workflowRunInfo = await fetchWorkflowRunInfo(runId);
@@ -122725,7 +122697,8 @@ async function startMcpServer(ctx) {
log.info(`\u{1F4DD} Using pre-created progress comment: ${workflowRunInfo.progressCommentId}`);
}
}
const { url: url2, close } = await startMcpHttpServer();
const allModes = [...modes, ...ctx.payload.modes || []];
const { url: url2, close } = await startMcpHttpServer({ payload: ctx.payload, modes: allModes });
ctx.mcpServerUrl = url2;
ctx.mcpServerClose = close;
log.info(`\u{1F680} MCP server started at ${url2}`);