get-user-info
Retrieve user information from Dynamics 365 to access contact details, roles, and permissions for account management and workflow coordination.
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)Handler function that executes the get-user-info tool: calls makeWhoAmIRequest on the Dynamics365 instance, formats the user information into an MCP response, or returns an error message.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 with the MCP server, including name, description, empty input schema, and inline handler function.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 in Dynamics365 class that performs the WhoAmI API request to retrieve current user information, including additional user details from systemusers endpoint.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; }