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 Crypto from "effect/Crypto";
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 ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
19import * as McpInvocationContext from "../../McpInvocationContext.ts";
20
21const shared = {
22 failure: OrchestratorMcpFailure,
23 failureMode: "return" as const,
24 dependencies: [
25 McpInvocationContext.McpInvocationContext,
26 ThreadManagementService.ThreadManagementService,
27 ServerConfig.ServerConfig,
28 ServerSecretStore.ServerSecretStore,
29 FileSystem.FileSystem,
30 Crypto.Crypto,
31 ],
32};
33const AttachmentUploadTool = Tool.make("t3_attachment_prepare_upload", {
34 ...shared,
35 description:
36 "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`.",
37 parameters: Schema.Struct({ upload: AttachmentCreateUploadUrlInput }),
38 success: AttachmentCreateUploadUrlResult,
39}).annotate(Tool.Destructive, true);
40const AttachmentDiscardTool = Tool.make("t3_attachment_discard", {
41 ...shared,
42 description: "Discard a pending upload (not a sent attachment).",
43 parameters: AttachmentDeleteInput,
44 success: Schema.Struct({}),
45}).annotate(Tool.Destructive, true);
46const AttachmentSendTool = Tool.make("t3_thread_send_attachments", {
47 ...shared,
48 description:
49 "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.",
50 parameters: Schema.Struct({
51 threadId: Schema.optional(ThreadId),
52 message: Schema.optional(Schema.String.check(Schema.isMaxLength(120000))),
53 attachments: Schema.Array(McpAttachmentInput).check(
54 Schema.isMinLength(1),
55 Schema.isMaxLength(8),
56 ),
57 }),
58 success: Schema.Struct({
59 threadId: ThreadId,
60 messageId: MessageId,
61 runId: RunId,
62 status: OrchestrationV2RunStatus,
63 }),
64})
65 .annotate(Tool.Destructive, true)
66 .annotate(Tool.OpenWorld, true);
67export const AttachmentToolkit = Toolkit.make(
68 AttachmentUploadTool,
69 AttachmentDiscardTool,
70 AttachmentSendTool,
71);