UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

28 lines (27 loc) • 1.84 kB
export const MCP_INJECTION_DROP_REASONS = Object.freeze(["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap"]); export const MCP_INJECTION_DROP_TEXT = { malformed_entry: "its declaration could not be read — fix the entry and start a new session", name_reserved_by_deployment: "the deployment mounts a server of that name and its own wins — rename the entry", gate_closed: "this deployment does not accept MCP servers from the request on this leg — ask the operator, or use the deployment's servers", over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list", }; const isReason = (x) => typeof x === "string" && MCP_INJECTION_DROP_REASONS.includes(x); export function mcpInjectionDroppedNotice(facts) { const { sessionId, server, reason, field } = facts; if (typeof sessionId !== "string" || sessionId.length === 0) { throw new TypeError("mcp.injection_dropped: sessionId is required — a user-audience notice with no session routes nowhere"); } if (typeof server !== "string" || server.length === 0) { throw new TypeError("mcp.injection_dropped: server name is required"); } if (!isReason(reason)) { throw new TypeError(`mcp.injection_dropped: reason ${JSON.stringify(reason)} is not one of ${MCP_INJECTION_DROP_REASONS.join("/")}`); } const fieldSeat = typeof field === "string" && field.length > 0 ? { field } : {}; const where = reason === "malformed_entry" && typeof field === "string" && field.length > 0 ? ` (field \`${field}\`)` : ""; return { code: "mcp.injection_dropped", message: `MCP server "${server}" from this request was not mounted: ${MCP_INJECTION_DROP_TEXT[reason]}${where}.`, detail: { sessionId, server, reason, ...fieldSeat }, }; }