Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(mcp): support KANEO_API_KEY for non-interactive auth

Andrej014cc9622b5a
diff --git a/packages/mcp/README.md b/packages/mcp/README.md
index 2d619c250..b7638a50d 100644
--- a/packages/mcp/README.md
+++ b/packages/mcp/README.md
@@ -25,6 +25,7 @@ DEVICE_AUTH_CLIENT_IDS=kaneo-cli,kaneo-mcp,your-client-id
|----------|-------------|
| `KANEO_API_URL` | Kaneo API origin (default `http://localhost:1337`). Do not include `/api`. |
| `KANEO_MCP_CLIENT_ID` | Device-flow client id (default `kaneo-mcp`). Must match `DEVICE_AUTH_CLIENT_IDS` on the server. |
+| `KANEO_API_KEY` | **Optional.** A Kaneo API key (create one under Settings → Account → Developer). When set, the server authenticates with it as a Bearer token and skips the interactive device flow — use this for headless/Docker setups. |
## Install
@@ -108,6 +109,10 @@ On the first tool call that needs Kaneo, the server:
4. Polls `POST /api/auth/device/token` until approved
5. Stores the access token at `~/.config/kaneo-mcp/credentials.json` with mode `0600`
+### Non-interactive (API key)
+
+For headless or sandboxed environments where opening a browser is impractical, set `KANEO_API_KEY` to a key created under Settings → Account → Developer. The server sends it as a Bearer token on every request and skips the device flow entirely, so no token is cached to disk.
+
## Tools
- Session: `whoami`, `list_workspaces`
diff --git a/packages/mcp/src/auth/auth-service.ts b/packages/mcp/src/auth/auth-service.ts
index 084e36f10..6101a98b3 100644
--- a/packages/mcp/src/auth/auth-service.ts
+++ b/packages/mcp/src/auth/auth-service.ts
@@ -10,6 +10,7 @@ import {
export type AuthServiceOptions = {
baseUrl: string;
clientId: string;
+ apiKey?: string;
};
type TokenValidationResult = "valid" | "invalid" | "unknown";
@@ -17,14 +18,26 @@ type TokenValidationResult = "valid" | "invalid" | "unknown";
export class AuthService {
readonly baseUrl: string;
readonly clientId: string;
+ private readonly apiKey?: string;
private activeGetAccessTokenPromise?: Promise<string>;
constructor(options: AuthServiceOptions) {
this.baseUrl = options.baseUrl;
this.clientId = options.clientId;
+ this.apiKey = options.apiKey;
+ }
+
+ /**
+ * True when a pre-created Kaneo API key is used instead of the interactive
+ * device flow. Callers use this to avoid clearing/retrying auth on a 401.
+ */
+ get usingApiKey(): boolean {
+ return Boolean(this.apiKey);
}
async clearToken(): Promise<void> {
+ // Nothing to clear for API-key auth; the key is static config.
+ if (this.apiKey) return;
await clearCredentials();
}
@@ -60,6 +73,13 @@ export class AuthService {
* Returns a valid access token, running the device authorization flow if needed.
*/
async getAccessToken(): Promise<string> {
+ // Non-interactive auth: a pre-created Kaneo API key (KANEO_API_KEY) is sent
+ // as a Bearer token, which the REST API already accepts. This skips the
+ // device flow so the MCP server works in headless/Docker environments.
+ if (this.apiKey) {
+ return this.apiKey;
+ }
+
if (this.activeGetAccessTokenPromise) {
return await this.activeGetAccessTokenPromise;
}
diff --git a/packages/mcp/src/kaneo/client.ts b/packages/mcp/src/kaneo/client.ts
index e72c62e76..98ba9b6b5 100644
--- a/packages/mcp/src/kaneo/client.ts
+++ b/packages/mcp/src/kaneo/client.ts
@@ -36,7 +36,9 @@ export class KaneoClient {
: timeoutSignal;
const res = await fetch(url, { ...init, headers, signal });
- if (res.status === 401 && !didRetry) {
+ // With a static API key there is nothing to refresh, so surface the 401
+ // instead of looping back into the interactive device flow.
+ if (res.status === 401 && !didRetry && !this.auth.usingApiKey) {
await this.auth.clearToken();
return this.authorizedFetch(path, init, true);
}
diff --git a/packages/mcp/src/server.ts b/packages/mcp/src/server.ts
index 615da8159..9c607dc0f 100644
--- a/packages/mcp/src/server.ts
+++ b/packages/mcp/src/server.ts
@@ -15,7 +15,8 @@ export function createMcpServer(): McpServer {
process.env.KANEO_API_URL || "http://localhost:1337",
);
const clientId = process.env.KANEO_MCP_CLIENT_ID || "kaneo-mcp";
- const auth = new AuthService({ baseUrl, clientId });
+ const apiKey = process.env.KANEO_API_KEY || undefined;
+ const auth = new AuthService({ baseUrl, clientId, apiKey });
const client = new KaneoClient({ baseUrl, auth });
const server = new McpServer({
name: "kaneo-mcp",