Skip to content
Source
Sign inSign up
Open History to see the last commit

mcpApps.ts

94 lines3.1 KB

1import * as Schema from "effect/Schema";
2​
3import { ThreadId, TrimmedNonEmptyString, TurnItemId } from "./baseSchemas.ts";
4​
5// The producing tool call restricts each app to its source server.
6const McpAppTarget = {
7 threadId: ThreadId,
8 itemId: TurnItemId,
9};
10​
11export const McpAppCallToolInput = Schema.Struct({
12 ...McpAppTarget,
13 name: TrimmedNonEmptyString,
14 arguments: Schema.Record(Schema.String, Schema.Unknown),
15});
16export type McpAppCallToolInput = typeof McpAppCallToolInput.Type;
17​
18export const McpAppCallToolResult = Schema.Struct({
19 content: Schema.Array(Schema.Unknown),
20 structuredContent: Schema.optional(Schema.Unknown),
21 isError: Schema.optional(Schema.Boolean),
22 _meta: Schema.optional(Schema.Unknown),
23});
24export type McpAppCallToolResult = typeof McpAppCallToolResult.Type;
25​
26export const McpAppToolInfoInput = Schema.Struct({
27 ...McpAppTarget,
28 name: TrimmedNonEmptyString,
29});
30export type McpAppToolInfoInput = typeof McpAppToolInfoInput.Type;
31​
32export const McpAppToolInfo = Schema.Struct({
33 callable: Schema.Boolean,
34 readOnly: Schema.Boolean,
35 title: Schema.optional(Schema.String),
36 tool: Schema.optional(Schema.Unknown),
37});
38export type McpAppToolInfo = typeof McpAppToolInfo.Type;
39​
40export const McpAppReadResourceInput = Schema.Struct({
41 ...McpAppTarget,
42 uri: TrimmedNonEmptyString,
43});
44export type McpAppReadResourceInput = typeof McpAppReadResourceInput.Type;
45​
46export const McpAppReadResourceResult = Schema.Struct({
47 contents: Schema.Array(Schema.Unknown),
48});
49export type McpAppReadResourceResult = typeof McpAppReadResourceResult.Type;
50​
51/** Replaces prior context; no content clears it. */
52export const McpAppUpdateModelContextInput = Schema.Struct({
53 ...McpAppTarget,
54 conversationThreadId: ThreadId,
55 content: Schema.optional(Schema.Array(Schema.Unknown)),
56 structuredContent: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
57});
58export type McpAppUpdateModelContextInput = typeof McpAppUpdateModelContextInput.Type;
59​
60export const McpAppRequestErrorReason = Schema.Literals([
61 "not-an-app",
62 "provider-unsupported",
63 "session-stopped",
64 "tool-not-callable",
65 "unsupported-content",
66 "request-failed",
67]);
68export type McpAppRequestErrorReason = typeof McpAppRequestErrorReason.Type;
69​
70export class McpAppRequestError extends Schema.TaggedError<McpAppRequestError>()(
71 "McpAppRequestError",
72 {
73 threadId: ThreadId,
74 reason: McpAppRequestErrorReason,
75 cause: Schema.optional(Schema.Defect()),
76 },
77) {
78 override get message(): string {
79 switch (this.reason) {
80 case "not-an-app":
81 return "This tool call has no MCP app.";
82 case "provider-unsupported":
83 return "This thread's provider cannot run MCP app requests.";
84 case "session-stopped":
85 return "The app's thread is not running. Send a message in the thread that created it to use the app again.";
86 case "tool-not-callable":
87 return "This app cannot call that tool.";
88 case "unsupported-content":
89 return "Only text and structured content are supported.";
90 case "request-failed":
91 return "The app's MCP server request failed.";
92 }
93 }