{"record":{"id":"36fbfe9ab068843d","repo":"n8n-io/n8n","slug":"this-tool-is-only-available-when-running-inside-th","errorCode":null,"errorMessage":"This tool is only available when running inside the n8n gateway context.","messagePattern":"This tool is only available when running inside the n8n gateway context\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/mcp-browser/src/tools/credential.ts","lineNumber":172,"sourceCode":"\t\t\t}\n\n\t\t\treturn formatCallToolResult({ ok: true, credentialId: credential.credentialId });\n\t\t},\n\t\tgetAffectedResources() {\n\t\t\treturn [CREATE_CREDENTIAL_RESOURCE];\n\t\t},\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction requireSecretsBuffer(\n\tcontext: ToolContext,\n): asserts context is ToolContext & { secretsBuffer: SecretsBuffer } {\n\tif (!context.secretsBuffer) {\n\t\tthrow new Error('This tool is only available when running inside the n8n gateway context.');\n\t}\n}\n\nfunction requireCreateCredential(context: ToolContext): asserts context is ToolContext & {\n\tcreateCredential: (payload: CreateCredentialPayload) => Promise<{ credentialId: string }>;\n} {\n\tif (!context.createCredential) {\n\t\tthrow new Error('This tool is only available when running inside the n8n gateway context.');\n\t}\n}\n\n/**\n * Recursively walk `resolveData`. Every leaf string value is a field name to\n * look up in `captured`. Throws if a field name is not found.\n */\nfunction resolveSecrets(\n\tresolveData: Record<string, unknown>,\n\tcaptured: Map<string, string>,","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/mcp-browser/src/tools/credential.ts#L154-L190","documentation":"Thrown by requireSecretsBuffer when context.secretsBuffer is undefined — the tool is being executed outside the n8n gateway context that provides a SecretsBuffer. The browser_capture_secret and browser_create_credential tools depend on gateway-injected infrastructure; without it they cannot function. This is an environment/initialization error, not a usage error.","triggerScenarios":"Invoking browser_capture_secret when the ToolContext was not constructed with a secretsBuffer (e.g. running the MCP browser server standalone, or a test harness that omitted the gateway wiring).","commonSituations":"Running the browser MCP tools in a non-gateway host (standalone CLI, direct adapter test). Gateway version mismatch where secretsBuffer injection was not yet implemented. Misconfigured tool registry that instantiates credential tools without gateway context.","solutions":["Run these tools only within the n8n gateway that injects secretsBuffer into ToolContext.","If testing, provide a mock secretsBuffer in the ToolContext before invoking the tool.","Upgrade the gateway/host to a version that wires secretsBuffer into the tool context."],"exampleFix":"// before — no secretsBuffer in context\ntool.execute(args, {}); // throws — context.secretsBuffer undefined\n\n// after — provide secretsBuffer (gateway or mock)\ntool.execute(args, { secretsBuffer: new SecretsBuffer(), createCredential: async () => ({ credentialId: 'x' }) });","handlingStrategy":"type-guard","validationCode":"if (!('secretsBuffer' in context) || !context.secretsBuffer) {\n  throw new Error('Run this tool inside the n8n gateway context.');\n}","typeGuard":"function hasSecretsBuffer(c: ToolContext): c is ToolContext & { secretsBuffer: SecretsBuffer } {\n  return !!c.secretsBuffer;\n}","tryCatchPattern":null,"preventionTips":["Only register browser_capture_secret/browser_create_credential in a gateway host.","Provide a mock secretsBuffer when unit-testing these tools.","Gate tool registration on the presence of gateway services."],"tags":["credential","gateway-context","secrets-buffer","initialization"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}