pcific 0.0.0-stage → 0.2.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/SKILL.md +127 -0
  4. package/dist/api/catalog.js +637 -0
  5. package/dist/api/run.js +960 -0
  6. package/dist/api/search.js +171 -0
  7. package/dist/api/shortcuts.js +799 -0
  8. package/dist/bin.js +648 -0
  9. package/dist/commands/auth.js +513 -0
  10. package/dist/commands/doctor.js +410 -0
  11. package/dist/commands/init.js +306 -0
  12. package/dist/commands/sync.js +214 -0
  13. package/dist/detect.js +214 -0
  14. package/dist/env.js +339 -0
  15. package/dist/goLive.js +629 -0
  16. package/dist/keyLink.js +305 -0
  17. package/dist/mcp/server.js +206 -0
  18. package/dist/mcp/tools.js +689 -0
  19. package/dist/python/template.js +793 -0
  20. package/dist/schema/discover.js +324 -0
  21. package/dist/schema/helpers.js +396 -0
  22. package/dist/schema/prismaToJsonSchema.js +197 -0
  23. package/dist/schema/push.js +570 -0
  24. package/dist/schema/tsToJsonSchema.js +405 -0
  25. package/dist/schema/zodToJsonSchema.js +442 -0
  26. package/dist/templates/openapi.json +1 -0
  27. package/dist/templates/sdk/auth.ts +139 -0
  28. package/dist/templates/sdk/client.ts +1059 -0
  29. package/dist/templates/sdk/errors.ts +76 -0
  30. package/dist/templates/sdk/generated-types.ts +5746 -0
  31. package/dist/templates/sdk/http.ts +359 -0
  32. package/dist/templates/sdk/index.ts +84 -0
  33. package/dist/templates/sdk/json.ts +24 -0
  34. package/dist/templates/sdk/kit.ts +516 -0
  35. package/dist/templates/sdk/multipart.ts +99 -0
  36. package/dist/templates/sdk/sse.ts +131 -0
  37. package/dist/templates/sdk/verify.ts +766 -0
  38. package/dist/templates/sdk-js/auth.d.ts +20 -0
  39. package/dist/templates/sdk-js/auth.js +85 -0
  40. package/dist/templates/sdk-js/client.d.ts +324 -0
  41. package/dist/templates/sdk-js/client.js +607 -0
  42. package/dist/templates/sdk-js/errors.d.ts +51 -0
  43. package/dist/templates/sdk-js/errors.js +48 -0
  44. package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
  45. package/dist/templates/sdk-js/generated-types.js +5 -0
  46. package/dist/templates/sdk-js/http.d.ts +50 -0
  47. package/dist/templates/sdk-js/http.js +263 -0
  48. package/dist/templates/sdk-js/index.d.ts +9 -0
  49. package/dist/templates/sdk-js/index.js +7 -0
  50. package/dist/templates/sdk-js/json.d.ts +11 -0
  51. package/dist/templates/sdk-js/json.js +16 -0
  52. package/dist/templates/sdk-js/kit.d.ts +220 -0
  53. package/dist/templates/sdk-js/kit.js +208 -0
  54. package/dist/templates/sdk-js/multipart.d.ts +23 -0
  55. package/dist/templates/sdk-js/multipart.js +61 -0
  56. package/dist/templates/sdk-js/sse.d.ts +12 -0
  57. package/dist/templates/sdk-js/sse.js +99 -0
  58. package/dist/templates/sdk-js/verify.d.ts +114 -0
  59. package/dist/templates/sdk-js/verify.js +506 -0
  60. package/dist/templates.js +925 -0
  61. package/dist/ui.js +399 -0
  62. package/dist/webhooks/events.js +171 -0
  63. package/dist/webhooks/listen.js +772 -0
  64. package/package.json +32 -4
