authenticate
Exchange EVE Online SSO authorization codes for access tokens to securely access market data via the MCP server.
Instructions
Exchange authorization code for access token
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Authorization code from EVE Online SSO |
Implementation Reference
- src/index.ts:498-527 (handler)Executes the authentication logic by exchanging the authorization code for an access token using getToken, verifying the token to retrieve character info, and returning the details in MCP content format or an error.async ({ code }) => { try { const token = await getToken(code); const character = await verifyToken(token.access_token); return { content: [ { type: "text", text: JSON.stringify({ character_name: character.CharacterName, character_id: character.CharacterID, access_token: token.access_token, refresh_token: token.refresh_token, expires_in: token.expires_in, token_type: token.token_type }, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Authentication failed: ${error instanceof Error ? error.message : 'Unknown error'}` } ] }; } }
- src/index.ts:495-497 (schema)Zod schema defining the single input parameter 'code' for the authenticate tool.{ code: z.string().describe("Authorization code from EVE Online SSO") },
- src/index.ts:492-527 (registration)MCP server tool registration for 'authenticate', specifying name, description, input schema, and inline handler function.server.tool( "authenticate", "Exchange authorization code for access token", { code: z.string().describe("Authorization code from EVE Online SSO") }, async ({ code }) => { try { const token = await getToken(code); const character = await verifyToken(token.access_token); return { content: [ { type: "text", text: JSON.stringify({ character_name: character.CharacterName, character_id: character.CharacterID, access_token: token.access_token, refresh_token: token.refresh_token, expires_in: token.expires_in, token_type: token.token_type }, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Authentication failed: ${error instanceof Error ? error.message : 'Unknown error'}` } ] }; } }
- src/index.ts:127-149 (helper)Helper function to exchange EVE Online SSO authorization code for access and refresh tokens.async function getToken(code: string): Promise<EveAuthToken> { const response = await fetch("https://login.eveonline.com/v2/oauth/token", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", "Authorization": `Basic ${Buffer.from(`${EVE_CLIENT_ID}:${EVE_CLIENT_SECRET}`).toString("base64")}` }, body: new URLSearchParams({ grant_type: "authorization_code", code: code }) }); if (!response.ok) { throw new Error("Failed to get token"); } const data = await response.json() as EveAuthToken; return { ...data, issued_at: Date.now() }; }
- src/index.ts:177-189 (helper)Helper function to verify the access token and retrieve character information.async function verifyToken(token: string): Promise<EveCharacter> { const response = await fetch("https://login.eveonline.com/oauth/verify", { headers: { "Authorization": `Bearer ${token}` } }); if (!response.ok) { throw new Error("Failed to verify token"); } return response.json() as Promise<EveCharacter>; }