diff --git a/apps/mesh/src/storage/ports.ts b/apps/mesh/src/storage/ports.ts index c80123c112..c2b01a9f22 100644 --- a/apps/mesh/src/storage/ports.ts +++ b/apps/mesh/src/storage/ports.ts @@ -74,7 +74,11 @@ export interface ProjectStoragePort { export interface ProjectPluginConfigStoragePort { list(projectId: string): Promise; - get(projectId: string, pluginId: string): Promise; + get( + projectId: string, + pluginId: string, + organizationId: string, + ): Promise; upsert( projectId: string, pluginId: string, @@ -82,6 +86,7 @@ export interface ProjectPluginConfigStoragePort { connectionId?: string | null; settings?: Record | null; }, + organizationId: string, ): Promise; delete(projectId: string, pluginId: string): Promise; } diff --git a/apps/mesh/src/storage/project-plugin-configs.ts b/apps/mesh/src/storage/project-plugin-configs.ts index 8f023fdbea..f1f272919a 100644 --- a/apps/mesh/src/storage/project-plugin-configs.ts +++ b/apps/mesh/src/storage/project-plugin-configs.ts @@ -60,13 +60,17 @@ export class ProjectPluginConfigsStorage async get( projectId: string, pluginId: string, + organizationId: string, ): Promise { - const row = await this.db + let query = this.db .selectFrom("project_plugin_configs") - .selectAll() - .where("project_id", "=", projectId) - .where("plugin_id", "=", pluginId) - .executeTakeFirst(); + .selectAll("project_plugin_configs") + .where("project_plugin_configs.project_id", "=", projectId) + .where("project_plugin_configs.plugin_id", "=", pluginId) + .innerJoin("projects", "projects.id", "project_plugin_configs.project_id") + .where("projects.organization_id", "=", organizationId); + + const row = await query.executeTakeFirst(); return row ? this.parseRow(row) : null; } @@ -77,9 +81,10 @@ export class ProjectPluginConfigsStorage connectionId?: string | null; settings?: Record | null; }, + organizationId: string, ): Promise { const now = new Date().toISOString(); - const existing = await this.get(projectId, pluginId); + const existing = await this.get(projectId, pluginId, organizationId); if (existing) { const updateData: Record = { updated_at: now }; @@ -98,7 +103,7 @@ export class ProjectPluginConfigsStorage .where("plugin_id", "=", pluginId) .execute(); - const updated = await this.get(projectId, pluginId); + const updated = await this.get(projectId, pluginId, organizationId); if (!updated) { throw new Error("Failed to update project plugin config"); } @@ -119,7 +124,7 @@ export class ProjectPluginConfigsStorage }) .execute(); - const created = await this.get(projectId, pluginId); + const created = await this.get(projectId, pluginId, organizationId); if (!created) { throw new Error("Failed to create project plugin config"); } diff --git a/apps/mesh/src/tools/projects/get.ts b/apps/mesh/src/tools/projects/get.ts index 04b124ebc6..9d841c91bc 100644 --- a/apps/mesh/src/tools/projects/get.ts +++ b/apps/mesh/src/tools/projects/get.ts @@ -21,7 +21,6 @@ export const PROJECT_GET = defineTool({ }, inputSchema: z .object({ - organizationId: z.string().describe("Organization ID"), projectId: z .string() .optional() @@ -52,7 +51,7 @@ export const PROJECT_GET = defineTool({ project = await ctx.storage.projects.get(input.projectId); } else if (input.slug) { project = await ctx.storage.projects.getBySlug( - input.organizationId, + ctx.organization!.id, input.slug, ); } diff --git a/apps/mesh/src/tools/projects/plugin-config-get.ts b/apps/mesh/src/tools/projects/plugin-config-get.ts index fac88477ef..69f39b0ef0 100644 --- a/apps/mesh/src/tools/projects/plugin-config-get.ts +++ b/apps/mesh/src/tools/projects/plugin-config-get.ts @@ -37,9 +37,18 @@ export const PROJECT_PLUGIN_CONFIG_GET = defineTool({ const { projectId, pluginId } = input; + let organizationId = null; + + if (ctx.organization?.id) { + organizationId = ctx.organization.id; + } else { + throw new Error("Organization context is required"); + } + const config = await ctx.storage.projectPluginConfigs.get( projectId, pluginId, + organizationId, ); if (!config) { diff --git a/apps/mesh/src/tools/projects/plugin-config-update.ts b/apps/mesh/src/tools/projects/plugin-config-update.ts index bd3f85aec6..d39e206581 100644 --- a/apps/mesh/src/tools/projects/plugin-config-update.ts +++ b/apps/mesh/src/tools/projects/plugin-config-update.ts @@ -59,6 +59,14 @@ export const PROJECT_PLUGIN_CONFIG_UPDATE = defineTool({ throw new Error(`Project not found: ${projectId}`); } + let organizationId = null; + + if (ctx.organization?.id) { + organizationId = ctx.organization.id; + } else { + throw new Error("Organization context is required"); + } + const connectionExists = connectionId ? await ctx.storage.connections.findById(connectionId) : null; @@ -92,6 +100,7 @@ export const PROJECT_PLUGIN_CONFIG_UPDATE = defineTool({ connectionId, settings, }, + organizationId, ); return {