feat: add guided MCP workflow prompts

This commit is contained in:
N0zoM1z0
2026-07-13 21:04:28 +08:00
parent 9f3639f29f
commit 24c3adb553
11 changed files with 1378 additions and 9 deletions
+54
View File
@@ -0,0 +1,54 @@
/** Extract the text payload used by packaged MCP smoke assertions. */
export const mcpText = (result) => {
const value = result.content?.find((item) => item.type === "text")?.text;
if (typeof value !== "string") throw new Error("MCP result omitted text");
return value;
};
/** Verify packaged prompt discovery and rendering through the public client. */
export const verifyPackagedPromptCatalog = async (
client,
options,
expectedNames,
) => {
const prompts = await client.listPrompts(undefined, options);
if (
JSON.stringify(prompts.prompts.map(({ name }) => name)) !==
JSON.stringify(expectedNames)
)
throw new Error("packaged MCP prompt inventory diverged from contracts");
const guided = await client.getPrompt(
{
name: "investigate_feature",
arguments: { feature: "fixture behavior" },
},
options,
);
const guidedText = guided.messages.find(
({ content }) => content.type === "text",
)?.content;
if (
guidedText?.type !== "text" ||
!guidedText.text.includes("`trace_feature`") ||
!guidedText.text.includes("Observations") ||
!guidedText.text.includes("Unknowns")
)
throw new Error("packaged MCP guided prompt rendering failed");
};
/** Verify live completion through the installed stdio MCP artifact. */
export const verifyPackagedPromptCompletion = async (client, options) => {
const result = await client.complete(
{
ref: { type: "ref/prompt", name: "investigate_feature" },
argument: { name: "document", value: "fix" },
},
options,
);
if (
JSON.stringify(result.completion.values) !== JSON.stringify(["fixture"]) ||
result.completion.total !== 1 ||
result.completion.hasMore !== false
)
throw new Error("packaged MCP prompt completion failed");
};
+12 -9
View File
@@ -14,9 +14,16 @@ import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { PROMPT_CONTRACTS } from "../dist/contracts/promptContracts.js";
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
import {
mcpText,
verifyPackagedPromptCatalog,
verifyPackagedPromptCompletion,
} from "./verify-package-prompts.mjs";
const expectedToolCount = TOOL_CONTRACTS.length;
const expectedPromptNames = PROMPT_CONTRACTS.map(({ name }) => name);
// Exercise the packed artifact in isolated HOME and prefix directories so the
// verifier cannot mutate real MCP registrations or rely on checkout-only files.
@@ -422,6 +429,7 @@ try {
expectedToolCount
)
throw new Error("packaged MCP tool inventory diverged from contracts");
await verifyPackagedPromptCatalog(client, mcpOptions, expectedPromptNames);
const result = await client.callTool(
{ name: "current_document", arguments: {} },
mcpOptions,
@@ -434,20 +442,21 @@ try {
);
if (opened.isError === true)
throw new Error("packaged MCP could not open a binary");
await verifyPackagedPromptCompletion(client, mcpOptions);
const current = await client.callTool(
{ name: "current_document", arguments: {} },
mcpOptions,
);
if (
current.isError === true ||
json(text(current)).normalized_result !== "fixture"
json(mcpText(current)).normalized_result !== "fixture"
)
throw new Error("packaged MCP bridge call failed");
const batch = await client.callTool(
{ name: "batch_decompile", arguments: { addresses: ["0x1000"] } },
mcpOptions,
);
const batchResult = json(text(batch)).normalized_result;
const batchResult = json(mcpText(batch)).normalized_result;
if (
batch.isError === true ||
batchResult?.total !== 1 ||
@@ -484,7 +493,7 @@ try {
}
process.stdout.write(
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, evidenceCli: true, incurMcpCommand: "npx -y rea-agents mcp", doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 2 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, skill: supportedSetupHost, mcpTools: expectedToolCount, evidenceMcp: true, targetFree: true, targetLifecycle: true })}\n`,
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, evidenceCli: true, incurMcpCommand: "npx -y rea-agents mcp", doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 2 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, skill: supportedSetupHost, mcpTools: expectedToolCount, mcpPrompts: expectedPromptNames.length, promptCompletion: true, evidenceMcp: true, targetFree: true, targetLifecycle: true })}\n`,
);
} finally {
if (tarball) await rm(join(root, tarball), { force: true });
@@ -497,9 +506,3 @@ async function run(command, args, env) {
function json(text) {
return JSON.parse(text);
}
function text(result) {
const value = result.content?.find((item) => item.type === "text")?.text;
if (typeof value !== "string") throw new Error("MCP result omitted text");
return value;
}