@jangmanj/mcp-client 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,330 @@
1
+ /**
2
+ * mcp.json discovery, validation, and merging.
3
+ *
4
+ * Mirrors Pi's built-in rules (docs/mcp.md): user-level servers live in
5
+ * ~/.pi/agent/mcp.json, project servers in .pi/mcp.json (trusted projects
6
+ * only), a project entry replaces a user entry, and a project entry without
7
+ * command/url/type overlays only enabled/exposure/toolExposure.
8
+ */
9
+
10
+ import { execSync } from "node:child_process";
11
+ import { existsSync, readFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import type { McpServerEntry } from "./pi-api.ts";
14
+
15
+ export type Exposure = "direct" | "codemode" | "deferred" | "hidden";
16
+
17
+ export interface OAuthConfig {
18
+ readonly clientId?: string;
19
+ readonly clientSecret?: string;
20
+ readonly clientName?: string;
21
+ }
22
+
23
+ export interface ResolvedServerConfig {
24
+ readonly name: string;
25
+ readonly source: "user" | "project" | "extension";
26
+ readonly kind: "stdio" | "http";
27
+ readonly command?: string;
28
+ readonly args?: readonly string[];
29
+ readonly env?: Record<string, string>;
30
+ readonly cwd?: string;
31
+ readonly url?: string;
32
+ readonly headers?: Record<string, string>;
33
+ readonly enabled: boolean;
34
+ readonly exposure: Exposure;
35
+ readonly toolExposure?: Record<string, string>;
36
+ readonly description?: string;
37
+ readonly timeoutMs: number;
38
+ /** Static client credentials / naming for the OAuth flow, when configured. */
39
+ readonly oauth?: OAuthConfig;
40
+ /** Present when the entry sets `oauth`. */
41
+ readonly wantsOAuth: boolean;
42
+ }
43
+
44
+ export interface LoadedConfigs {
45
+ readonly servers: Map<string, ResolvedServerConfig>;
46
+ readonly warnings: string[];
47
+ }
48
+
49
+ export interface LoadOptions {
50
+ readonly homeDir: string;
51
+ readonly cwd: string;
52
+ readonly projectTrusted: boolean;
53
+ /** Environment for `${VAR}` interpolation; defaults to process.env. */
54
+ readonly env?: Record<string, string | undefined>;
55
+ /** Runner for `!command` values; injectable for tests. */
56
+ readonly exec?: (command: string) => string;
57
+ /** Registered (extension) servers; file entries win on name collision. */
58
+ readonly registered?: ReadonlyMap<string, McpServerEntry>;
59
+ }
60
+
61
+ const NAME_RE = /^[A-Za-z0-9_-]+$/;
62
+ const EXPOSURES = new Set(["direct", "codemode", "codemode-deferred", "deferred", "hidden"]);
63
+ const DEFAULT_TIMEOUT_MS = 60_000;
64
+
65
+ export function normalizeExposure(value: string | undefined): Exposure {
66
+ switch (value) {
67
+ case "direct":
68
+ case "deferred":
69
+ case "hidden":
70
+ return value;
71
+ default:
72
+ return "codemode"; // codemode-deferred and unknown values land here
73
+ }
74
+ }
75
+
76
+ /** Normalized identity: names differing only in `-` vs `_` are the same server. */
77
+ export function serverKey(name: string): string {
78
+ return name.replace(/-/g, "_");
79
+ }
80
+
81
+ function defaultExec(command: string): string {
82
+ return execSync(command, { encoding: "utf8", timeout: 10_000 }).trim();
83
+ }
84
+
85
+ /**
86
+ * Interpolate one config value: `!command` (whole value) runs a command,
87
+ * `${VAR}` reads from env. Returns undefined warnings-free value or the value
88
+ * with failures replaced by "".
89
+ */
90
+ export function interpolate(
91
+ value: string,
92
+ env: Record<string, string | undefined>,
93
+ exec: (command: string) => string,
94
+ warnings: string[],
95
+ where: string,
96
+ ): string {
97
+ if (value.startsWith("!")) {
98
+ try {
99
+ return exec(value.slice(1));
100
+ } catch (err) {
101
+ warnings.push(`${where}: command failed: ${err instanceof Error ? err.message : String(err)}`);
102
+ return "";
103
+ }
104
+ }
105
+ return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_m, name: string) => {
106
+ const v = env[name];
107
+ if (v === undefined) warnings.push(`${where}: environment variable ${name} is not set`);
108
+ return v ?? "";
109
+ });
110
+ }
111
+
112
+ export function expandTilde(path: string, homeDir: string): string {
113
+ if (path === "~") return homeDir;
114
+ if (path.startsWith("~/")) return join(homeDir, path.slice(2));
115
+ return path;
116
+ }
117
+
118
+ function interpolateRecord(
119
+ record: Record<string, string>,
120
+ env: Record<string, string | undefined>,
121
+ exec: (command: string) => string,
122
+ warnings: string[],
123
+ where: string,
124
+ ): Record<string, string> {
125
+ const out: Record<string, string> = {};
126
+ for (const [k, v] of Object.entries(record)) {
127
+ out[k] = interpolate(v, env, exec, warnings, `${where}.${k}`);
128
+ }
129
+ return out;
130
+ }
131
+
132
+ interface RawEntry {
133
+ readonly name: string;
134
+ readonly raw: McpServerEntry;
135
+ readonly source: "user" | "project" | "extension";
136
+ }
137
+
138
+ function readFileEntries(path: string, source: "user" | "project", warnings: string[]): RawEntry[] {
139
+ if (!existsSync(path)) return [];
140
+ let parsed: unknown;
141
+ try {
142
+ parsed = JSON.parse(readFileSync(path, "utf8"));
143
+ } catch (err) {
144
+ warnings.push(`${path}: ${err instanceof Error ? err.message : String(err)}`);
145
+ return [];
146
+ }
147
+ const servers = (parsed as { mcpServers?: unknown })?.mcpServers;
148
+ if (servers === undefined || servers === null) return [];
149
+ if (typeof servers !== "object" || Array.isArray(servers)) {
150
+ warnings.push(`${path}: "mcpServers" must be an object`);
151
+ return [];
152
+ }
153
+ return Object.entries(servers as Record<string, unknown>).map(([name, raw]) => ({
154
+ name,
155
+ raw: (raw ?? {}) as McpServerEntry,
156
+ source,
157
+ }));
158
+ }
159
+
160
+ function isPartialOverride(raw: McpServerEntry): boolean {
161
+ return raw.command === undefined && raw.url === undefined && raw.type === undefined;
162
+ }
163
+
164
+ function resolveOAuth(
165
+ raw: McpServerEntry,
166
+ env: Record<string, string | undefined>,
167
+ exec: (command: string) => string,
168
+ warnings: string[],
169
+ where: string,
170
+ ): OAuthConfig | undefined {
171
+ if (raw.oauth === undefined) return undefined;
172
+ const out: { clientId?: string; clientSecret?: string; clientName?: string } = {};
173
+ for (const key of ["clientId", "clientSecret", "clientName"] as const) {
174
+ const v = raw.oauth[key];
175
+ if (v === undefined) continue;
176
+ if (typeof v !== "string") {
177
+ warnings.push(`${where}: oauth.${key} must be a string`);
178
+ continue;
179
+ }
180
+ out[key] = key === "clientName" ? v : interpolate(v, env, exec, warnings, `${where}.oauth.${key}`);
181
+ }
182
+ return out;
183
+ }
184
+
185
+ function resolveEntry(
186
+ entry: RawEntry,
187
+ opts: LoadOptions,
188
+ warnings: string[],
189
+ ): ResolvedServerConfig | undefined {
190
+ const { name, raw, source } = entry;
191
+ const where = `${source} server "${name}"`;
192
+ if (!NAME_RE.test(name)) {
193
+ warnings.push(`${where}: invalid name (allowed: letters, digits, _, -)`);
194
+ return undefined;
195
+ }
196
+ if (raw.type !== undefined && raw.type !== "stdio" && raw.type !== "http" && raw.type !== "streamable-http") {
197
+ warnings.push(`${where}: unsupported type ${JSON.stringify(raw.type)} (sse is not supported)`);
198
+ return undefined;
199
+ }
200
+ if (raw.exposure !== undefined && !EXPOSURES.has(raw.exposure)) {
201
+ warnings.push(`${where}: unknown exposure ${JSON.stringify(raw.exposure)}, using "codemode"`);
202
+ }
203
+ for (const [pattern, value] of Object.entries(raw.toolExposure ?? {})) {
204
+ if (!EXPOSURES.has(value)) {
205
+ warnings.push(`${where}: unknown toolExposure ${JSON.stringify(value)} for ${pattern}`);
206
+ }
207
+ }
208
+
209
+ const env = opts.env ?? process.env;
210
+ const exec = opts.exec ?? defaultExec;
211
+
212
+ const oauth = resolveOAuth(raw, env, exec, warnings, where);
213
+
214
+ const base = {
215
+ name,
216
+ source,
217
+ enabled: raw.enabled !== false,
218
+ exposure: normalizeExposure(raw.exposure),
219
+ timeoutMs: raw.timeout !== undefined && raw.timeout > 0 ? raw.timeout * 1000 : DEFAULT_TIMEOUT_MS,
220
+ wantsOAuth: raw.oauth !== undefined,
221
+ ...(oauth !== undefined ? { oauth } : {}),
222
+ ...(raw.toolExposure !== undefined ? { toolExposure: raw.toolExposure } : {}),
223
+ ...(raw.description !== undefined ? { description: raw.description } : {}),
224
+ };
225
+
226
+ if (raw.command !== undefined) {
227
+ return {
228
+ ...base,
229
+ kind: "stdio",
230
+ command: expandTilde(raw.command, opts.homeDir),
231
+ args: (raw.args ?? []).map((a) => expandTilde(a, opts.homeDir)),
232
+ ...(raw.env !== undefined
233
+ ? { env: interpolateRecord(raw.env, env, exec, warnings, where) }
234
+ : {}),
235
+ ...(raw.cwd !== undefined ? { cwd: expandTilde(raw.cwd, opts.homeDir) } : {}),
236
+ };
237
+ }
238
+ if (raw.url !== undefined) {
239
+ return {
240
+ ...base,
241
+ kind: "http",
242
+ url: raw.url,
243
+ ...(raw.headers !== undefined
244
+ ? { headers: interpolateRecord(raw.headers, env, exec, warnings, where) }
245
+ : {}),
246
+ };
247
+ }
248
+ warnings.push(`${where}: needs "command" (stdio) or "url" (http)`);
249
+ return undefined;
250
+ }
251
+
252
+ /**
253
+ * Directory holding mcp.json: PI_CODING_AGENT_DIR when set, else
254
+ * ~/.pi/agent. Mirrors Pi's own resolution (docs/environment-variables.md).
255
+ */
256
+ export function agentDir(env: Record<string, string | undefined>, homeDir: string): string {
257
+ const override = env.PI_CODING_AGENT_DIR;
258
+ if (typeof override === "string" && override !== "") return override;
259
+ return join(homeDir, ".pi", "agent");
260
+ }
261
+
262
+ /**
263
+ * Load and merge user-level and project-level mcp.json, plus servers
264
+ * registered by other extensions. File entries take precedence over
265
+ * registered ones; project entries take precedence over user entries.
266
+ */
267
+ export function loadServerConfigs(opts: LoadOptions): LoadedConfigs {
268
+ const warnings: string[] = [];
269
+ const merged = new Map<string, ResolvedServerConfig>();
270
+ const seenKeys = new Map<string, string>(); // normalized key -> first name
271
+
272
+ const userEntries = readFileEntries(
273
+ join(agentDir(opts.env ?? (process.env as Record<string, string | undefined>), opts.homeDir), "mcp.json"),
274
+ "user",
275
+ warnings,
276
+ );
277
+ const projectEntries = opts.projectTrusted
278
+ ? readFileEntries(join(opts.cwd, ".pi", "mcp.json"), "project", warnings)
279
+ : [];
280
+
281
+ // Extension-registered servers first: file config overrides them by name.
282
+ if (opts.registered) {
283
+ for (const [name, raw] of opts.registered) {
284
+ const cfg = resolveEntry({ name, raw, source: "extension" }, opts, warnings);
285
+ if (cfg) {
286
+ merged.set(name, cfg);
287
+ seenKeys.set(serverKey(name), name);
288
+ }
289
+ }
290
+ }
291
+
292
+ const applyFile = (entries: RawEntry[], overlayOnly: boolean) => {
293
+ for (const entry of entries) {
294
+ const key = serverKey(entry.name);
295
+ const priorName = seenKeys.get(key);
296
+ if (priorName !== undefined && priorName !== entry.name) {
297
+ warnings.push(
298
+ `${entry.source} server "${entry.name}": conflicts with "${priorName}" (names differ only in -/_), skipping`,
299
+ );
300
+ continue;
301
+ }
302
+ if (overlayOnly && isPartialOverride(entry.raw)) {
303
+ const base = merged.get(entry.name);
304
+ if (!base) {
305
+ warnings.push(
306
+ `project server "${entry.name}": partial override without a matching user-level server`,
307
+ );
308
+ continue;
309
+ }
310
+ merged.set(entry.name, {
311
+ ...base,
312
+ enabled: entry.raw.enabled !== undefined ? entry.raw.enabled !== false : base.enabled,
313
+ exposure: entry.raw.exposure !== undefined ? normalizeExposure(entry.raw.exposure) : base.exposure,
314
+ ...(entry.raw.toolExposure !== undefined ? { toolExposure: entry.raw.toolExposure } : {}),
315
+ });
316
+ continue;
317
+ }
318
+ const cfg = resolveEntry(entry, opts, warnings);
319
+ if (cfg) {
320
+ merged.set(entry.name, cfg);
321
+ seenKeys.set(key, entry.name);
322
+ }
323
+ }
324
+ };
325
+
326
+ applyFile(userEntries, false);
327
+ applyFile(projectEntries, true);
328
+
329
+ return { servers: merged, warnings };
330
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Convert MCP content blocks to Pi tool-result content.
3
+ *
4
+ * Pi's built-in MCP support truncates long text and offloads binary to temp
5
+ * files. This bridge truncates text inline at the same order of magnitude and
6
+ * passes images through as Pi image blocks; everything else degrades to a
7
+ * text description so the model always sees something.
8
+ */
9
+
10
+ import type { ContentBlock } from "../dist/ops/index.js";
11
+ import type { PiContent } from "./pi-api.ts";
12
+
13
+ /** Per-text-block cap, matching Pi's generic tool-output limit of ~50 KB. */
14
+ export const MAX_TEXT_CHARS = 50_000;
15
+
16
+ export function truncateText(text: string): string {
17
+ if (text.length <= MAX_TEXT_CHARS) return text;
18
+ return `${text.slice(0, MAX_TEXT_CHARS)}\n…${text.length - MAX_TEXT_CHARS} chars truncated…`;
19
+ }
20
+
21
+ function asRecord(v: unknown): Record<string, unknown> | undefined {
22
+ return typeof v === "object" && v !== null ? (v as Record<string, unknown>) : undefined;
23
+ }
24
+
25
+ function textBlock(text: unknown): PiContent {
26
+ return { type: "text", text: truncateText(typeof text === "string" ? text : JSON.stringify(text)) };
27
+ }
28
+
29
+ export function convertBlocks(blocks: readonly ContentBlock[]): PiContent[] {
30
+ const out: PiContent[] = [];
31
+ for (const block of blocks) {
32
+ const raw = asRecord(block.raw) ?? {};
33
+ switch (block.type) {
34
+ case "text":
35
+ out.push(textBlock(raw.text));
36
+ break;
37
+ case "image": {
38
+ const data = raw.data;
39
+ const mimeType = raw.mimeType;
40
+ if (typeof data === "string" && typeof mimeType === "string") {
41
+ out.push({ type: "image", data, mimeType });
42
+ } else {
43
+ out.push(textBlock("[image block with invalid data omitted]"));
44
+ }
45
+ break;
46
+ }
47
+ case "audio":
48
+ out.push(textBlock(`[audio${typeof raw.mimeType === "string" ? ` ${raw.mimeType}` : ""} omitted]`));
49
+ break;
50
+ case "resource_link": {
51
+ const name = typeof raw.name === "string" ? raw.name : undefined;
52
+ const uri = typeof raw.uri === "string" ? raw.uri : "(no uri)";
53
+ out.push(textBlock(`Resource${name ? ` "${name}"` : ""}: ${uri}`));
54
+ break;
55
+ }
56
+ case "resource": {
57
+ const resource = asRecord(raw.resource) ?? raw;
58
+ const uri = typeof resource.uri === "string" ? resource.uri : undefined;
59
+ if (typeof resource.text === "string") {
60
+ out.push(textBlock(resource.text));
61
+ } else if (
62
+ typeof resource.blob === "string" &&
63
+ typeof resource.mimeType === "string" &&
64
+ resource.mimeType.startsWith("image/")
65
+ ) {
66
+ out.push({ type: "image", data: resource.blob, mimeType: resource.mimeType });
67
+ } else {
68
+ out.push(textBlock(`[binary resource${uri ? ` ${uri}` : ""} omitted]`));
69
+ }
70
+ break;
71
+ }
72
+ default:
73
+ out.push(textBlock(block.raw));
74
+ }
75
+ }
76
+ if (out.length === 0) out.push(textBlock("(no content)"));
77
+ return out;
78
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Pi extension entry: replaces Pi's built-in MCP session support with a
3
+ * bridge implemented on this library (@jangmanj/mcp-client).
4
+ *
5
+ * Registering the /mcp command is what makes Pi stand down its built-in MCP
6
+ * extension for sessions (docs/mcp.md#replace-the-built-in-mcp-support), so
7
+ * this extension reads mcp.json itself and owns all connections.
8
+ */
9
+
10
+ import { homedir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { McpBridge } from "./bridge.ts";
13
+ import { agentDir, loadServerConfigs, type ResolvedServerConfig } from "./config.ts";
14
+ import type { ExtensionAPI, McpServerEntry, SessionContext, Ui } from "./pi-api.ts";
15
+
16
+ /** Tolerantly unwrap pi.getMcpServers() / mcp_servers_change event shapes. */
17
+ export function registeredServersOf(x: unknown): Map<string, McpServerEntry> {
18
+ const out = new Map<string, McpServerEntry>();
19
+ const put = (name: unknown, value: unknown) => {
20
+ if (typeof name !== "string" || name === "") return;
21
+ const rec = (typeof value === "object" && value !== null ? value : {}) as Record<string, unknown>;
22
+ const config = (typeof rec.config === "object" && rec.config !== null ? rec.config : rec) as McpServerEntry;
23
+ out.set(name, config);
24
+ };
25
+ if (x instanceof Map) {
26
+ for (const [k, v] of x) put(k, v);
27
+ } else if (Array.isArray(x)) {
28
+ for (const item of x) {
29
+ if (Array.isArray(item)) put(item[0], item[1]);
30
+ else if (typeof item === "object" && item !== null) {
31
+ const rec = item as Record<string, unknown>;
32
+ put(rec.name, rec.config ?? rec);
33
+ }
34
+ }
35
+ } else if (typeof x === "object" && x !== null) {
36
+ for (const [k, v] of Object.entries(x)) put(k, v);
37
+ }
38
+ return out;
39
+ }
40
+
41
+ export default function (pi: ExtensionAPI) {
42
+ // Bridge notifications go to the most recent session context's UI.
43
+ let currentUi: Ui | undefined;
44
+ const bridge = new McpBridge({
45
+ pi,
46
+ notify: (message, level) => currentUi?.notify(message, level),
47
+ credentialStorePath: join(agentDir(process.env, homedir()), "mcp-client-oauth.json"),
48
+ confirm: (title, message) => currentUi?.confirm?.(title, message) ?? Promise.resolve(false),
49
+ });
50
+
51
+ // Registering /mcp replaces built-in MCP support for sessions.
52
+ pi.registerCommand("mcp", {
53
+ description: "MCP (mcp-client bridge): /mcp [list] | /mcp reconnect|login|logout <name>",
54
+ handler: async (args, ctx) => {
55
+ const [sub, ...rest] = args.trim().split(/\s+/).filter(Boolean);
56
+ if (sub === undefined || sub === "list") {
57
+ ctx.ui.notify(bridge.statusLines().join("\n"), "info");
58
+ return;
59
+ }
60
+ if ((sub === "reconnect" || sub === "login" || sub === "logout") && rest[0] !== undefined) {
61
+ try {
62
+ const state =
63
+ sub === "login"
64
+ ? await bridge.login(rest[0])
65
+ : sub === "logout"
66
+ ? await bridge.logout(rest[0])
67
+ : await bridge.reconnect(rest[0]);
68
+ ctx.ui.notify(
69
+ state.status === "connected"
70
+ ? `mcp "${state.name}": connected, ${state.toolCount} tools`
71
+ : `mcp "${state.name}": ${state.error ?? "failed"}`,
72
+ state.status === "connected" ? "info" : "error",
73
+ );
74
+ } catch (err) {
75
+ ctx.ui.notify(err instanceof Error ? err.message : String(err), "error");
76
+ }
77
+ return;
78
+ }
79
+ ctx.ui.notify("Usage: /mcp [list] | /mcp reconnect|login|logout <name>", "info");
80
+ },
81
+ });
82
+
83
+ let fileConfigs = new Map<string, ResolvedServerConfig>();
84
+
85
+ const loadAndSync = (ctx: SessionContext) => {
86
+ const { servers, warnings } = loadServerConfigs({
87
+ homeDir: homedir(),
88
+ cwd: ctx.cwd,
89
+ projectTrusted: safeTrusted(ctx),
90
+ registered: registeredServersOf(pi.getMcpServers()),
91
+ });
92
+ fileConfigs = servers;
93
+ for (const warning of warnings) ctx.ui.notify(`mcp: ${warning}`, "warning");
94
+ bridge.sync(servers);
95
+ };
96
+
97
+ pi.on("session_start", async (_event, ctx) => {
98
+ currentUi = ctx.ui;
99
+ loadAndSync(ctx);
100
+ });
101
+
102
+ pi.on("mcp_servers_change", async (event, ctx) => {
103
+ currentUi = ctx.ui; const merged = new Map(fileConfigs);
104
+ for (const [name, raw] of registeredServersOf(event.servers)) {
105
+ if (!merged.has(name)) {
106
+ const { servers } = loadServerConfigs({
107
+ homeDir: homedir(),
108
+ cwd: ctx.cwd,
109
+ projectTrusted: false,
110
+ registered: new Map([[name, raw]]),
111
+ });
112
+ const cfg = servers.get(name);
113
+ if (cfg) merged.set(name, cfg);
114
+ }
115
+ }
116
+ bridge.sync(merged);
117
+ });
118
+
119
+ pi.on("session_shutdown", async (_event, ctx) => {
120
+ currentUi = ctx.ui;
121
+ await bridge.closeAll();
122
+ fileConfigs = new Map();
123
+ });
124
+
125
+ pi.on("before_agent_start", async (event, _ctx) => {
126
+ // Direct-exposure tools must be declared in the first request: wait for
127
+ // those servers, bounded, like built-in MCP does.
128
+ await bridge.waitForPending((s) => s.config.exposure === "direct");
129
+
130
+ const sections = event.systemPromptOptions?.sections;
131
+ if (!sections) return;
132
+ const lines = bridge
133
+ .list()
134
+ .filter((s) => s.config.enabled && s.config.exposure !== "direct" && s.config.exposure !== "hidden")
135
+ .map((s) => {
136
+ const reach = s.config.exposure === "deferred" ? "tool_search" : "codemode";
137
+ const desc = s.description ?? "MCP server";
138
+ return `- mcp__${s.name.replace(/-/g, "_")}: ${desc} (tools reachable via ${reach})`;
139
+ });
140
+ if (lines.length > 0) sections.mcp_servers = lines.join("\n");
141
+ });
142
+
143
+ pi.on("tool_call", async (event, _ctx) => {
144
+ // Late registration: finish connecting servers before codemode /
145
+ // tool_search / direct mcp__* calls run.
146
+ if (
147
+ event.toolName === "codemode" ||
148
+ event.toolName === "tool_search" ||
149
+ event.toolName.startsWith("mcp__")
150
+ ) {
151
+ await bridge.waitForPending();
152
+ }
153
+ });
154
+ }
155
+
156
+ function safeTrusted(ctx: SessionContext): boolean {
157
+ try {
158
+ return ctx.isProjectTrusted();
159
+ } catch {
160
+ return false;
161
+ }
162
+ }