get_token
Fetch and cache authentication tokens for the ZenTao project management system using account credentials to enable API access.
Instructions
Fetch a token via POST /tokens using env ZENTAO_ACCOUNT/PASSWORD. Caches in-memory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| forceRefresh | No | Ignore cached token |
Implementation Reference
- src/zentao-mcp-server.js:545-554 (handler)Handler logic for the 'get_token' tool within the CallToolRequestSchema handler. It calls fetchToken with the optional forceRefresh argument and returns the token as a text content block.if (name === "get_token") { const token = await fetchToken(Boolean(args.forceRefresh)); return { content: [ { type: "text", text: `token=${token}`, }, ], };
- src/zentao-mcp-server.js:377-388 (schema)Schema definition for the 'get_token' tool, including name, description, and input schema (with optional forceRefresh boolean). Registered in ListToolsRequestSchema response.{ name: "get_token", description: "Fetch a token via POST /tokens using env ZENTAO_ACCOUNT/PASSWORD. Caches in-memory.", inputSchema: { type: "object", properties: { forceRefresh: { type: "boolean", description: "Ignore cached token" }, }, required: [], additionalProperties: false, }, },
- src/zentao-mcp-server.js:62-77 (helper)Core helper function that implements the token fetching logic: checks cache, asserts config, POSTs to /tokens endpoint with account/password, parses response, caches and returns the token.async function fetchToken(forceRefresh = false) { if (cachedToken && !forceRefresh) return cachedToken; assertConfig(); const url = `${baseUrl}/api.php/v1/tokens`; const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ account, password }), }); const text = await res.text(); if (!res.ok) throw new Error(`Token request failed: ${res.status} ${text}`); const data = safeJson(text); if (!data?.token) throw new Error("Token missing in response"); cachedToken = data.token; return cachedToken; }