mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-22 02:15:26 -06:00
4249df34b4
* feat(code-mode): expose tools as global functions * fix(code-mode): harden callable tool composition * fix(code-mode): reserve private guest globals * fix(cron): migrate legacy code-mode triggers * fix(code-mode): align final tool result contracts
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
// MCP code-mode probe server fixture shared by local and Docker E2E scripts.
|
|
import fs from "node:fs/promises";
|
|
import { createRequire } from "node:module";
|
|
import path from "node:path";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
export async function writeProbeMcpServer(serverPath: string) {
|
|
const sdkMcpServerPath = require.resolve("@modelcontextprotocol/sdk/server/mcp.js");
|
|
const sdkStdioServerPath = require.resolve("@modelcontextprotocol/sdk/server/stdio.js");
|
|
const zodPath = require.resolve("zod");
|
|
await fs.mkdir(path.dirname(serverPath), { recursive: true });
|
|
await fs.writeFile(
|
|
serverPath,
|
|
`#!/usr/bin/env node
|
|
import { McpServer } from ${JSON.stringify(sdkMcpServerPath)};
|
|
import { StdioServerTransport } from ${JSON.stringify(sdkStdioServerPath)};
|
|
import { z } from ${JSON.stringify(zodPath)};
|
|
|
|
const notes = new Map([
|
|
["alpha", "fixture-note-alpha"],
|
|
["beta", "fixture-note-beta"],
|
|
]);
|
|
const server = new McpServer({ name: "code-mode-fixture", version: "1.0.0" });
|
|
|
|
server.tool(
|
|
"lookup_note",
|
|
"Look up one read-only fixture note by id.",
|
|
{
|
|
id: z.string().describe("Fixture note id to look up."),
|
|
},
|
|
async ({ id }) => {
|
|
const note = notes.get(id);
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: note ?? "missing-note",
|
|
annotations: { audience: ["assistant"] },
|
|
_meta: { proof: "fixture-content-metadata" },
|
|
}],
|
|
structuredContent: { id, note: note ?? "missing-note" },
|
|
isError: note === undefined,
|
|
_meta: { private: "fixture-private-metadata" },
|
|
};
|
|
},
|
|
);
|
|
|
|
server.registerResource(
|
|
"fixture_note",
|
|
"memo://fixture/alpha",
|
|
{ description: "Fixture alpha note", mimeType: "text/plain" },
|
|
async (uri) => ({
|
|
contents: [{ uri: uri.href, mimeType: "text/plain", text: notes.get("alpha") }],
|
|
}),
|
|
);
|
|
|
|
server.registerPrompt(
|
|
"fixture_brief",
|
|
{ description: "A fixture note briefing", argsSchema: { id: z.string() } },
|
|
async ({ id }) => ({
|
|
description: "A fixture note briefing",
|
|
messages: [{ role: "user", content: { type: "text", text: notes.get(id) ?? "missing-note" } }],
|
|
}),
|
|
);
|
|
|
|
await server.connect(new StdioServerTransport());
|
|
`,
|
|
{ encoding: "utf8", mode: 0o755 },
|
|
);
|
|
}
|