get-user-info
Retrieve user details from Dynamics 365 using the Dynamics 365 MCP Server for efficient data access and management.
Instructions
Get user info from Dynamics 365
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:11-35 (handler)Inline handler function for the "get-user-info" tool. Fetches user info using d365.makeWhoAmIRequest() and returns formatted text response or error.async () => { try { const response = await d365.makeWhoAmIRequest(); return { content: [ { type: "text", text: `Hi ${response.FullName}, your user ID is ${response.UserId} and your business unit ID is ${response.BusinessUnitId}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your credentials and try again.`, }, ], isError: true, }; } }
- src/tools.ts:7-36 (registration)Registration of the "get-user-info" tool using McpServer.tool() with name, description, empty input schema, and inline handler.server.tool( "get-user-info", "Get user info from Dynamics 365", {}, async () => { try { const response = await d365.makeWhoAmIRequest(); return { content: [ { type: "text", text: `Hi ${response.FullName}, your user ID is ${response.UserId} and your business unit ID is ${response.BusinessUnitId}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }, please check your credentials and try again.`, }, ], isError: true, }; } } );
- src/main.ts:152-174 (helper)Helper method makeWhoAmIRequest() in Dynamics365 class that queries Dynamics 365 API for current user's WhoAmI and additional user details.public async makeWhoAmIRequest(): Promise<{ BusinessUnitId: string; UserId: string; OrganizationId: string; UserName?: string; FullName?: string; }> { const data = await this.makeApiRequest("api/data/v9.2/WhoAmI", "GET"); // If we want to get more details about the user, we can make an additional request if (data && data.UserId) { const userDetails = await this.makeApiRequest( `api/data/v9.2/systemusers(${data.UserId})`, "GET", undefined, { Prefer: 'odata.include-annotations="*"' } ); data.UserName = userDetails.domainname; data.FullName = userDetails.fullname; } return data; }