{"record":{"id":"737a567b1ea938ef","repo":"NousResearch/hermes-agent","slug":"bearer-token-required","errorCode":null,"errorMessage":"Bearer token required","messagePattern":"Bearer token required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/lib/mcp-server-create.ts","lineNumber":58,"sourceCode":"    if (!line) continue;\n    const separator = line.indexOf(\"=\");\n    if (separator === -1) continue;\n    const key = line.slice(0, separator).trim();\n    const value = line.slice(separator + 1).trim();\n    if (key) env[key] = value;\n  }\n  return env;\n}\n\nexport function buildMcpServerCreate(draft: McpServerDraft): McpServerCreate {\n  const name = draft.name.trim();\n  if (!name) throw new Error(\"Name required\");\n\n  if (draft.transport === \"http\") {\n    const url = draft.url.trim();\n    if (!url) throw new Error(\"URL required\");\n    if (draft.httpAuth === \"header\" && !draft.bearerToken.trim()) {\n      throw new Error(\"Bearer token required\");\n    }\n\n    const server: McpServerCreate = { name, url };\n    if (draft.httpAuth !== \"none\") server.auth = draft.httpAuth;\n    if (draft.httpAuth === \"header\") {\n      server.bearer_token = draft.bearerToken;\n    }\n    return server;\n  }\n\n  const command = draft.command.trim();\n  if (!command) throw new Error(\"Command required\");\n\n  const server: McpServerCreate = { name, command };\n  const args = parseArgs(draft.args);\n  if (args.length) server.args = args;\n  const env = parseEnv(draft.env);\n  if (Object.keys(env).length) server.env = env;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/web/src/lib/mcp-server-create.ts#L40-L76","documentation":"When an HTTP-transport MCP server selects header auth (httpAuth === 'header'), a bearer token is mandatory and is sent as bearer_token in the create payload. A whitespace-only token fails the trim check and throws client-side.","triggerScenarios":"Choosing 'Bearer token' auth in the add-server form but leaving the token field empty; pasting only whitespace; state where httpAuth defaults to 'header' before the user enters a token.","commonSituations":"Users selecting header auth 'just in case' without a token; autofill failing on password-type inputs; form resubmission after a failed attempt clearing the token field.","solutions":["Paste the server's bearer token into the token field and submit.","If the server needs no auth header, set auth to 'none'; if it uses OAuth, pick that option instead.","Disable submit until bearerToken.trim() is non-empty when httpAuth === 'header'."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (draft.transport === 'http' && draft.httpAuth === 'header' && !draft.bearerToken.trim()) {\n  setFieldError('bearerToken', 'Bearer token is required for header auth')\n  return\n}","typeGuard":"function hasBearerWhenHeader(d: McpServerDraft): boolean {\n  return d.httpAuth !== 'header' || d.bearerToken.trim().length > 0\n}","tryCatchPattern":"try {\n  const payload = buildMcpServerCreate(draft)\n} catch (err) {\n  if (String(err) === 'Bearer token required') { focusField('bearerToken'); return }\n  throw err\n}","preventionTips":["Reset the auth choice to 'none' when the user leaves the token blank.","Never log or persist the bearer token beyond the create call.","Validate token presence before enabling submit when header auth is selected."],"tags":["validation","mcp","auth","form"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}