The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | import { ThreadId, TrimmedNonEmptyString, TurnItemId } from "./baseSchemas.ts"; |
| 4 | |
| 5 | // The producing tool call restricts each app to its source server. |
| 6 | const McpAppTarget = { |
| 7 | threadId: ThreadId, |
| 8 | itemId: TurnItemId, |
| 9 | }; |
| 10 | |
| 11 | export const McpAppCallToolInput = Schema.Struct({ |
| 12 | ...McpAppTarget, |
| 13 | name: TrimmedNonEmptyString, |
| 14 | arguments: Schema.Record(Schema.String, Schema.Unknown), |
| 15 | }); |
| 16 | export type McpAppCallToolInput = typeof McpAppCallToolInput.Type; |
| 17 | |
| 18 | export 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 | }); |
| 24 | export type McpAppCallToolResult = typeof McpAppCallToolResult.Type; |
| 25 | |
| 26 | export const McpAppToolInfoInput = Schema.Struct({ |
| 27 | ...McpAppTarget, |
| 28 | name: TrimmedNonEmptyString, |
| 29 | }); |
| 30 | export type McpAppToolInfoInput = typeof McpAppToolInfoInput.Type; |
| 31 | |
| 32 | export 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 | }); |
| 38 | export type McpAppToolInfo = typeof McpAppToolInfo.Type; |
| 39 | |
| 40 | export const McpAppReadResourceInput = Schema.Struct({ |
| 41 | ...McpAppTarget, |
| 42 | uri: TrimmedNonEmptyString, |
| 43 | }); |
| 44 | export type McpAppReadResourceInput = typeof McpAppReadResourceInput.Type; |
| 45 | |
| 46 | export const McpAppReadResourceResult = Schema.Struct({ |
| 47 | contents: Schema.Array(Schema.Unknown), |
| 48 | }); |
| 49 | export type McpAppReadResourceResult = typeof McpAppReadResourceResult.Type; |
| 50 | |
| 51 | /** Replaces prior context; no content clears it. */ |
| 52 | export 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 | }); |
| 58 | export type McpAppUpdateModelContextInput = typeof McpAppUpdateModelContextInput.Type; |
| 59 | |
| 60 | export 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 | ]); |
| 68 | export type McpAppRequestErrorReason = typeof McpAppRequestErrorReason.Type; |
| 69 | |
| 70 | export 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 | } |
| 94 | } |