| 1 | import { WS_METHODS } from "@t3tools/contracts"; |
| 2 | import type { Atom } from "effect/reactivity"; |
| 3 | |
| 4 | import type { EnvironmentRegistry } from "../connection/registry.ts"; |
| 5 | import { createEnvironmentRpcCommand } from "./runtime.ts"; |
| 6 | |
| 7 | /** |
| 8 | * RPC commands an MCP App host makes on an app's behalf. Each client |
| 9 | * instantiates them with its own connection runtime (`mcpAppEnvironment` in |
| 10 | * web and mobile). |
| 11 | */ |
| 12 | export function createMcpAppEnvironmentAtoms<R, E>( |
| 13 | runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>, |
| 14 | ) { |
| 15 | return { |
| 16 | callTool: createEnvironmentRpcCommand(runtime, { |
| 17 | label: "environment-command:mcp-apps:call-tool", |
| 18 | tag: WS_METHODS.mcpAppsCallTool, |
| 19 | }), |
| 20 | toolInfo: createEnvironmentRpcCommand(runtime, { |
| 21 | label: "environment-command:mcp-apps:tool-info", |
| 22 | tag: WS_METHODS.mcpAppsToolInfo, |
| 23 | }), |
| 24 | readResource: createEnvironmentRpcCommand(runtime, { |
| 25 | label: "environment-command:mcp-apps:read-resource", |
| 26 | tag: WS_METHODS.mcpAppsReadResource, |
| 27 | }), |
| 28 | updateModelContext: createEnvironmentRpcCommand(runtime, { |
| 29 | label: "environment-command:mcp-apps:update-model-context", |
| 30 | tag: WS_METHODS.mcpAppsUpdateModelContext, |
| 31 | }), |
| 32 | }; |
| 33 | } |