Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] Structure preview capability errors (#3454)

Julius Marminge8d4a8b4f3179
diff --git a/apps/server/src/mcp/McpInvocationContext.test.ts b/apps/server/src/mcp/McpInvocationContext.test.ts
new file mode 100644
index 000000000..39c686890
--- /dev/null
+++ b/apps/server/src/mcp/McpInvocationContext.test.ts
@@ -0,0 +1,39 @@
+import { expect, it } from "@effect/vitest";
+import {
+ EnvironmentId,
+ PreviewAutomationUnavailableError,
+ ProviderInstanceId,
+ ThreadId,
+} from "@t3tools/contracts";
+import * as Effect from "effect/Effect";
+
+import * as McpInvocationContext from "./McpInvocationContext.ts";
+
+it.effect("reports the scoped credential context when preview capability is unavailable", () => {
+ const invocation: McpInvocationContext.McpInvocationScope = {
+ environmentId: EnvironmentId.make("environment-1"),
+ threadId: ThreadId.make("thread-1"),
+ providerSessionId: "provider-session-1",
+ providerInstanceId: ProviderInstanceId.make("codex"),
+ capabilities: new Set(),
+ issuedAt: 1,
+ expiresAt: 2,
+ };
+
+ return Effect.gen(function* () {
+ const error = yield* McpInvocationContext.requireMcpCapability("preview").pipe(
+ Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
+ Effect.flip,
+ );
+
+ expect(error).toBeInstanceOf(PreviewAutomationUnavailableError);
+ expect(error).toMatchObject({
+ capability: "preview",
+ environmentId: invocation.environmentId,
+ threadId: invocation.threadId,
+ providerSessionId: invocation.providerSessionId,
+ providerInstanceId: invocation.providerInstanceId,
+ });
+ expect(error.message).toBe("MCP credential does not grant the preview capability.");
+ });
+});
diff --git a/apps/server/src/mcp/McpInvocationContext.ts b/apps/server/src/mcp/McpInvocationContext.ts
index 0d3f84df4..b13bf2d31 100644
--- a/apps/server/src/mcp/McpInvocationContext.ts
+++ b/apps/server/src/mcp/McpInvocationContext.ts
@@ -1,5 +1,9 @@
-import type { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
-import { PreviewAutomationUnavailableError } from "@t3tools/contracts";
+import {
+ type EnvironmentId,
+ PreviewAutomationUnavailableError,
+ type ProviderInstanceId,
+ type ThreadId,
+} from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
@@ -26,7 +30,11 @@ export const requireMcpCapability = Effect.fn("mcp.requireCapability")(function*
const invocation = yield* McpInvocationContext;
if (!invocation.capabilities.has(capability)) {
return yield* new PreviewAutomationUnavailableError({
- message: `MCP credential does not grant the ${capability} capability.`,
+ capability,
+ environmentId: invocation.environmentId,
+ threadId: invocation.threadId,
+ providerSessionId: invocation.providerSessionId,
+ providerInstanceId: invocation.providerInstanceId,
});
}
return invocation;
diff --git a/packages/contracts/src/previewAutomation.ts b/packages/contracts/src/previewAutomation.ts
index d6b9f59ae..118fb8927 100644
--- a/packages/contracts/src/previewAutomation.ts
+++ b/packages/contracts/src/previewAutomation.ts
@@ -453,8 +453,18 @@ export type PreviewAutomationResponse = typeof PreviewAutomationResponse.Type;
export class PreviewAutomationUnavailableError extends Schema.TaggedErrorClass<PreviewAutomationUnavailableError>()(
"PreviewAutomationUnavailableError",
- { message: Schema.String },
-) {}
+ {
+ capability: Schema.Literal("preview"),
+ environmentId: EnvironmentId,
+ threadId: ThreadId,
+ providerSessionId: TrimmedNonEmptyString,
+ providerInstanceId: ProviderInstanceId,
+ },
+) {
+ override get message(): string {
+ return `MCP credential does not grant the ${this.capability} capability.`;
+ }
+}
const PreviewAutomationScopeErrorFields = {
operation: PreviewAutomationOperation,