get_me
Retrieve the authenticated user's details including ID, display name, and email from Azure DevOps.
Instructions
Get details of the authenticated user (id, displayName, email)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Main handler function for the get_me tool. Calls Azure DevOps Profile API to get authenticated user info (id, displayName, email). Throws if not Azure DevOps Services URL.
export async function getMe(connection: WebApi): Promise<UserProfile> { try { if (!isAzureDevOpsServicesUrl(connection.serverUrl)) { throw new AzureDevOpsValidationError( 'The get_me profile endpoint is only available for Azure DevOps Services', ); } const baseUrls = resolveAzureDevOpsBaseUrls(connection.serverUrl); const organization = baseUrls.organization; if (!organization) { throw new AzureDevOpsValidationError( 'Could not extract organization from Azure DevOps Services URL', ); } // Get the authorization header const authHeader = await getAuthorizationHeader(); // Make direct call to the Profile API endpoint // Note: This API is in the vssps.dev.azure.com domain, not dev.azure.com const response = await axios.get( `https://vssps.dev.azure.com/${organization}/_apis/profile/profiles/me?api-version=7.1`, { headers: { Authorization: authHeader, 'Content-Type': 'application/json', }, }, ); const profile = response.data; // Return the user profile with required fields return { id: profile.id, displayName: profile.displayName || '', email: profile.emailAddress || '', }; } catch (error) { // Handle authentication errors if ( axios.isAxiosError(error) && (error.response?.status === 401 || error.response?.status === 403) ) { throw new AzureDevOpsAuthenticationError( `Authentication failed: ${error.message}`, ); } // If it's already an AzureDevOpsError, rethrow it if (error instanceof AzureDevOpsError) { throw error; } // Otherwise, wrap it in a generic error throw new AzureDevOpsError( `Failed to get user information: ${error instanceof Error ? error.message : String(error)}`, ); } } - Helper function that constructs the authorization header using either PAT (Basic) or Azure Identity/Azure CLI (Bearer) authentication.
async function getAuthorizationHeader(): Promise<string> { try { // For PAT authentication, we can construct the header directly if ( process.env.AZURE_DEVOPS_AUTH_METHOD?.toLowerCase() === 'pat' && process.env.AZURE_DEVOPS_PAT ) { // For PAT auth, we can construct the Basic auth header directly const token = process.env.AZURE_DEVOPS_PAT; const base64Token = Buffer.from(`:${token}`).toString('base64'); return `Basic ${base64Token}`; } // For Azure Identity / Azure CLI auth, we need to get a token // using the Azure DevOps resource ID // Choose the appropriate credential based on auth method const credential = process.env.AZURE_DEVOPS_AUTH_METHOD?.toLowerCase() === 'azure-cli' ? new AzureCliCredential() : new DefaultAzureCredential(); // Azure DevOps resource ID for token acquisition const AZURE_DEVOPS_RESOURCE_ID = '499b84ac-1321-427f-aa17-267ca6975798'; // Get token for Azure DevOps const token = await credential.getToken( `${AZURE_DEVOPS_RESOURCE_ID}/.default`, ); if (!token || !token.token) { throw new Error('Failed to acquire token for Azure DevOps'); } return `Bearer ${token.token}`; } catch (error) { throw new AzureDevOpsAuthenticationError( `Failed to get authorization header: ${error instanceof Error ? error.message : String(error)}`, ); } } - src/features/users/schemas.ts:1-6 (schema)Schema definition for get_me tool - an empty object (no parameters required), using Zod validation.
import { z } from 'zod'; /** * Schema for the get_me tool, which takes no parameters */ export const GetMeSchema = z.object({}).strict(); - src/features/users/tool-definitions.ts:8-15 (registration)Tool registration definition - registers 'get_me' with its description and JSON schema.
export const usersTools: ToolDefinition[] = [ { name: 'get_me', description: 'Get details of the authenticated user (id, displayName, email)', inputSchema: zodToJsonSchema(GetMeSchema), }, ]; - src/features/users/index.ts:25-49 (registration)Request routing: isUsersRequest checks if the tool name is 'get_me', and handleUsersRequest dispatches to the getMe function.
export const isUsersRequest: RequestIdentifier = ( request: CallToolRequest, ): boolean => { const toolName = request.params.name; return ['get_me'].includes(toolName); }; /** * Handles users feature requests */ export const handleUsersRequest: RequestHandler = async ( connection: WebApi, request: CallToolRequest, ): Promise<{ content: Array<{ type: string; text: string }> }> => { switch (request.params.name) { case 'get_me': { const result = await getMe(connection); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } default: throw new Error(`Unknown users tool: ${request.params.name}`); } };