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

peerPairingCode.ts

43 lines1.7 KB

1import {
2 createMcpApprovalCodeCommand,
3 createPeerPairingCodeCommand,
4} from "@t3tools/client-runtime/state/peerPairingCode";
5import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
6import type {
7 AuthMcpClientAccess,
8 AuthPairingCredentialResult,
9 EnvironmentId,
10} from "@t3tools/contracts";
11import * as Result from "effect/Result";
12​
13import { connectionAtomRuntime } from "../connection/runtime";
14import { appAtomRegistry } from "../rpc/atomRegistry";
15​
16const mintPairingCode = createPeerPairingCodeCommand(connectionAtomRuntime);
17const mintMcpApprovalCode = createMcpApprovalCodeCommand(connectionAtomRuntime);
18​
19/**
20 * A fresh pairing code minted on `environmentId` with this client's session
21 * there, for linking with `access`. Fails with `PeerPairingCodeError` when the
22 * session may not create one.
23 */
24export async function mintPairingCodeOn(
25 environmentId: EnvironmentId,
26 access: AuthMcpClientAccess,
27): Promise<Result.Result<string, unknown>> {
28 const result = await mintPairingCode.run(appAtomRegistry, { environmentId, input: access });
29 return result._tag === "Success"
30 ? Result.succeed(result.value)
31 : Result.fail(squashAtomCommandFailure(result));
33​
34/** A fresh code on `environmentId` that approves one app's sign-in at `access`. */
35export async function mintMcpApprovalCodeOn(
36 environmentId: EnvironmentId,
37 access: AuthMcpClientAccess,
38): Promise<Result.Result<AuthPairingCredentialResult, unknown>> {
39 const result = await mintMcpApprovalCode.run(appAtomRegistry, { environmentId, input: access });
40 return result._tag === "Success"
41 ? Result.succeed(result.value)
42 : Result.fail(squashAtomCommandFailure(result));