401 from an MCP server: "Missing, unknown or expired token"
An app gets a 401 from Hamloy when its token is missing, revoked or badly written in the Authorization header. What each answer means, and the fix.
The app shows the server as failed, or "needs authentication", and its log holds a 401 with one of these from Hamloy:
Missing, unknown or expired token. Sign in again from your app, or make an API token at https://hamloy.com/connect.
The Authorization header should be Bearer, a space and the token, and nothing else; this one is the token without Bearer before it. The sign-in itself may be fine.
What each one means
"Missing, unknown or expired token." The app sent no key, or one Hamloy doesn't have. That is one of three things:
- The app never signed in. An app that signs in gets this answer on its very first call, on purpose: it is how the app learns where to send you. If no browser window followed, see No sign-in window opens.
- The sign-in went unused for 90 days, or you chose Disconnect for that app on the Connect page. The app asks you to sign in again.
- The API token was revoked, or copied with a space or a missing character. A token starts with
hml_and is shown once.
"The Authorization header should be Bearer, a space and the token." The key may be fine; the header around it isn't. Hamloy says which way it is wrong without repeating the token: the token without Bearer before it, or a helper's whole output pasted where the value should be.
The fix
For an app that signs in: sign in again from the app. In Claude Code, type /mcp, pick hamloy and choose Authenticate; in Gemini CLI, /mcp auth hamloy; in Codex, codex mcp login hamloy. In Cursor and VS Code, start the server again and the browser opens.
For a token, the header is exactly this, in whichever file the app reads:
{
"mcpServers": {
"hamloy": {
"url": "https://hamloy.com/mcp",
"headers": { "Authorization": "Bearer hml_…" }
}
}
}
If the token is lost or may have a typo in it, don't hunt for it. Revoke it on the Connect page under API tokens and make a new one; anything still using the old one is refused from then on. Keep the token in a variable, not in a file the repo keeps: see The token in a variable isn't read.
Check that it worked
Ask the app "What's open in Hamloy?" It answers with your lists instead of an error, and the Connect page shows the app or the token as used just now.
More on the two ways in: Remote link or API token and API tokens.