snow-flow 1.1.68 → 1.1.69

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.
@@ -2136,58 +2136,111 @@ class ServiceNowIntelligentMCP {
2136
2136
  current_permissions: {},
2137
2137
  required_actions: []
2138
2138
  };
2139
- // Check current user permissions
2140
- const currentUser = await this.client.get('/api/now/table/sys_user', {
2141
- sysparm_query: 'user_name=current_user',
2142
- sysparm_fields: 'sys_id,user_name,roles'
2139
+ // Get current user info
2140
+ const whoAmI = await this.client.get('/api/now/table/sys_user', {
2141
+ sysparm_query: 'user_name=admin', // Try admin user first
2142
+ sysparm_fields: 'sys_id,user_name,name,email',
2143
+ sysparm_limit: 1
2143
2144
  });
2144
- if (currentUser.result?.[0]) {
2145
- // Get user roles
2146
- const userRoles = await this.client.get('/api/now/table/sys_user_has_role', {
2147
- sysparm_query: `user=${currentUser.result[0].sys_id}`,
2148
- sysparm_fields: 'role.name,role.sys_id'
2149
- });
2150
- escalationResults.current_permissions = {
2151
- user_id: currentUser.result[0].sys_id,
2152
- current_roles: userRoles.result?.map((r) => r.role?.name || r.role) || []
2153
- };
2154
- // Check which roles are missing
2155
- const currentRoleNames = escalationResults.current_permissions.current_roles;
2156
- const missingRoles = required_roles.filter((role) => !currentRoleNames.includes(role));
2157
- if (missingRoles.length === 0) {
2158
- escalationResults.escalation_status = 'not_needed';
2159
- escalationResults.message = 'User already has all required permissions';
2160
- }
2161
- else {
2162
- escalationResults.escalation_status = 'required';
2163
- escalationResults.missing_roles = missingRoles;
2164
- // Generate escalation recommendations
2165
- escalationResults.required_actions = [
2166
- `Contact ServiceNow administrator to temporarily grant these roles: ${missingRoles.join(', ')}`,
2167
- `Reason: ${reason}`,
2168
- `Duration: ${duration}`,
2169
- `Workflow context: ${workflow_context || 'Multi-agent development'}`
2170
- ];
2171
- if (duration === 'session') {
2172
- escalationResults.required_actions.push('Permissions can be revoked after current development session');
2173
- }
2174
- // Provide specific guidance for common roles
2175
- for (const role of missingRoles) {
2176
- switch (role) {
2177
- case 'admin':
2178
- escalationResults.required_actions.push('🔐 Admin role: Navigate to User Administration > Users, find your user, and add "admin" role');
2179
- break;
2180
- case 'app_creator':
2181
- escalationResults.required_actions.push('📱 App Creator role: Required for creating new applications and scoped artifacts');
2182
- break;
2183
- case 'system_administrator':
2184
- escalationResults.required_actions.push('⚙️ System Administrator: Full system access for advanced configuration');
2185
- break;
2186
- }
2187
- }
2145
+ const currentUser = whoAmI.result?.[0];
2146
+ if (!currentUser) {
2147
+ return { content: [{
2148
+ type: 'text',
2149
+ text: '❌ Could not identify current user. Please ensure you are logged in to ServiceNow.'
2150
+ }] };
2151
+ }
2152
+ // Get user roles
2153
+ const userRoles = await this.client.get('/api/now/table/sys_user_has_role', {
2154
+ sysparm_query: `user=${currentUser.sys_id}`,
2155
+ sysparm_fields: 'role.name,role.description,inherited'
2156
+ });
2157
+ const currentRoles = userRoles.result?.map((r) => r.role?.name).filter(Boolean) || [];
2158
+ const missingRoles = required_roles.filter((role) => !currentRoles.includes(role));
2159
+ // Get instance URL
2160
+ const instanceUrl = process.env.SNOW_INSTANCE ?
2161
+ `https://${process.env.SNOW_INSTANCE.replace(/\/$/, '')}.service-now.com` :
2162
+ 'https://your-instance.service-now.com';
2163
+ if (missingRoles.length === 0) {
2164
+ return { content: [{
2165
+ type: 'text',
2166
+ text: `✅ **Permission Check Passed**\n\nYou already have all required roles:\n${required_roles.map((r) => `- ✓ ${r}`).join('\n')}\n\nNo escalation needed!`
2167
+ }] };
2168
+ }
2169
+ // Build actionable response
2170
+ let response = `🔐 **Permission Escalation Required**\n\n`;
2171
+ response += `**Current User:** ${currentUser.name} (${currentUser.user_name})\n`;
2172
+ response += `**Current Roles:** ${currentRoles.length > 0 ? currentRoles.join(', ') : 'None'}\n`;
2173
+ response += `**Missing Roles:** ${missingRoles.join(', ')}\n`;
2174
+ response += `**Reason:** ${reason}\n`;
2175
+ response += `**Duration:** ${duration}\n\n`;
2176
+ response += `## 🎯 Required Actions:\n\n`;
2177
+ // Provide specific instructions for each missing role
2178
+ for (const role of missingRoles) {
2179
+ response += `### ${role} Role\n`;
2180
+ switch (role) {
2181
+ case 'admin':
2182
+ response += `The **admin** role provides:\n`;
2183
+ response += `- Global scope access for creating widgets, flows, and applications\n`;
2184
+ response += `- Ability to modify system tables and configurations\n`;
2185
+ response += `- Access to all ServiceNow modules and features\n\n`;
2186
+ response += `**How to obtain:**\n`;
2187
+ response += `1. Contact your ServiceNow administrator\n`;
2188
+ response += `2. Or if you have admin access: [Click here to manage user roles](${instanceUrl}/sys_user.do?sys_id=${currentUser.sys_id})\n`;
2189
+ response += `3. In the "Roles" related list, click "Edit" and add "admin"\n\n`;
2190
+ break;
2191
+ case 'app_creator':
2192
+ response += `The **app_creator** role provides:\n`;
2193
+ response += `- Create custom applications and scoped apps\n`;
2194
+ response += `- Design application modules and menus\n`;
2195
+ response += `- Manage application artifacts\n\n`;
2196
+ response += `**How to obtain:**\n`;
2197
+ response += `1. Request from ServiceNow administrator\n`;
2198
+ response += `2. Or navigate to: [User Administration > Users](${instanceUrl}/sys_user_list.do)\n`;
2199
+ response += `3. Find your user record and add "app_creator" role\n\n`;
2200
+ break;
2201
+ case 'system_administrator':
2202
+ response += `The **system_administrator** role provides:\n`;
2203
+ response += `- Full system access and configuration\n`;
2204
+ response += `- Advanced scripting and development capabilities\n`;
2205
+ response += `- Access to all system properties and settings\n\n`;
2206
+ response += `**How to obtain:**\n`;
2207
+ response += `1. This is a highly privileged role - contact system admin\n`;
2208
+ response += `2. Requires approval from ServiceNow instance owner\n\n`;
2209
+ break;
2210
+ case 'global_admin':
2211
+ response += `The **global_admin** role provides:\n`;
2212
+ response += `- Cross-scope application access\n`;
2213
+ response += `- Global artifact creation and management\n`;
2214
+ response += `- Override scope restrictions\n\n`;
2215
+ response += `**How to obtain:**\n`;
2216
+ response += `1. Contact ServiceNow administrator\n`;
2217
+ response += `2. May require business justification\n\n`;
2218
+ break;
2219
+ default:
2220
+ response += `The **${role}** role is required for this operation.\n\n`;
2221
+ response += `**How to obtain:**\n`;
2222
+ response += `1. Contact your ServiceNow administrator\n`;
2223
+ response += `2. Request temporary access for: "${reason}"\n\n`;
2188
2224
  }
2189
2225
  }
2190
- return { content: [{ type: 'text', text: JSON.stringify(escalationResults, null, 2) }] };
2226
+ response += `## 💡 Alternative Solutions:\n\n`;
2227
+ response += `1. **Use a development instance** where you have admin access\n`;
2228
+ response += `2. **Request a personal developer instance** from [developer.servicenow.com](https://developer.servicenow.com)\n`;
2229
+ response += `3. **Work with a team member** who has the required permissions\n`;
2230
+ response += `4. **Use Update Sets** to package changes for deployment by an admin\n\n`;
2231
+ response += `## 📋 Template Request for Admin:\n\n`;
2232
+ response += `\`\`\`\n`;
2233
+ response += `Subject: Temporary Permission Request - ${reason}\n\n`;
2234
+ response += `Hi Admin,\n\n`;
2235
+ response += `I need temporary access to the following roles for development:\n`;
2236
+ response += `- Roles needed: ${missingRoles.join(', ')}\n`;
2237
+ response += `- Reason: ${reason}\n`;
2238
+ response += `- Duration: ${duration}\n`;
2239
+ response += `- Context: ${workflow_context || 'ServiceNow multi-agent development'}\n\n`;
2240
+ response += `These permissions can be revoked after the ${duration === 'session' ? 'current session' : duration}.\n\n`;
2241
+ response += `Thank you!\n`;
2242
+ response += `\`\`\``;
2243
+ return { content: [{ type: 'text', text: response }] };
2191
2244
  }
2192
2245
  catch (error) {
2193
2246
  return { content: [{