Open History to see the last commit
1import { McpAttachmentInput } from "./input.ts";
2import {
3 AttachmentCreateUploadUrlInput,
4 AttachmentCreateUploadUrlResult,
5 AttachmentDeleteInput,
6 MessageId,
7 RunId,
8 ThreadId,
9 OrchestrationV2RunStatus,
10 OrchestratorMcpFailure,
11} from "@t3tools/contracts";
12import * as SecureRandom from "effect/crypto/SecureRandom";
13import * as FileSystem from "effect/FileSystem";
14import * as Schema from "effect/Schema";
15import { Tool, Toolkit } from "effect/ai";
16import * as ServerSecretStore from "../../../auth/ServerSecretStore.ts";
17import * as ServerConfig from "../../../config.ts";
18import * as DocumentText from "../../../provider/DocumentText.ts";
19import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
20import * as McpInvocationContext from "../../McpInvocationContext.ts";
21
22const shared = {
23 failure: OrchestratorMcpFailure,
24 failureMode: "return" as const,
25 dependencies: [
26 McpInvocationContext.McpInvocationContext,
27 ThreadManagementService.ThreadManagementService,
28 ServerConfig.ServerConfig,
29 ServerSecretStore.ServerSecretStore,
30 FileSystem.FileSystem,
31 SecureRandom.SecureRandom,
32 ],
33};
34const AttachmentUploadTool = Tool.make("t3_attachment_prepare_upload", {
35 ...shared,
36 description:
37 "Get an upload URL. POST the file's exact bytes to `relativeUrl` on this MCP server's HTTP origin, then send via `t3_thread_send_attachments` with the returned `attachmentId`.",
38 parameters: Schema.Struct({ upload: AttachmentCreateUploadUrlInput }),
39 success: AttachmentCreateUploadUrlResult,
40}).annotate(Tool.Destructive, true);
41const AttachmentDiscardTool = Tool.make("t3_attachment_discard", {
42 ...shared,
43 description: "Discard a pending upload (not a sent attachment).",
44 parameters: AttachmentDeleteInput,
45 success: Schema.Struct({}),
46}).annotate(Tool.Destructive, true);
47const AttachmentSendTool = Tool.make("t3_thread_send_attachments", {
48 ...shared,
49 dependencies: [...shared.dependencies, DocumentText.DocumentText],
50 description:
51 "Send uploaded attachments as a new message to a thread. No retry key. Target modes cannot exceed yours. Success does not mean the provider read them or finished.",
52 parameters: Schema.Struct({
53 threadId: Schema.optional(ThreadId),
54 message: Schema.optional(Schema.String.check(Schema.isMaxLength(120000))),
55 attachments: Schema.Array(McpAttachmentInput).check(
56 Schema.isMinLength(1),
57 Schema.isMaxLength(8),
58 ),
59 }),
60 success: Schema.Struct({
61 threadId: ThreadId,
62 messageId: MessageId,
63 runId: RunId,
64 status: OrchestrationV2RunStatus,
65 }),
66})
67 .annotate(Tool.Destructive, true)
68 .annotate(Tool.OpenWorld, true);
69export const AttachmentToolkit = Toolkit.make(
70 AttachmentUploadTool,
71 AttachmentDiscardTool,
72 AttachmentSendTool,
73);