@@ -0,0 +1,305 @@
1
+ import { execFile } from "node:child_process";
2
+ import { assertTestKeyOnly, CliError, normalizeBaseUrl, writeEnvKeysAtomically } from "./env.js";
3
+ export const DEFAULT_KEY_LINK_SCOPES = [
4
+ "orbit",
5
+ "safeguard",
6
+ "ask-pcific",
7
+ "pixel-trace",
8
+ "message-check",
9
+ "dispute-pack",
10
+ "settings",
11
+ "listing-fields",
12
+ "documents",
13
+ "webhooks",
14
+ "read",
15
+ "logs",
16
+ ];
17
+ function isJsonObject(value) {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19
+ }
20
+ function isString(value) {
21
+ return typeof value === "string";
22
+ }
23
+ function isKeyLinkStatus(value) {
24
+ return (value === "pending" ||
25
+ value === "ready" ||
26
+ value === "connected" ||
27
+ value === "revoked" ||
28
+ value === "cancelled" ||
29
+ value === "expired");
30
+ }
31
+ async function parseErrorResponse(response, fallbackMessage, retryCommand = "pcific init") {
32
+ const rawText = await response.text().catch(() => "");
33
+ if (rawText.trim().startsWith("{")) {
34
+ try {
35
+ // SAFETY: JSON.parse returns JSON values matching CliJsonValue.
36
+ const parsed = JSON.parse(rawText);
37
+ if (isJsonObject(parsed)) {
38
+ const errorText = isString(parsed.error) ? parsed.error : fallbackMessage;
39
+ const tryThis = isString(parsed.tryThis)
40
+ ? parsed.tryThis
41
+ : `Check your network connection and PCIFIC_BASE_URL, then run ${retryCommand} again.`;
42
+ const code = isString(parsed.code) ? parsed.code : `HTTP_${response.status}`;
43
+ return new CliError(errorText, { code, tryThis });
44
+ }
45
+ }
46
+ catch {
47
+ // Fall through to generic HTTP error.
48
+ }
49
+ }
50
+ return new CliError(`${fallbackMessage} (HTTP ${response.status}).`, {
51
+ code: `HTTP_${response.status}`,
52
+ tryThis: `Check your connection to PCIFIC and retry ${retryCommand}.`,
53
+ });
54
+ }
55
+ async function parseJsonObject(response, context, retryCommand = "pcific init") {
56
+ const text = await response.text();
57
+ try {
58
+ // SAFETY: JSON.parse returns JSON values matching CliJsonValue.
59
+ const parsed = JSON.parse(text);
60
+ if (isJsonObject(parsed)) {
61
+ return parsed;
62
+ }
63
+ }
64
+ catch {
65
+ // Handled below.
66
+ }
67
+ throw new CliError(`PCIFIC returned an unexpected response while ${context}.`, {
68
+ code: "INVALID_KEY_LINK_RESPONSE",
69
+ tryThis: `Check PCIFIC_BASE_URL points to your PCIFIC server, then run ${retryCommand} again.`,
70
+ });
71
+ }
72
+ /**
73
+ * Starts a new key-linking session via `POST /api/key-link`.
74
+ */
75
+ export async function startKeyLink(options) {
76
+ const fetchImpl = options.fetch ?? globalThis.fetch;
77
+ const baseUrl = normalizeBaseUrl(options.baseUrl);
78
+ const retryCommand = options.retryCommand ?? "pcific init";
79
+ const body = {
80
+ suggestedName: options.suggestedName,
81
+ destination: options.destination ?? ".env",
82
+ scopes: [...(options.scopes ?? DEFAULT_KEY_LINK_SCOPES)],
83
+ };
84
+ if (options.shop) {
85
+ body.shop = options.shop;
86
+ }
87
+ const response = await fetchImpl(`${baseUrl}/api/key-link`, {
88
+ method: "POST",
89
+ headers: { "content-type": "application/json" },
90
+ body: JSON.stringify(body),
91
+ });
92
+ if (!response.ok) {
93
+ throw await parseErrorResponse(response, "Could not start PCIFIC key linking", retryCommand);
94
+ }
95
+ const data = await parseJsonObject(response, "starting key linking", retryCommand);
96
+ const id = isString(data.id) ? data.id : "";
97
+ const confirmationCode = isString(data.confirmationCode) ? data.confirmationCode : "";
98
+ const pollToken = isString(data.pollToken) ? data.pollToken : "";
99
+ const approvalUrl = isString(data.approvalUrl) ? data.approvalUrl : "";
100
+ if (!id || !confirmationCode || !pollToken || !approvalUrl) {
101
+ throw new CliError("PCIFIC key-link start response was missing required fields.", {
102
+ code: "INCOMPLETE_KEY_LINK_RESPONSE",
103
+ tryThis: `Retry ${retryCommand} or create a test key manually in your PCIFIC dashboard.`,
104
+ });
105
+ }
106
+ return {
107
+ id,
108
+ confirmationCode,
109
+ pollToken,
110
+ approvalUrl,
111
+ shopNote: isString(data.shopNote) ? data.shopNote : undefined,
112
+ expiresAt: isString(data.expiresAt) ? data.expiresAt : undefined,
113
+ };
114
+ }
115
+ /**
116
+ * Long-polls `POST /api/key-link` with `action: "wait"` until approval finishes
117
+ * or `maxRounds` completes (default 12 rounds x 25s = 5 minutes).
118
+ */
119
+ export async function waitForKeyLink(options) {
120
+ const fetchImpl = options.fetch ?? globalThis.fetch;
121
+ const baseUrl = normalizeBaseUrl(options.baseUrl);
122
+ const maxRounds = options.maxRounds ?? 12;
123
+ const waitSeconds = options.waitSeconds ?? 25;
124
+ const retryCommand = options.retryCommand ?? "pcific init";
125
+ let lastExpiresAt;
126
+ for (let round = 1; round <= maxRounds; round += 1) {
127
+ if (options.signal?.aborted) {
128
+ throw new CliError("Key linking was cancelled.", {
129
+ code: "KEY_LINK_ABORTED",
130
+ tryThis: `Run ${retryCommand} when you are ready to link a test key.`,
131
+ });
132
+ }
133
+ const response = await fetchImpl(`${baseUrl}/api/key-link`, {
134
+ method: "POST",
135
+ headers: {
136
+ "content-type": "application/json",
137
+ "x-pcific-link-token": options.pollToken,
138
+ },
139
+ body: JSON.stringify({
140
+ id: options.id,
141
+ action: "wait",
142
+ waitSeconds,
143
+ }),
144
+ signal: options.signal,
145
+ });
146
+ if (!response.ok) {
147
+ throw await parseErrorResponse(response, "Could not check PCIFIC key-link status", retryCommand);
148
+ }
149
+ const data = await parseJsonObject(response, "waiting for key approval", retryCommand);
150
+ const rawStatus = isString(data.status) ? data.status : "";
151
+ if (!isKeyLinkStatus(rawStatus)) {
152
+ throw new CliError(`Unexpected key-link status "${rawStatus}".`, {
153
+ code: "INVALID_KEY_LINK_STATUS",
154
+ tryThis: `Start a fresh connection with ${retryCommand}.`,
155
+ });
156
+ }
157
+ lastExpiresAt = isString(data.expiresAt) ? data.expiresAt : lastExpiresAt;
158
+ options.onTick?.({ round, maxRounds, status: rawStatus });
159
+ if (rawStatus !== "pending") {
160
+ return {
161
+ status: rawStatus,
162
+ expiresAt: lastExpiresAt,
163
+ timedOut: false,
164
+ };
165
+ }
166
+ }
167
+ return {
168
+ status: "pending",
169
+ expiresAt: lastExpiresAt,
170
+ timedOut: true,
171
+ };
172
+ }
173
+ /**
174
+ * Parses the plain-text response returned by `action: "collect"`.
175
+ * Accepts only `PCIFIC_TEST_KEY` and `PCIFIC_MARKETPLACE_ID` lines.
176
+ */
177
+ export function parseCollectedEnvLines(rawText, retryCommand = "pcific init") {
178
+ let testKey = "";
179
+ let marketplaceId;
180
+ for (const rawLine of rawText.split(/\r?\n/)) {
181
+ const line = rawLine.trim();
182
+ if (!line || line.startsWith("#"))
183
+ continue;
184
+ if (line.startsWith("PCIFIC_TEST_KEY=")) {
185
+ testKey = line.slice("PCIFIC_TEST_KEY=".length).trim();
186
+ continue;
187
+ }
188
+ if (line.startsWith("PCIFIC_MARKETPLACE_ID=")) {
189
+ const value = line.slice("PCIFIC_MARKETPLACE_ID=".length).trim();
190
+ if (value) {
191
+ marketplaceId = value;
192
+ }
193
+ }
194
+ }
195
+ if (!testKey) {
196
+ throw new CliError("Key collection response did not include PCIFIC_TEST_KEY.", {
197
+ code: "MISSING_COLLECTED_KEY",
198
+ tryThis: `Run ${retryCommand} to start a new key connection.`,
199
+ });
200
+ }
201
+ assertTestKeyOnly(testKey);
202
+ return { testKey, marketplaceId };
203
+ }
204
+ /**
205
+ * Collects the one-time test key package and writes it atomically straight to `.env`.
206
+ * Never returns or logs the secret key.
207
+ */
208
+ export async function collectKeyLink(options) {
209
+ const fetchImpl = options.fetch ?? globalThis.fetch;
210
+ const baseUrl = normalizeBaseUrl(options.baseUrl);
211
+ const retryCommand = options.retryCommand ?? "pcific init";
212
+ const response = await fetchImpl(`${baseUrl}/api/key-link`, {
213
+ method: "POST",
214
+ headers: {
215
+ "content-type": "application/json",
216
+ "x-pcific-link-token": options.pollToken,
217
+ },
218
+ body: JSON.stringify({
219
+ id: options.id,
220
+ action: "collect",
221
+ }),
222
+ });
223
+ if (!response.ok) {
224
+ throw await parseErrorResponse(response, "Could not collect PCIFIC test key", retryCommand);
225
+ }
226
+ const rawText = await response.text();
227
+ const parsed = parseCollectedEnvLines(rawText, retryCommand);
228
+ const keysWritten = ["PCIFIC_TEST_KEY", "PCIFIC_MODE"];
229
+ if (parsed.marketplaceId) {
230
+ keysWritten.push("PCIFIC_MARKETPLACE_ID");
231
+ }
232
+ const envPath = writeEnvKeysAtomically(options.cwd, {
233
+ PCIFIC_TEST_KEY: parsed.testKey,
234
+ PCIFIC_MODE: "test",
235
+ PCIFIC_MARKETPLACE_ID: parsed.marketplaceId ?? null,
236
+ });
237
+ return {
238
+ envPath,
239
+ keysWritten,
240
+ marketplaceId: parsed.marketplaceId,
241
+ };
242
+ }
243
+ const SHELL_METACHARS_PATTERN = /["'&|<>^%!]/;
244
+ function hasUnsafeBrowserUrlChars(value) {
245
+ if (SHELL_METACHARS_PATTERN.test(value)) {
246
+ return true;
247
+ }
248
+ for (let i = 0; i < value.length; i += 1) {
249
+ const code = value.charCodeAt(i);
250
+ if (code <= 0x1f || code === 0x7f) {
251
+ return true;
252
+ }
253
+ }
254
+ return false;
255
+ }
256
+ export function buildOpenBrowserCommand(url, platform = process.platform) {
257
+ if (hasUnsafeBrowserUrlChars(url)) {
258
+ return null;
259
+ }
260
+ let parsed;
261
+ try {
262
+ parsed = new URL(url);
263
+ }
264
+ catch {
265
+ return null;
266
+ }
267
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
268
+ return null;
269
+ }
270
+ const safeUrl = parsed.toString();
271
+ if (hasUnsafeBrowserUrlChars(safeUrl)) {
272
+ return null;
273
+ }
274
+ if (platform === "win32") {
275
+ return {
276
+ command: "powershell.exe",
277
+ args: ["-NoProfile", "-NonInteractive", "-Command", "Start-Process", "--", safeUrl],
278
+ };
279
+ }
280
+ if (platform === "darwin") {
281
+ return { command: "open", args: [safeUrl] };
282
+ }
283
+ return { command: "xdg-open", args: [safeUrl] };
284
+ }
285
+ /**
286
+ * Safely opens an http(s) URL in the user's default browser without shell interpolation.
287
+ * Fails silently and returns false in headless environments or for unsafe URLs.
288
+ */
289
+ export function openBrowser(url, platform = process.platform) {
290
+ const spec = buildOpenBrowserCommand(url, platform);
291
+ if (!spec) {
292
+ return Promise.resolve(false);
293
+ }
294
+ return new Promise((resolve) => {
295
+ try {
296
+ const child = execFile(spec.command, spec.args, { timeout: 5_000 }, (error) => {
297
+ resolve(!error);
298
+ });
299
+ child.unref();
300
+ }
301
+ catch {
302
+ resolve(false);
303
+ }
304
+ });
305
+ }
@@ -0,0 +1,206 @@
1
+ import { createInterface } from "node:readline";
2
+ import { BaseUrlError, DEFAULT_BASE_URL, normalizeBaseUrl, readMergedEnv, } from "../api/run.js";
3
+ import { executeMcpTool, isMcpJsonObject, isMcpNumber, isMcpString, MCP_TOOLS, parseMcpJsonValue, redactSecret, resolveMcpTestKey, } from "./tools.js";
4
+ const SUPPORTED_PROTOCOL_VERSIONS = new Set(["2024-11-05", "2025-03-26"]);
5
+ const DEFAULT_PROTOCOL_VERSION = "2025-03-26";
6
+ const SERVER_INFO = {
7
+ name: "pcific-mcp",
8
+ version: "0.1.0",
9
+ };
10
+ function toJsonRpcId(value) {
11
+ if (isMcpString(value) || isMcpNumber(value))
12
+ return value;
13
+ return null;
14
+ }
15
+ export function createMcpHandler(options = {}) {
16
+ const cwd = options.cwd ?? process.cwd();
17
+ const mergedEnv = readMergedEnv(cwd, options.env);
18
+ const resolvedBaseUrl = options.baseUrl ?? mergedEnv.get("PCIFIC_BASE_URL")?.trim() ?? DEFAULT_BASE_URL;
19
+ const ctx = {
20
+ cwd,
21
+ baseUrl: resolvedBaseUrl,
22
+ fetch: options.fetch ?? globalThis.fetch,
23
+ env: options.env,
24
+ sleep: options.sleep,
25
+ now: options.now,
26
+ };
27
+ return async function handleMessage(rawMessage) {
28
+ if (!isMcpJsonObject(rawMessage) ||
29
+ rawMessage.jsonrpc !== "2.0" ||
30
+ !isMcpString(rawMessage.method)) {
31
+ return {
32
+ jsonrpc: "2.0",
33
+ id: null,
34
+ error: {
35
+ code: -32600,
36
+ message: "Invalid JSON-RPC 2.0 request.",
37
+ },
38
+ };
39
+ }
40
+ const hasId = "id" in rawMessage && rawMessage.id !== undefined;
41
+ const id = hasId ? toJsonRpcId(rawMessage.id) : null;
42
+ const method = rawMessage.method;
43
+ const params = isMcpJsonObject(rawMessage.params) ? rawMessage.params : {};
44
+ if (method === "notifications/initialized" || method === "notifications/cancelled") {
45
+ return null;
46
+ }
47
+ if (!hasId) {
48
+ return null;
49
+ }
50
+ if (method === "initialize") {
51
+ const requestedVersion = isMcpString(params.protocolVersion)
52
+ ? params.protocolVersion
53
+ : DEFAULT_PROTOCOL_VERSION;
54
+ const negotiatedVersion = SUPPORTED_PROTOCOL_VERSIONS.has(requestedVersion)
55
+ ? requestedVersion
56
+ : DEFAULT_PROTOCOL_VERSION;
57
+ return {
58
+ jsonrpc: "2.0",
59
+ id,
60
+ result: {
61
+ protocolVersion: negotiatedVersion,
62
+ capabilities: {
63
+ tools: {},
64
+ },
65
+ serverInfo: SERVER_INFO,
66
+ },
67
+ };
68
+ }
69
+ if (method === "ping") {
70
+ return {
71
+ jsonrpc: "2.0",
72
+ id,
73
+ result: {},
74
+ };
75
+ }
76
+ if (method === "tools/list") {
77
+ return {
78
+ jsonrpc: "2.0",
79
+ id,
80
+ result: {
81
+ tools: MCP_TOOLS,
82
+ },
83
+ };
84
+ }
85
+ if (method === "tools/call") {
86
+ const toolName = isMcpString(params.name) ? params.name : "";
87
+ if (!toolName) {
88
+ return {
89
+ jsonrpc: "2.0",
90
+ id,
91
+ error: {
92
+ code: -32602,
93
+ message: "Missing tool name in tools/call params.",
94
+ },
95
+ };
96
+ }
97
+ const result = await executeMcpTool(toolName, params.arguments, ctx);
98
+ return {
99
+ jsonrpc: "2.0",
100
+ id,
101
+ result,
102
+ };
103
+ }
104
+ return {
105
+ jsonrpc: "2.0",
106
+ id,
107
+ error: {
108
+ code: -32601,
109
+ message: `Method not found: ${method}`,
110
+ },
111
+ };
112
+ };
113
+ }
114
+ export async function runMcpCommand(args, options = {}) {
115
+ const cwd = options.cwd ?? process.cwd();
116
+ const stdin = options.stdin ?? process.stdin;
117
+ const stdout = options.stdout ?? process.stdout;
118
+ const stderr = options.stderr ?? process.stderr;
119
+ let baseUrlFlag;
120
+ for (let index = 0; index < args.length; index += 1) {
121
+ const arg = args[index];
122
+ if (arg === "--help" || arg === "-h") {
123
+ stdout.write("Usage: pcific mcp [--base-url <url>]\n");
124
+ stdout.write("Starts the local PCIFIC stdio MCP server (test keys only).\n");
125
+ return 0;
126
+ }
127
+ if (arg === "--base-url" || arg.startsWith("--base-url=")) {
128
+ const value = arg.startsWith("--base-url=") ? arg.slice("--base-url=".length) : args[index + 1];
129
+ if (!value || (!arg.startsWith("--base-url=") && value.startsWith("-"))) {
130
+ stderr.write(`${redactSecret("Error [MISSING_FLAG_VALUE]: Missing value for --base-url.\nNext: Pass a URL, for example --base-url https://business.pcific.ai")}\n`);
131
+ return 1;
132
+ }
133
+ if (!arg.startsWith("--base-url=")) {
134
+ index += 1;
135
+ }
136
+ baseUrlFlag = value;
137
+ continue;
138
+ }
139
+ if (arg.startsWith("-")) {
140
+ stderr.write(`${redactSecret(`Error [UNKNOWN_FLAG]: Unknown flag "${arg}" for pcific mcp.\nNext: Run pcific mcp --help to see supported options.`)}\n`);
141
+ return 1;
142
+ }
143
+ }
144
+ // Upfront live-key guard: refuse immediately if PCIFIC_TEST_KEY contains a live key
145
+ const keyCheck = resolveMcpTestKey(cwd, options.env);
146
+ if (keyCheck.error && keyCheck.error.includes("pcific_live_")) {
147
+ stderr.write(`${redactSecret(keyCheck.error)}\n`);
148
+ return 1;
149
+ }
150
+ let baseUrl;
151
+ try {
152
+ baseUrl = normalizeBaseUrl(baseUrlFlag ?? options.baseUrl ?? keyCheck.baseUrl ?? DEFAULT_BASE_URL);
153
+ }
154
+ catch (error) {
155
+ if (error instanceof BaseUrlError) {
156
+ stderr.write(`${redactSecret(`Error [${error.code}]: ${error.message}\nNext: ${error.tryThis}`)}\n`);
157
+ return 1;
158
+ }
159
+ throw error;
160
+ }
161
+ const secretToRedact = keyCheck.apiKey;
162
+ const handleMessage = createMcpHandler({
163
+ cwd,
164
+ baseUrl,
165
+ fetch: options.fetch,
166
+ env: options.env,
167
+ sleep: options.sleep,
168
+ now: options.now,
169
+ });
170
+ const rl = createInterface({
171
+ input: stdin,
172
+ crlfDelay: Infinity,
173
+ });
174
+ for await (const line of rl) {
175
+ const trimmed = line.trim();
176
+ if (trimmed.length === 0)
177
+ continue;
178
+ let parsed;
179
+ try {
180
+ parsed = parseMcpJsonValue(trimmed);
181
+ }
182
+ catch {
183
+ const parseError = {
184
+ jsonrpc: "2.0",
185
+ id: null,
186
+ error: {
187
+ code: -32700,
188
+ message: "Parse error: invalid JSON.",
189
+ },
190
+ };
191
+ stdout.write(`${JSON.stringify(parseError)}\n`);
192
+ continue;
193
+ }
194
+ try {
195
+ const response = await handleMessage(parsed);
196
+ if (response !== null) {
197
+ stdout.write(`${redactSecret(JSON.stringify(response), secretToRedact)}\n`);
198
+ }
199
+ }
200
+ catch (error) {
201
+ const message = redactSecret(error instanceof Error ? error.message : String(error), secretToRedact);
202
+ stderr.write(`pcific-mcp internal error: ${message}\n`);
203
+ }
204
+ }
205
+ return 0;
206
+ }