@sema-agent/core
Version:
Stateless, task-oriented AI agent core
18 lines (17 loc) • 1.05 kB
JavaScript
const MCP_META_RESULT_SIZE_CAP = 500_000;
export function resolveMcpDeclaredResultSize(meta) {
const declared = meta?.["anthropic/maxResultSizeChars"];
if (typeof declared !== "number" || !Number.isFinite(declared) || declared <= 0)
return undefined;
return Math.min(declared, MCP_META_RESULT_SIZE_CAP);
}
const MCP_REQUIRES_USER_INTERACTION_META_KEY = "anthropic/requiresUserInteraction";
export function resolveMcpRequiresUserInteraction(meta) {
const value = meta?.[MCP_REQUIRES_USER_INTERACTION_META_KEY];
if (value === true)
return { declared: true };
if (value === undefined || value === false)
return { declared: false };
const kind = value === null ? "null" : Array.isArray(value) ? "an array" : typeof value === "object" ? "an object" : `a ${typeof value}`;
return { declared: false, advisory: `its _meta["${MCP_REQUIRES_USER_INTERACTION_META_KEY}"] is ${kind}, not the boolean true — the declaration is ignored, so this tool is judged like a server tool that did not declare it` };
}