@rigstate/mcp 0.7.8 → 0.7.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rigstate/mcp",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "Rigstate MCP Server - Model Context Protocol for AI Editors",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,13 +23,16 @@ Useful for understanding the strategic context and major milestones.`,
23
23
  let source = 'DB';
24
24
 
25
25
  try {
26
- // Try secure gateway for project
27
- const { data } = await supabase
26
+ // 1. Try secure gateway for project context
27
+ const { data, error } = await supabase
28
28
  .rpc('get_project_context_secure', { p_project_id: projectId, p_user_id: userId })
29
- .single() as any;
29
+ .single();
30
+
31
+ if (error || !data) throw error || new Error('Project not found');
30
32
  projectRow = data;
31
33
  } catch (e) {
32
- // Fallback
34
+ console.error('[list_features] Secure Project RPC failed:', e);
35
+ // Fallback: Direct table query (Requires proper RLS)
33
36
  const { data } = await supabase.from('projects').select('id, functional_spec').eq('id', projectId).single();
34
37
  projectRow = data;
35
38
  }
@@ -73,18 +73,21 @@ export async function saveToProjectBrain(
73
73
  p_tags: tags || [],
74
74
  p_importance: (category === 'DECISION' || category === 'ARCHITECTURE') ? 9 : 5
75
75
  });
76
- if (data && !error) {
77
- memoryId = data;
78
- } else {
76
+
77
+ if (error) {
78
+ console.error('[save_to_project_brain] RPC Error:', error);
79
79
  saveError = error;
80
+ } else if (data) {
81
+ memoryId = data;
80
82
  }
81
83
  } catch (e) {
84
+ console.error('[save_to_project_brain] RPC Exception:', e);
82
85
  saveError = e;
83
86
  }
84
87
 
85
- // 2. Fallback to direct insert (RLS was updated to allow members)
88
+ // 2. Fallback to direct insert (Requires proper RLS)
86
89
  if (!memoryId) {
87
- console.warn('RPC save_project_memory_secure failed, trying direct insert. Error:', saveError);
90
+ console.warn('[save_to_project_brain] Falling back to direct insert. RPC Error/Response was:', saveError);
88
91
  const { data, error } = await supabase
89
92
  .from('project_memories')
90
93
  .insert({
@@ -100,10 +103,11 @@ export async function saveToProjectBrain(
100
103
  .single();
101
104
 
102
105
  if (data) {
103
- memoryId = data.id;
106
+ memoryId = (data as any).id;
104
107
  } else {
105
- console.error('Direct insert failed:', error);
106
- throw new Error(`Failed to save memory: ${error?.message || 'Unknown error'}`);
108
+ console.error('[save_to_project_brain] Direct insert failed:', error);
109
+ const detail = error?.message || (saveError as any)?.message || 'Unknown error';
110
+ throw new Error(`Failed to save memory: ${detail}. (Note: secure RPC failed first)`);
107
111
  }
108
112
  }
109
113
 
@@ -75,18 +75,26 @@ export async function queryBrain(
75
75
  }
76
76
  }
77
77
 
78
- // Related Features from Spec
78
+ // 3. Related Features from Spec (Use Secure Gateway)
79
79
  let relevantFeatures: any[] = [];
80
80
  try {
81
- const { data: projectRow } = await supabase.from('projects').select('functional_spec').eq('id', projectId).single();
81
+ const { data: projectRow } = await supabase
82
+ .rpc('get_project_context_secure', { p_project_id: projectId, p_user_id: userId })
83
+ .single() as any;
84
+
82
85
  if (projectRow?.functional_spec) {
83
- const spec = projectRow.functional_spec as any;
86
+ const spec = typeof projectRow.functional_spec === 'string'
87
+ ? JSON.parse(projectRow.functional_spec)
88
+ : projectRow.functional_spec;
89
+
84
90
  const features = spec.featureList || spec.features || [];
85
91
  relevantFeatures = features
86
92
  .filter((f: any) => (f.name || f.title)?.toLowerCase().includes(query.toLowerCase()))
87
93
  .slice(0, 3);
88
94
  }
89
- } catch (e) { }
95
+ } catch (e) {
96
+ console.error('[query_brain] Failed to fetch project spec for features:', e);
97
+ }
90
98
 
91
99
  const contextLines = memories.map((m: any) => `- [${(m.category || 'GENERAL').toUpperCase()}]: ${m.content}`);
92
100
  let formatted = `=== PROJECT BRAIN: RELEVANT MEMORIES ===\nSearch Mode: ${searchType}\nQuery: "${query}"`;