Skip to main content
Glama

get_user_last_location

Retrieve the last known location and login details for a specified Okta user by providing their unique user ID.

Instructions

Retrieve the last known location and login information for a user from Okta system logs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userIdYesThe unique identifier of the Okta user

Implementation Reference

  • The main handler function that implements the tool logic. It parses the userId input, fetches the user from Okta, queries system logs for the most recent login event in the last 90 days, and returns formatted location information including IP, city, state, country, device, and user agent.
    get_user_last_location: async (request: { parameters: unknown }) => { const { userId } = userSchemas.getUserLastLocation.parse( request.parameters ); try { const oktaClient = getOktaClient(); // First get the user to ensure they exist and get their login const user = await oktaClient.userApi.getUser({ userId }); if (!user || !user.profile) { return { content: [ { type: "text", text: `User with ID ${userId} not found.`, }, ], }; } // Get the last 90 days of system logs for this user's login events const ninetyDaysAgo = new Date(); ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90); // Use the system log API to get login events const logs = await oktaClient.systemLogApi.listLogEvents({ since: ninetyDaysAgo.toISOString(), filter: `target.id eq "${userId}" and (eventType eq "user.session.start" or eventType eq "user.authentication.auth_via_mfa" or eventType eq "user.authentication.sso")`, limit: 1, }); // Get the first (most recent) log entry const lastLogin = await logs.next(); if (!lastLogin || !lastLogin.value) { return { content: [ { type: "text", text: `No login events found for user ${user.profile.login} in the last 90 days. This might mean the user hasn't logged in recently or the events are not being captured in the system logs.`, }, ], }; } const event = lastLogin.value; const clientData = event.client || {}; const geographicalContext = event.client?.geographicalContext || {}; const formattedLocation = `• Last Login Information for User ${user.profile.login}: Time: ${formatDate(event.published)} Event Type: ${event.eventType || "N/A"} IP Address: ${clientData.ipAddress || "N/A"} City: ${geographicalContext.city || "N/A"} State: ${geographicalContext.state || "N/A"} Country: ${geographicalContext.country || "N/A"} Device: ${clientData.device || "N/A"} User Agent: ${clientData.userAgent || "N/A"}`; return { content: [ { type: "text", text: formattedLocation, }, ], }; } catch (error) { console.error("Error fetching user location:", error); return { content: [ { type: "text", text: `Failed to fetch user location: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } },
  • Zod schema for input validation of the tool's parameters, requiring a userId string.
    getUserLastLocation: z.object({ userId: z.string().min(1, "User ID is required"), }),
  • Tool registration in the userTools array, defining the name, description, and input schema for MCP tool registration.
    { name: "get_user_last_location", description: "Retrieve the last known location and login information for a user from Okta system logs", inputSchema: { type: "object", properties: { userId: { type: "string", description: "The unique identifier of the Okta user", }, }, required: ["userId"], }, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kapilduraphe/okta-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server