@mcp-consultant-tools/azure-b2c 22.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # @mcp-consultant-tools/azure-b2c
2
+
3
+ MCP server for Azure AD B2C user management via Microsoft Graph API.
4
+
5
+ ## Features
6
+
7
+ - **User Management**: List, search, get user details
8
+ - **Group Operations**: List groups, get memberships
9
+ - **Password Reset**: Reset passwords, force change on next login
10
+ - **User Lifecycle**: Create, update, and delete users
11
+ - **Granular Security**: Separate flags for each write operation type
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @mcp-consultant-tools/azure-b2c
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ ### Required Environment Variables
22
+
23
+ ```bash
24
+ AZURE_B2C_TENANT_ID=your-tenant.onmicrosoft.com # or tenant GUID
25
+ AZURE_B2C_CLIENT_ID=app-registration-client-id
26
+ AZURE_B2C_CLIENT_SECRET=app-registration-secret
27
+ ```
28
+
29
+ ### Optional Security Flags
30
+
31
+ All write operations are disabled by default. Enable only what you need:
32
+
33
+ ```bash
34
+ AZURE_B2C_ENABLE_PASSWORD_RESET=true # Enable password reset tools
35
+ AZURE_B2C_ENABLE_USER_CREATE=true # Enable user creation/update
36
+ AZURE_B2C_ENABLE_USER_DELETE=true # Enable user deletion (dangerous!)
37
+ ```
38
+
39
+ ### Optional Settings
40
+
41
+ ```bash
42
+ AZURE_B2C_MAX_RESULTS=100 # Max users/groups per request
43
+ ```
44
+
45
+ ## Azure Setup Requirements
46
+
47
+ 1. **Create App Registration** in your B2C tenant
48
+ 2. **Add API Permissions** (Application type):
49
+ - `User.ReadWrite.All`
50
+ - `Directory.ReadWrite.All` (for group operations)
51
+ 3. **Grant Admin Consent** for the permissions
52
+ 4. **Assign Role**: Add "User Administrator" role to the app's service principal
53
+
54
+ ## Tools (11)
55
+
56
+ ### Read-Only (Always Enabled)
57
+
58
+ | Tool | Description |
59
+ |------|-------------|
60
+ | `b2c-list-users` | List users with optional filtering |
61
+ | `b2c-get-user` | Get user by ID or email |
62
+ | `b2c-search-users` | Search by name, email |
63
+ | `b2c-list-groups` | List all groups |
64
+ | `b2c-get-user-groups` | Get groups for a user |
65
+ | `b2c-get-group-members` | Get members of a group |
66
+
67
+ ### Password Operations (Requires `AZURE_B2C_ENABLE_PASSWORD_RESET=true`)
68
+
69
+ | Tool | Description |
70
+ |------|-------------|
71
+ | `b2c-reset-user-password` | Set new password |
72
+ | `b2c-force-password-change` | Force change on next login |
73
+
74
+ ### User Creation (Requires `AZURE_B2C_ENABLE_USER_CREATE=true`)
75
+
76
+ | Tool | Description |
77
+ |------|-------------|
78
+ | `b2c-create-user` | Create new local account |
79
+ | `b2c-update-user` | Update user profile |
80
+
81
+ ### User Deletion (Requires `AZURE_B2C_ENABLE_USER_DELETE=true`)
82
+
83
+ | Tool | Description |
84
+ |------|-------------|
85
+ | `b2c-delete-user` | Delete user (irreversible!) |
86
+
87
+ ## Prompts (2)
88
+
89
+ | Prompt | Description |
90
+ |--------|-------------|
91
+ | `b2c-user-overview` | Formatted user profile with groups |
92
+ | `b2c-tenant-summary` | Tenant statistics |
93
+
94
+ ## Usage Example
95
+
96
+ ### MCP Client Configuration
97
+
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "azure-b2c": {
102
+ "command": "npx",
103
+ "args": ["@mcp-consultant-tools/azure-b2c"],
104
+ "env": {
105
+ "AZURE_B2C_TENANT_ID": "contoso.onmicrosoft.com",
106
+ "AZURE_B2C_CLIENT_ID": "your-client-id",
107
+ "AZURE_B2C_CLIENT_SECRET": "your-secret",
108
+ "AZURE_B2C_ENABLE_PASSWORD_RESET": "true"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ ```
114
+
115
+ ## Important Notes
116
+
117
+ - **Local Accounts Only**: Password operations only work for local B2C accounts, not federated/social accounts
118
+ - **Password Requirements**: Passwords must be 8-256 characters with at least 3 of: lowercase, uppercase, digit, symbol
119
+ - **Deletion is Permanent**: The delete operation cannot be undone
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Azure AD B2C Integration
3
+ *
4
+ * Provides user management capabilities for Azure AD B2C tenants via Microsoft Graph API.
5
+ * Supports user listing, search, password management, and group operations.
6
+ *
7
+ * Security Model:
8
+ * - Read-only operations: Always enabled (list, get, search users/groups)
9
+ * - Password operations: Requires AZURE_B2C_ENABLE_PASSWORD_RESET=true
10
+ * - User creation: Requires AZURE_B2C_ENABLE_USER_CREATE=true
11
+ * - User deletion: Requires AZURE_B2C_ENABLE_USER_DELETE=true
12
+ *
13
+ * Authentication:
14
+ * - Uses Microsoft Graph API with client credentials flow
15
+ * - Requires app registration with User.ReadWrite.All permission
16
+ * - App must have "User Administrator" role for password operations
17
+ */
18
+ /**
19
+ * Azure B2C user representation
20
+ */
21
+ export interface B2CUser {
22
+ id: string;
23
+ displayName: string;
24
+ givenName?: string;
25
+ surname?: string;
26
+ userPrincipalName: string;
27
+ mail?: string;
28
+ otherMails?: string[];
29
+ identities?: B2CIdentity[];
30
+ accountEnabled: boolean;
31
+ createdDateTime?: string;
32
+ lastSignInDateTime?: string;
33
+ jobTitle?: string;
34
+ department?: string;
35
+ mobilePhone?: string;
36
+ city?: string;
37
+ country?: string;
38
+ }
39
+ /**
40
+ * B2C Identity (local or federated)
41
+ */
42
+ export interface B2CIdentity {
43
+ signInType: string;
44
+ issuer: string;
45
+ issuerAssignedId: string;
46
+ }
47
+ /**
48
+ * B2C Group representation
49
+ */
50
+ export interface B2CGroup {
51
+ id: string;
52
+ displayName: string;
53
+ description?: string;
54
+ mailEnabled: boolean;
55
+ securityEnabled: boolean;
56
+ memberCount?: number;
57
+ }
58
+ /**
59
+ * Password profile for user creation/update
60
+ */
61
+ export interface PasswordProfile {
62
+ password: string;
63
+ forceChangePasswordNextSignIn: boolean;
64
+ }
65
+ /**
66
+ * User creation request
67
+ */
68
+ export interface CreateUserRequest {
69
+ displayName: string;
70
+ identities: B2CIdentity[];
71
+ passwordProfile: PasswordProfile;
72
+ givenName?: string;
73
+ surname?: string;
74
+ jobTitle?: string;
75
+ department?: string;
76
+ mobilePhone?: string;
77
+ city?: string;
78
+ country?: string;
79
+ }
80
+ /**
81
+ * User update request
82
+ */
83
+ export interface UpdateUserRequest {
84
+ displayName?: string;
85
+ givenName?: string;
86
+ surname?: string;
87
+ jobTitle?: string;
88
+ department?: string;
89
+ mobilePhone?: string;
90
+ city?: string;
91
+ country?: string;
92
+ accountEnabled?: boolean;
93
+ }
94
+ /**
95
+ * Azure B2C service configuration
96
+ */
97
+ export interface AzureB2CConfig {
98
+ tenantId: string;
99
+ clientId: string;
100
+ clientSecret: string;
101
+ enablePasswordReset: boolean;
102
+ enableUserCreate: boolean;
103
+ enableUserDelete: boolean;
104
+ maxResults?: number;
105
+ cacheUsersTTL?: number;
106
+ }
107
+ /**
108
+ * Tenant summary information
109
+ */
110
+ export interface TenantSummary {
111
+ tenantId: string;
112
+ userCount: number;
113
+ groupCount: number;
114
+ enabledUserCount: number;
115
+ disabledUserCount: number;
116
+ localAccountCount: number;
117
+ federatedAccountCount: number;
118
+ }
119
+ export declare class AzureB2CService {
120
+ private config;
121
+ private graphClient;
122
+ private credential;
123
+ private usersCache;
124
+ private groupsCache;
125
+ constructor(config: AzureB2CConfig);
126
+ /**
127
+ * Get or create the Microsoft Graph client
128
+ */
129
+ private getClient;
130
+ /**
131
+ * List all users with pagination
132
+ */
133
+ listUsers(top?: number, filter?: string, skipCache?: boolean): Promise<B2CUser[]>;
134
+ /**
135
+ * Get user by ID or email
136
+ */
137
+ getUser(userIdOrEmail: string): Promise<B2CUser>;
138
+ /**
139
+ * Search users by display name, email, or other criteria
140
+ */
141
+ searchUsers(searchTerm: string, searchFields?: ('displayName' | 'mail' | 'userPrincipalName' | 'givenName' | 'surname')[], top?: number): Promise<B2CUser[]>;
142
+ /**
143
+ * List all groups
144
+ */
145
+ listGroups(top?: number): Promise<B2CGroup[]>;
146
+ /**
147
+ * Get groups a user belongs to
148
+ */
149
+ getUserGroups(userId: string): Promise<B2CGroup[]>;
150
+ /**
151
+ * Get members of a group
152
+ */
153
+ getGroupMembers(groupId: string, top?: number): Promise<B2CUser[]>;
154
+ /**
155
+ * Reset user password
156
+ * Requires: AZURE_B2C_ENABLE_PASSWORD_RESET=true
157
+ */
158
+ resetUserPassword(userId: string, newPassword: string, forceChangeOnNextLogin?: boolean): Promise<void>;
159
+ /**
160
+ * Force password change on next login
161
+ * Requires: AZURE_B2C_ENABLE_PASSWORD_RESET=true
162
+ */
163
+ forcePasswordChange(userId: string): Promise<void>;
164
+ /**
165
+ * Create a new local account user
166
+ * Requires: AZURE_B2C_ENABLE_USER_CREATE=true
167
+ */
168
+ createUser(request: CreateUserRequest): Promise<B2CUser>;
169
+ /**
170
+ * Update user profile (non-password fields)
171
+ * Requires: AZURE_B2C_ENABLE_USER_CREATE=true
172
+ */
173
+ updateUser(userId: string, updates: UpdateUserRequest): Promise<B2CUser>;
174
+ /**
175
+ * Delete a user (irreversible)
176
+ * Requires: AZURE_B2C_ENABLE_USER_DELETE=true
177
+ */
178
+ deleteUser(userId: string): Promise<void>;
179
+ /**
180
+ * Get tenant summary (user/group counts)
181
+ */
182
+ getTenantSummary(): Promise<TenantSummary>;
183
+ /**
184
+ * Test connection to the B2C tenant
185
+ */
186
+ testConnection(): Promise<{
187
+ connected: boolean;
188
+ tenantId: string;
189
+ canReadUsers: boolean;
190
+ canReadGroups: boolean;
191
+ error?: string;
192
+ }>;
193
+ /**
194
+ * Get current configuration status
195
+ */
196
+ getConfigStatus(): {
197
+ tenantId: string;
198
+ enablePasswordReset: boolean;
199
+ enableUserCreate: boolean;
200
+ enableUserDelete: boolean;
201
+ };
202
+ /**
203
+ * Check if operation is permitted
204
+ */
205
+ private checkPermission;
206
+ /**
207
+ * Map Graph API user response to B2CUser
208
+ */
209
+ private mapUserResponse;
210
+ /**
211
+ * Map array of Graph API user responses
212
+ */
213
+ private mapUsersResponse;
214
+ /**
215
+ * Map Graph API group response to B2CGroup
216
+ */
217
+ private mapGroupResponse;
218
+ /**
219
+ * Map array of Graph API group responses
220
+ */
221
+ private mapGroupsResponse;
222
+ /**
223
+ * Enhance error with helpful context
224
+ */
225
+ private enhanceError;
226
+ /**
227
+ * Clear all caches
228
+ */
229
+ clearCache(): void;
230
+ }
231
+ //# sourceMappingURL=AzureB2CService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureB2CService.d.ts","sourceRoot":"","sources":["../src/AzureB2CService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAWH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MA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