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
+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;
}