aps_get_token
Obtain a 2-legged access token for Autodesk Platform Services to verify credential configuration. Cached and auto-refreshed by other tools.
Instructions
Get a 2‑legged access token for Autodesk Platform Services (APS). Use this to verify that credentials are configured correctly. The token is cached and auto‑refreshed by all other tools, so you rarely need to call this explicitly.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:1023-1030 (handler)The handler function that executes the 'aps_get_token' tool logic. It calls the internal token() function which prefers a cached 3-legged token, falling back to a 2-legged token via getApsToken(), then returns a success message with the token length.
// ── aps_get_token ──────────────────────────────────────────── if (name === "aps_get_token") { const t = await token(); return ok( `2‑legged token obtained (length ${t.length}). ` + "All other tools use this token automatically – you don't need to pass it.", ); } - src/index.ts:167-175 (schema)The input schema definition for 'aps_get_token'. It declares the tool name, description, and input schema (empty object, no parameters required).
// 1 ── aps_get_token { name: "aps_get_token", description: "Get a 2‑legged access token for Autodesk Platform Services (APS). " + "Use this to verify that credentials are configured correctly. " + "The token is cached and auto‑refreshed by all other tools, so you rarely need to call this explicitly.", inputSchema: { type: "object" as const, properties: {} }, }, - src/index.ts:1588-1588 (registration)The tool is registered in the TOOLS array (which is passed to ListToolsRequestSchema handler), making 'aps_get_token' available as an MCP tool.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS })); - src/index.ts:112-117 (helper)The internal token() helper function used by the handler. Prefers a valid 3-legged token (user context) via getValid3loToken(), otherwise falls back to a 2-legged (app context) token via getApsToken() from aps-auth.ts.
async function token(): Promise<string> { requireApsEnv(); const three = await getValid3loToken(APS_CLIENT_ID, APS_CLIENT_SECRET); if (three) return three; return getApsToken(APS_CLIENT_ID, APS_CLIENT_SECRET, APS_SCOPE || undefined); } - src/aps-auth.ts:68-108 (helper)The core getApsToken() function that obtains a 2-legged OAuth access token from APS. It uses client credentials grant, caches the token in memory until near expiry, and defaults to 'data:read' scope.
export async function getApsToken( clientId: string, clientSecret: string, scope?: string ): Promise<string> { const effectiveScope = (scope?.trim() || DEFAULT_SCOPE); const now = Date.now(); if ( cachedToken && cachedToken.expiresAt > now + 60_000 && cachedToken.scope === effectiveScope ) { return cachedToken.token; } const body = new URLSearchParams({ grant_type: "client_credentials", client_id: clientId, client_secret: clientSecret, scope: effectiveScope, }); const res = await fetch(APS_TOKEN_URL, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: body.toString(), }); if (!res.ok) { const text = await res.text(); throw new Error(`APS token failed (${res.status}): ${text}`); } const data = (await res.json()) as ApsTokenResponse; cachedToken = { token: data.access_token, expiresAt: now + (data.expires_in - 60) * 1000, scope: effectiveScope, }; return data.access_token; }