@foundocs/foundocs-setup 0.3.9 → 0.3.10
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.
- package/dist/bridge.mjs +54 -6
- package/package.json +2 -2
- package/skills/foundocs/references/configuration.md +6 -0
- package/src/bridge.mjs +42 -5
package/dist/bridge.mjs
CHANGED
|
@@ -36133,6 +36133,53 @@ if (process.argv[1] && process.argv[2] === "--headers" && import.meta.url === pa
|
|
|
36133
36133
|
// src/bridge.mjs
|
|
36134
36134
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
36135
36135
|
import { resolve as resolve2 } from "node:path";
|
|
36136
|
+
function requestError(error2, name) {
|
|
36137
|
+
const tool = typeof name === "string" && /^[a-z][a-z0-9_]{0,63}$/i.test(name) ? name : void 0;
|
|
36138
|
+
let code = "REQUEST_FAILED", retryable = false, message = "The MCP request failed. Run foundocs-setup doctor for connection diagnostics.";
|
|
36139
|
+
let httpStatus, remoteCode;
|
|
36140
|
+
const schemaError = error2 instanceof ProtocolError3 && (error2.code === ProtocolErrorCode2.InvalidParams && (error2.message.startsWith("Structured content does not match the tool's output schema:") || error2.message.startsWith("Failed to validate structured content:") || /^Tool '[^']+' has an invalid outputSchema:/.test(error2.message)) || error2.code === ProtocolErrorCode2.InvalidRequest && /^Tool .+ has an output schema but did not return structured content$/.test(error2.message));
|
|
36141
|
+
if (schemaError) {
|
|
36142
|
+
code = "OUTPUT_VALIDATION_ERROR";
|
|
36143
|
+
message = "The server response does not match the advertised tool output schema. Update the server tool contract; changing credentials will not fix this error.";
|
|
36144
|
+
} else if (error2 instanceof SdkHttpError || error2 instanceof UnauthorizedError) {
|
|
36145
|
+
httpStatus = error2 instanceof UnauthorizedError ? 401 : error2.status;
|
|
36146
|
+
if (httpStatus === 401) {
|
|
36147
|
+
code = "UNAUTHENTICATED";
|
|
36148
|
+
message = "Authentication failed (HTTP 401). Run foundocs-setup doctor and check the configured workspace key.";
|
|
36149
|
+
} else if (httpStatus === 403) {
|
|
36150
|
+
code = "FORBIDDEN";
|
|
36151
|
+
message = "Access was denied (HTTP 403). Check the workspace key permissions for this project.";
|
|
36152
|
+
} else if (httpStatus === 429) {
|
|
36153
|
+
code = "RATE_LIMITED";
|
|
36154
|
+
retryable = true;
|
|
36155
|
+
message = "The server rate limit was reached (HTTP 429). Wait before retrying.";
|
|
36156
|
+
} else {
|
|
36157
|
+
code = "REMOTE_HTTP_ERROR";
|
|
36158
|
+
retryable = httpStatus >= 500;
|
|
36159
|
+
message = `The remote MCP server returned HTTP ${httpStatus}. Check the server status.`;
|
|
36160
|
+
}
|
|
36161
|
+
} else if (error2 instanceof SdkError && error2.code === SdkErrorCode.RequestTimeout) {
|
|
36162
|
+
code = "REQUEST_TIMEOUT";
|
|
36163
|
+
retryable = true;
|
|
36164
|
+
message = "The remote MCP request timed out.";
|
|
36165
|
+
} else if (error2 instanceof SdkError && [SdkErrorCode.InvalidResult, SdkErrorCode.UnsupportedResultType].includes(error2.code)) {
|
|
36166
|
+
code = "INVALID_REMOTE_RESPONSE";
|
|
36167
|
+
message = "The remote MCP response is malformed. Check the server protocol and response schema.";
|
|
36168
|
+
} else if (error2 instanceof SdkError && [SdkErrorCode.NotConnected, SdkErrorCode.ConnectionClosed, SdkErrorCode.SendFailed].includes(error2.code) || error2 instanceof TypeError && error2.message === "fetch failed" || ["AbortError", "TimeoutError"].includes(error2?.name)) {
|
|
36169
|
+
code = "CONNECTION_ERROR";
|
|
36170
|
+
retryable = true;
|
|
36171
|
+
message = "The remote MCP connection failed or was interrupted. Check connectivity and the server status.";
|
|
36172
|
+
} else if (error2 instanceof ProtocolError3) {
|
|
36173
|
+
code = "REMOTE_PROTOCOL_ERROR";
|
|
36174
|
+
remoteCode = error2.code;
|
|
36175
|
+
message = "The remote MCP server returned a protocol error. Check the requested tool and arguments.";
|
|
36176
|
+
}
|
|
36177
|
+
return new ProtocolError3(
|
|
36178
|
+
ProtocolErrorCode2.InternalError,
|
|
36179
|
+
`Foundocs ${tool ?? "request"} [${code}]: ${message} Writes may already have succeeded; retry only with the same requestId and input.`,
|
|
36180
|
+
{ code, retryable, ...tool ? { tool } : {}, ...httpStatus !== void 0 ? { httpStatus } : {}, ...remoteCode !== void 0 ? { remoteCode } : {} }
|
|
36181
|
+
);
|
|
36182
|
+
}
|
|
36136
36183
|
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint }) {
|
|
36137
36184
|
let remote, local;
|
|
36138
36185
|
async function close() {
|
|
@@ -36158,16 +36205,16 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36158
36205
|
local.setRequestHandler("tools/list", async (request) => {
|
|
36159
36206
|
try {
|
|
36160
36207
|
return await remote.listTools(request.params);
|
|
36161
|
-
} catch {
|
|
36162
|
-
throw
|
|
36208
|
+
} catch (error2) {
|
|
36209
|
+
throw requestError(error2, "tools_list");
|
|
36163
36210
|
}
|
|
36164
36211
|
});
|
|
36165
36212
|
local.setRequestHandler("tools/call", async (request) => {
|
|
36166
36213
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(request.params.arguments?.project_id)) throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Read and pass the explicit project_id from the governing foundocs.json.");
|
|
36167
36214
|
try {
|
|
36168
36215
|
return await remote.callTool(request.params);
|
|
36169
|
-
} catch {
|
|
36170
|
-
throw
|
|
36216
|
+
} catch (error2) {
|
|
36217
|
+
throw requestError(error2, request.params.name);
|
|
36171
36218
|
}
|
|
36172
36219
|
});
|
|
36173
36220
|
local.onerror = () => process.stderr.write("Foundocs local MCP transport error.\n");
|
|
@@ -36179,8 +36226,9 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36179
36226
|
void close().finally(() => process.exit(0));
|
|
36180
36227
|
});
|
|
36181
36228
|
await local.connect(new StdioServerTransport());
|
|
36182
|
-
} catch {
|
|
36183
|
-
process.stderr.write(
|
|
36229
|
+
} catch (error2) {
|
|
36230
|
+
process.stderr.write(`Foundocs MCP bridge unavailable. ${requestError(error2, "initialize").message}
|
|
36231
|
+
`);
|
|
36184
36232
|
await close();
|
|
36185
36233
|
process.exitCode = 1;
|
|
36186
36234
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundocs/foundocs-setup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "Repeatable project setup and agent skills for the Foundocs remote MCP server",
|
|
5
5
|
"foundocsRelease": {
|
|
6
|
-
"summary": "
|
|
6
|
+
"summary": "Distinguish MCP output schema failures, authentication, access, rate limits and connection errors without exposing credentials or response data."
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"bin": {
|
|
@@ -7,3 +7,9 @@ Read that exact file and validate a JSON object with a UUID project_id. Pass tha
|
|
|
7
7
|
If that exact file is missing, malformed, or lacks a valid project_id, stop all Foundocs calls and ask for corrected configuration. A failed read does not change which AGENTS.md governs the task: never reinterpret the root, search for another configuration file, or try a relative-path or shell fallback. If the project is inaccessible, stop and ask; never guess another project. A client without local file access must ask the user for an explicit project_id.
|
|
8
8
|
|
|
9
9
|
Use the existing MCP connection and private authentication helper. FOUNDOCS_API_KEY is a supported scoped process-environment alternative. Never read, print, commit or copy credentials into reports, memories, prompts, AGENTS.md or the project configuration.
|
|
10
|
+
|
|
11
|
+
## Tool response errors
|
|
12
|
+
|
|
13
|
+
`OUTPUT_VALIDATION_ERROR` means a tool response does not match its advertised output schema; `INVALID_REMOTE_RESPONSE` means the MCP result is malformed. Check the server tool contract and runtime version. These errors do not establish an authentication failure: do not rotate keys, switch projects or repeat unchanged requests as a remedy. Another read tool in the same configured project may still work. Authentication (`UNAUTHENTICATED`), authorization (`FORBIDDEN`) and project-configuration errors still follow the stop rules above. Never bypass a denial with another tool or key.
|
|
14
|
+
|
|
15
|
+
The bridge reports safe error categories and tool names without forwarding raw response bodies, credentials or provider error data. A failed write response can follow a successful mutation; any identical retry must preserve the original requestId and input.
|
package/src/bridge.mjs
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
// Bundled once at publication, copied into private storage at installation.
|
|
2
2
|
// Codex reserves Authorization in http_headers_helper. Its stdio transport
|
|
3
3
|
// therefore uses this local adapter to authenticate to the unchanged remote MCP.
|
|
4
|
-
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
|
|
4
|
+
import { Client, StreamableHTTPClientTransport, SdkError, SdkErrorCode, SdkHttpError, UnauthorizedError } from '@modelcontextprotocol/client';
|
|
5
5
|
import { Server, ProtocolError, ProtocolErrorCode } from '@modelcontextprotocol/server';
|
|
6
6
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
7
7
|
import { readCredential } from './auth.mjs';
|
|
8
8
|
import { pathToFileURL } from 'node:url';
|
|
9
9
|
import { resolve } from 'node:path';
|
|
10
10
|
|
|
11
|
+
// Forward only a stable category and safe context, never raw remote messages or data.
|
|
12
|
+
function requestError(error, name) {
|
|
13
|
+
const tool = typeof name === 'string' && /^[a-z][a-z0-9_]{0,63}$/i.test(name) ? name : undefined;
|
|
14
|
+
let code = 'REQUEST_FAILED', retryable = false, message = 'The MCP request failed. Run foundocs-setup doctor for connection diagnostics.';
|
|
15
|
+
let httpStatus, remoteCode;
|
|
16
|
+
const schemaError = error instanceof ProtocolError && (
|
|
17
|
+
(error.code === ProtocolErrorCode.InvalidParams && (
|
|
18
|
+
error.message.startsWith("Structured content does not match the tool's output schema:") ||
|
|
19
|
+
error.message.startsWith('Failed to validate structured content:') ||
|
|
20
|
+
/^Tool '[^']+' has an invalid outputSchema:/.test(error.message)
|
|
21
|
+
)) || (error.code === ProtocolErrorCode.InvalidRequest && /^Tool .+ has an output schema but did not return structured content$/.test(error.message))
|
|
22
|
+
);
|
|
23
|
+
if (schemaError) {
|
|
24
|
+
code = 'OUTPUT_VALIDATION_ERROR';
|
|
25
|
+
message = 'The server response does not match the advertised tool output schema. Update the server tool contract; changing credentials will not fix this error.';
|
|
26
|
+
} else if (error instanceof SdkHttpError || error instanceof UnauthorizedError) {
|
|
27
|
+
httpStatus = error instanceof UnauthorizedError ? 401 : error.status;
|
|
28
|
+
if (httpStatus === 401) { code = 'UNAUTHENTICATED'; message = 'Authentication failed (HTTP 401). Run foundocs-setup doctor and check the configured workspace key.'; }
|
|
29
|
+
else if (httpStatus === 403) { code = 'FORBIDDEN'; message = 'Access was denied (HTTP 403). Check the workspace key permissions for this project.'; }
|
|
30
|
+
else if (httpStatus === 429) { code = 'RATE_LIMITED'; retryable = true; message = 'The server rate limit was reached (HTTP 429). Wait before retrying.'; }
|
|
31
|
+
else { code = 'REMOTE_HTTP_ERROR'; retryable = httpStatus >= 500; message = `The remote MCP server returned HTTP ${httpStatus}. Check the server status.`; }
|
|
32
|
+
} else if (error instanceof SdkError && error.code === SdkErrorCode.RequestTimeout) {
|
|
33
|
+
code = 'REQUEST_TIMEOUT'; retryable = true; message = 'The remote MCP request timed out.';
|
|
34
|
+
} else if ((error instanceof SdkError && [SdkErrorCode.InvalidResult, SdkErrorCode.UnsupportedResultType].includes(error.code))) {
|
|
35
|
+
code = 'INVALID_REMOTE_RESPONSE'; message = 'The remote MCP response is malformed. Check the server protocol and response schema.';
|
|
36
|
+
} else if ((error instanceof SdkError && [SdkErrorCode.NotConnected, SdkErrorCode.ConnectionClosed, SdkErrorCode.SendFailed].includes(error.code)) ||
|
|
37
|
+
(error instanceof TypeError && error.message === 'fetch failed') || ['AbortError', 'TimeoutError'].includes(error?.name)) {
|
|
38
|
+
code = 'CONNECTION_ERROR'; retryable = true; message = 'The remote MCP connection failed or was interrupted. Check connectivity and the server status.';
|
|
39
|
+
} else if (error instanceof ProtocolError) {
|
|
40
|
+
code = 'REMOTE_PROTOCOL_ERROR'; remoteCode = error.code;
|
|
41
|
+
message = 'The remote MCP server returned a protocol error. Check the requested tool and arguments.';
|
|
42
|
+
}
|
|
43
|
+
return new ProtocolError(ProtocolErrorCode.InternalError,
|
|
44
|
+
`Foundocs ${tool ?? 'request'} [${code}]: ${message} Writes may already have succeeded; retry only with the same requestId and input.`,
|
|
45
|
+
{ code, retryable, ...(tool ? { tool } : {}), ...(httpStatus !== undefined ? { httpStatus } : {}), ...(remoteCode !== undefined ? { remoteCode } : {}) });
|
|
46
|
+
}
|
|
47
|
+
|
|
11
48
|
export async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint }) {
|
|
12
49
|
let remote, local;
|
|
13
50
|
async function close() {
|
|
@@ -30,20 +67,20 @@ try {
|
|
|
30
67
|
local = new Server({ name: 'foundocs', version: '0.2.0' }, { capabilities: { tools: {} }, instructions: remote.getInstructions() });
|
|
31
68
|
local.setRequestHandler('tools/list', async (request) => {
|
|
32
69
|
try { return await remote.listTools(request.params); }
|
|
33
|
-
catch { throw
|
|
70
|
+
catch (error) { throw requestError(error, 'tools_list'); }
|
|
34
71
|
});
|
|
35
72
|
local.setRequestHandler('tools/call', async (request) => {
|
|
36
73
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(request.params.arguments?.project_id)) throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Read and pass the explicit project_id from the governing foundocs.json.');
|
|
37
74
|
try { return await remote.callTool(request.params); }
|
|
38
|
-
catch { throw
|
|
75
|
+
catch (error) { throw requestError(error, request.params.name); }
|
|
39
76
|
});
|
|
40
77
|
local.onerror = () => process.stderr.write('Foundocs local MCP transport error.\n');
|
|
41
78
|
remote.onerror = () => process.stderr.write('Foundocs remote MCP transport error.\n');
|
|
42
79
|
process.stdin.on('end', () => { void close(); });
|
|
43
80
|
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { void close().finally(() => process.exit(0)); });
|
|
44
81
|
await local.connect(new StdioServerTransport());
|
|
45
|
-
} catch {
|
|
46
|
-
process.stderr.write(
|
|
82
|
+
} catch (error) {
|
|
83
|
+
process.stderr.write(`Foundocs MCP bridge unavailable. ${requestError(error, 'initialize').message}\n`);
|
|
47
84
|
await close(); process.exitCode = 1;
|
|
48
85
|
}
|
|
49
86
|
|