@theronap/cortex-mcp 0.9.41 → 0.9.42

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.
Files changed (2) hide show
  1. package/lib/server.mjs +59 -0
  2. package/package.json +1 -1
package/lib/server.mjs CHANGED
@@ -152,6 +152,65 @@ export async function runServer(version) {
152
152
  },
153
153
  )
154
154
 
155
+ // Pull/claim attribution ([[cortex-subscription-inference]]): the agent decides which project a
156
+ // messaging thread is about — on ITS subscription, zero server-metered inference — and records it
157
+ // here. The server stamps `project:<slug>` onto the thread's timeline events via the locked-down
158
+ // cortex_labeler role, so the thread threads onto that project's node timeline (retroactive @> join).
159
+ server.registerTool(
160
+ 'attribute_thread',
161
+ {
162
+ title: 'Attribute a messaging thread to a project',
163
+ description: "Record that a messaging thread (email, etc.) belongs to a project — stamps project:<slug> onto the thread's timeline events so its whole history threads onto that project's node timeline. Attribute AS YOU WORK: when you recognize which known project a thread you're looking at is about, attribute it. KNOWN projects only — if you're not confident, don't (a wrong tag pollutes a timeline; leaving it unattributed self-heals). Idempotent (safe to re-call) and reversible (remove:true undoes an attribution you made).",
164
+ inputSchema: {
165
+ threadKey: z.string().describe('the thread identifier — a Gmail threadId, or a full `thread:<id>` key'),
166
+ project: z.string().describe('the slug/key of the EXISTING project the thread belongs to'),
167
+ remove: z.boolean().optional().describe('true to REMOVE a project attribution you previously made (reversibility)'),
168
+ },
169
+ },
170
+ async ({ threadKey, project, remove }) => {
171
+ const res = await fetchCortex(`${BASE}/api/timeline/attribute`, {
172
+ method: 'POST',
173
+ headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
174
+ body: JSON.stringify({ threadKey, project, ...(remove ? { remove: true } : {}) }),
175
+ })
176
+ if (!res.ok) {
177
+ const body = await res.text()
178
+ throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
179
+ }
180
+ const j = await res.json().catch(() => ({}))
181
+ const verb = remove ? 'Removed' : 'Attributed'
182
+ const prep = remove ? 'from' : 'to'
183
+ return { content: [{ type: 'text', text: `${verb} ${j.threadKey ?? threadKey} ${prep} ${j.project ?? `project:${project}`} — ${j.stamped ?? 0} event(s) ${remove ? 'un' : ''}stamped.` }] }
184
+ },
185
+ )
186
+
187
+ // The PULL half: surface the org's unattributed messaging backlog so the agent can triage it and
188
+ // attribute the threads it recognizes (pairs with attribute_thread above).
189
+ server.registerTool(
190
+ 'timeline_pull',
191
+ {
192
+ title: 'Pull unattributed messaging threads to triage',
193
+ description: "Surface messaging threads captured in the org (email, etc.) that AREN'T yet attributed to a project — the backlog awaiting your judgment. Call it as you work; when you recognize which KNOWN project a surfaced thread is about, attribute it with attribute_thread. Threads you don't recognize: leave them (they self-heal as the graph fills). Returns participants + subject + recency per thread — enough to recognize, not the message bodies.",
194
+ inputSchema: { limit: z.number().optional().describe('max threads to return (default 20)') },
195
+ },
196
+ async ({ limit }) => {
197
+ const qs = typeof limit === 'number' ? `?limit=${limit}` : ''
198
+ const res = await fetchCortex(`${BASE}/api/timeline/pull${qs}`, { headers: { Authorization: `Bearer ${TOKEN}` } })
199
+ if (!res.ok) {
200
+ const body = await res.text()
201
+ throw new Error(classify(res.status, res.headers.get('content-type'), body, res.headers.get('x-vercel-id')).message)
202
+ }
203
+ const { threads } = await res.json()
204
+ if (!threads?.length) return { content: [{ type: 'text', text: 'No unattributed threads in the backlog.' }] }
205
+ const lines = threads.map((t) => {
206
+ const who = (t.participants ?? []).map((p) => String(p).replace(/^email:/, '')).join(', ')
207
+ const when = t.lastAt ? String(t.lastAt).slice(0, 10) : '—'
208
+ return `- ${t.threadKey} — ${t.subject ?? '(no subject)'} · ${who || 'unknown participants'} · ${t.eventCount} msg · ${when}`
209
+ })
210
+ return { content: [{ type: 'text', text: `Unattributed threads (${threads.length}) — attribute recognized ones with attribute_thread(threadKey, project):\n${lines.join('\n')}` }] }
211
+ },
212
+ )
213
+
155
214
  server.registerTool(
156
215
  'search_org',
157
216
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/cortex-mcp",
3
- "version": "0.9.41",
3
+ "version": "0.9.42",
4
4
  "description": "Connect your AI assistant to Cortex — your org's projects, activity, gaps, and directives, scoped to you.",
5
5
  "type": "module",
6
6
  "bin": {