@unifiedmemory/cli 1.3.16 → 1.3.17
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/commands/init.js +0 -31
- package/lib/mcp-server.js +7 -8
- package/package.json +1 -1
package/commands/init.js
CHANGED
|
@@ -141,24 +141,6 @@ export async function init(options = {}) {
|
|
|
141
141
|
console.log(' 3. Run `um status` to verify configuration\n');
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
/**
|
|
145
|
-
* Validate that we have a real organization context (not fallback to user_id)
|
|
146
|
-
* @param {Object} authData - Auth data with user_id and org_id
|
|
147
|
-
* @returns {Object} { isValid, isPersonalContext, message }
|
|
148
|
-
*/
|
|
149
|
-
function validateOrganizationContext(authData) {
|
|
150
|
-
const isPersonalContext = authData.org_id === authData.user_id;
|
|
151
|
-
|
|
152
|
-
if (isPersonalContext) {
|
|
153
|
-
return {
|
|
154
|
-
isValid: false,
|
|
155
|
-
isPersonalContext: true,
|
|
156
|
-
message: 'You are in personal account context. Organization-scoped operations require an organization.',
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return { isValid: true, isPersonalContext: false, message: null };
|
|
161
|
-
}
|
|
162
144
|
|
|
163
145
|
async function ensureAuthenticated(options) {
|
|
164
146
|
// Try to load and refresh token if expired
|
|
@@ -213,19 +195,6 @@ async function ensureAuthenticated(options) {
|
|
|
213
195
|
async function selectOrCreateProject(authData, options) {
|
|
214
196
|
const apiUrl = authData.api_url || 'https://rose-asp-main-1c0b114.d2.zuplo.dev';
|
|
215
197
|
|
|
216
|
-
// Validate organization context BEFORE making API calls
|
|
217
|
-
const contextValidation = validateOrganizationContext(authData);
|
|
218
|
-
|
|
219
|
-
if (!contextValidation.isValid && contextValidation.isPersonalContext) {
|
|
220
|
-
console.log(chalk.yellow('\n⚠️ ' + contextValidation.message));
|
|
221
|
-
console.log(chalk.gray('\nOrganization-scoped projects require an organization context.'));
|
|
222
|
-
console.log(chalk.cyan('\nRecommended actions:'));
|
|
223
|
-
console.log(chalk.cyan(' 1. Switch to an organization: um org switch'));
|
|
224
|
-
console.log(chalk.cyan(' 2. Create an organization at: https://unifiedmemory.ai'));
|
|
225
|
-
console.log(chalk.cyan(' 3. Re-run: um init'));
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
198
|
// Fetch existing projects with enhanced error handling
|
|
230
199
|
console.log(chalk.gray('Fetching projects...'));
|
|
231
200
|
const result = await fetchProjects(authData, apiUrl);
|
package/lib/mcp-server.js
CHANGED
|
@@ -218,15 +218,14 @@ function buildAuthHeaders(authData, projectContext) {
|
|
|
218
218
|
headers['X-User-Id'] = authData.decoded.sub;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
// Add X-Org-Id - check JWT claims first, fall back to selectedOrgId
|
|
222
|
-
const orgId = authData.decoded?.o?.o_id || authData.selectedOrgId;
|
|
221
|
+
// Add X-Org-Id - check JWT claims first, fall back to selectedOrgId, then userId (personal account)
|
|
222
|
+
const orgId = authData.decoded?.o?.o_id || authData.selectedOrgId || authData.decoded?.sub;
|
|
223
223
|
const orgName = authData.decoded?.o?.o_name || authData.selectedOrgName;
|
|
224
224
|
|
|
225
225
|
if (orgId) {
|
|
226
226
|
headers['X-Org-Id'] = orgId;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
console.error(`✓ Using personal account context`);
|
|
227
|
+
const isPersonal = orgId === authData.decoded?.sub;
|
|
228
|
+
console.error(`✓ ${isPersonal ? 'Personal account' : 'Organization'}: ${orgName || orgId}`);
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
// Add project context if available
|
|
@@ -249,9 +248,9 @@ async function loadFreshAuth(projectContext) {
|
|
|
249
248
|
const authData = await loadAndRefreshToken();
|
|
250
249
|
const authHeaders = buildAuthHeaders(authData, projectContext);
|
|
251
250
|
|
|
252
|
-
// Build auth context - check JWT claims first, fall back to selectedOrgId
|
|
251
|
+
// Build auth context - check JWT claims first, fall back to selectedOrgId, then userId (personal account)
|
|
253
252
|
const jwtOrgId = authData.decoded?.o?.o_id;
|
|
254
|
-
const orgId = jwtOrgId || authData.selectedOrgId;
|
|
253
|
+
const orgId = jwtOrgId || authData.selectedOrgId || authData.decoded?.sub;
|
|
255
254
|
const orgName = authData.decoded?.o?.o_name || authData.selectedOrgName;
|
|
256
255
|
const orgRole = authData.decoded?.o?.o_role;
|
|
257
256
|
|
|
@@ -259,7 +258,7 @@ async function loadFreshAuth(projectContext) {
|
|
|
259
258
|
decoded: authData.decoded,
|
|
260
259
|
orgContext: orgId ? {
|
|
261
260
|
id: orgId,
|
|
262
|
-
name: orgName,
|
|
261
|
+
name: orgName || 'Personal',
|
|
263
262
|
role: orgRole,
|
|
264
263
|
} : null
|
|
265
264
|
};
|