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

mcpSession.ts

34 lines1.3 KB

1import type { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
2​
3export interface McpProviderSessionConfig {
4 readonly environmentId: EnvironmentId;
5 readonly threadId: ThreadId;
6 readonly providerSessionId: string;
7 readonly providerInstanceId: ProviderInstanceId;
8 readonly endpoint: string;
9 readonly authorizationHeader: string;
10 /**
11 * Adapters read it to keep developer instructions truthful: when the user
12 * withholds agent browser access, the prompt must not advertise `preview_*`
13 * tools that every call would reject.
14 */
15 readonly browserToolsAvailable: boolean;
16 readonly capabilities?: ReadonlySet<string>;
17 readonly agentDeviceEnvironment?: Readonly<Record<string, string>>;
19​
20export function withAgentDeviceEnvironment(
21 base: NodeJS.ProcessEnv,
22 config: Pick<McpProviderSessionConfig, "agentDeviceEnvironment"> | undefined,
23): NodeJS.ProcessEnv {
24 const extra = config?.agentDeviceEnvironment;
25 if (!extra) return base;
26 const separator = extra.PATH_SEPARATOR ?? ":";
27 const basePath = base.PATH ?? base.Path;
28 const { PATH: shimDir, PATH_SEPARATOR: _separator, ...rest } = extra;
29 return {
30 ...base,
31 ...rest,
32 ...(shimDir ? { PATH: basePath ? `${shimDir}${separator}${basePath}` : shimDir } : {}),
33 };