Review a generated scoped source tool

from Agent instructions and MCP
Node 24 advanced 10 min 4 issues to find

Review this generated MCP-style handler before connecting it to an agent.

Implement read_source for authenticated callers: accept exactly one relative .ts path under /srv/project/src, reject missing or extra fields with a structured error, read at most 4096 valid UTF-8 bytes, and return canonical path and byte count matching the declared output schema.

JavaScript
import { readFile } from "node:fs/promises";

export const tool = {
  name: "read_source",
  inputSchema: {
    type: "object",
    properties: { path: { type: "string" } },
    required: ["path"],
    additionalProperties: false,
  },
  outputSchema: {
    type: "object",
    required: ["path", "bytes"],
  },
};

export async function readSource(args, caller) {
  if (!caller.canReadSource) return { isError: true };
  const fullPath = `/srv/project/src/${args.path}`;
  const text = await readFile(fullPath, "utf8");
  return {
    structuredContent: { path: args.path, bytes: text.length },
    content: [{ type: "text", text }],
  };
}

generated code is illustrative, not from any one model

Open in playground
Report an error