get-user-info
Retrieve user information from Dynamics 365 to access contact details, roles, and permissions for system management and support tasks.
Instructions
Get user info from Dynamics 365
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:11-36 (handler)Handler function that executes the get-user-info tool: calls makeWhoAmIRequest on Dynamics365 instance and returns formatted user info 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)Registers the get-user-info tool on the MCP server with no 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 in Dynamics365 class that makes WhoAmI API request to fetch current user info, used by the tool handler.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; }