@mpowr/nexus-mcp 0.5.0
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/README.md +59 -0
- package/dist/auth.d.ts +39 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +47 -0
- package/dist/auth.js.map +1 -0
- package/dist/nexus-api.d.ts +29 -0
- package/dist/nexus-api.d.ts.map +1 -0
- package/dist/nexus-api.js +76 -0
- package/dist/nexus-api.js.map +1 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +183 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/add-task-note.d.ts +34 -0
- package/dist/tools/add-task-note.d.ts.map +1 -0
- package/dist/tools/add-task-note.js +39 -0
- package/dist/tools/add-task-note.js.map +1 -0
- package/dist/tools/append-session-entry.d.ts +53 -0
- package/dist/tools/append-session-entry.d.ts.map +1 -0
- package/dist/tools/append-session-entry.js +67 -0
- package/dist/tools/append-session-entry.js.map +1 -0
- package/dist/tools/create-task.d.ts +52 -0
- package/dist/tools/create-task.d.ts.map +1 -0
- package/dist/tools/create-task.js +51 -0
- package/dist/tools/create-task.js.map +1 -0
- package/dist/tools/decision-comments.d.ts +54 -0
- package/dist/tools/decision-comments.d.ts.map +1 -0
- package/dist/tools/decision-comments.js +80 -0
- package/dist/tools/decision-comments.js.map +1 -0
- package/dist/tools/get-document.d.ts +47 -0
- package/dist/tools/get-document.d.ts.map +1 -0
- package/dist/tools/get-document.js +68 -0
- package/dist/tools/get-document.js.map +1 -0
- package/dist/tools/get-project-memory.d.ts +47 -0
- package/dist/tools/get-project-memory.d.ts.map +1 -0
- package/dist/tools/get-project-memory.js +53 -0
- package/dist/tools/get-project-memory.js.map +1 -0
- package/dist/tools/get-related-entities.d.ts +44 -0
- package/dist/tools/get-related-entities.d.ts.map +1 -0
- package/dist/tools/get-related-entities.js +60 -0
- package/dist/tools/get-related-entities.js.map +1 -0
- package/dist/tools/governance.d.ts +90 -0
- package/dist/tools/governance.d.ts.map +1 -0
- package/dist/tools/governance.js +124 -0
- package/dist/tools/governance.js.map +1 -0
- package/dist/tools/ingest-document.d.ts +40 -0
- package/dist/tools/ingest-document.d.ts.map +1 -0
- package/dist/tools/ingest-document.js +48 -0
- package/dist/tools/ingest-document.js.map +1 -0
- package/dist/tools/letter-inbox.d.ts +80 -0
- package/dist/tools/letter-inbox.d.ts.map +1 -0
- package/dist/tools/letter-inbox.js +118 -0
- package/dist/tools/letter-inbox.js.map +1 -0
- package/dist/tools/letters.d.ts +91 -0
- package/dist/tools/letters.d.ts.map +1 -0
- package/dist/tools/letters.js +112 -0
- package/dist/tools/letters.js.map +1 -0
- package/dist/tools/project-list.d.ts +28 -0
- package/dist/tools/project-list.d.ts.map +1 -0
- package/dist/tools/project-list.js +43 -0
- package/dist/tools/project-list.js.map +1 -0
- package/dist/tools/reviews.d.ts +145 -0
- package/dist/tools/reviews.d.ts.map +1 -0
- package/dist/tools/reviews.js +216 -0
- package/dist/tools/reviews.js.map +1 -0
- package/dist/tools/search-knowledge.d.ts +48 -0
- package/dist/tools/search-knowledge.d.ts.map +1 -0
- package/dist/tools/search-knowledge.js +54 -0
- package/dist/tools/search-knowledge.js.map +1 -0
- package/dist/tools/sessions.d.ts +81 -0
- package/dist/tools/sessions.d.ts.map +1 -0
- package/dist/tools/sessions.js +120 -0
- package/dist/tools/sessions.js.map +1 -0
- package/dist/tools/skill-assign.d.ts +77 -0
- package/dist/tools/skill-assign.d.ts.map +1 -0
- package/dist/tools/skill-assign.js +108 -0
- package/dist/tools/skill-assign.js.map +1 -0
- package/dist/tools/skills.d.ts +138 -0
- package/dist/tools/skills.d.ts.map +1 -0
- package/dist/tools/skills.js +192 -0
- package/dist/tools/skills.js.map +1 -0
- package/dist/tools/update-task-status.d.ts +48 -0
- package/dist/tools/update-task-status.d.ts.map +1 -0
- package/dist/tools/update-task-status.js +51 -0
- package/dist/tools/update-task-status.js.map +1 -0
- package/package.json +30 -0
- package/src/__tests__/auth.test.ts +162 -0
- package/src/__tests__/decision-comments.test.ts +173 -0
- package/src/__tests__/helpers.ts +58 -0
- package/src/__tests__/layer1-knowledge.test.ts +302 -0
- package/src/__tests__/layer2-coordination.test.ts +775 -0
- package/src/__tests__/layer3-governance.test.ts +205 -0
- package/src/__tests__/project-list-and-skill-assign.test.ts +282 -0
- package/src/__tests__/reviews.test.ts +420 -0
- package/src/__tests__/server.test.ts +238 -0
- package/src/__tests__/setup.ts +15 -0
- package/src/auth.ts +81 -0
- package/src/nexus-api.ts +110 -0
- package/src/server.ts +499 -0
- package/src/tools/add-task-note.ts +50 -0
- package/src/tools/append-session-entry.ts +83 -0
- package/src/tools/create-task.ts +66 -0
- package/src/tools/decision-comments.ts +102 -0
- package/src/tools/get-document.ts +80 -0
- package/src/tools/get-project-memory.ts +65 -0
- package/src/tools/get-related-entities.ts +73 -0
- package/src/tools/governance.ts +162 -0
- package/src/tools/ingest-document.ts +64 -0
- package/src/tools/letter-inbox.ts +157 -0
- package/src/tools/letters.ts +144 -0
- package/src/tools/project-list.ts +52 -0
- package/src/tools/reviews.ts +277 -0
- package/src/tools/search-knowledge.ts +68 -0
- package/src/tools/sessions.ts +154 -0
- package/src/tools/skill-assign.ts +142 -0
- package/src/tools/skills.ts +252 -0
- package/src/tools/update-task-status.ts +64 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +8 -0
package/src/auth.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Authentication Layer
|
|
3
|
+
*
|
|
4
|
+
* Resolves the NEXUS_PRIVATE_TOKEN environment variable at server startup
|
|
5
|
+
* to a verified user identity by calling the Nexus API identity endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. Read NEXUS_PRIVATE_TOKEN from process.env
|
|
9
|
+
* 2. Call GET /api/mcp/identity with Bearer token
|
|
10
|
+
* 3. Cache resolved identity for the lifetime of the MCP process
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { nexusGet } from './nexus-api.js'
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Types
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
export interface McpIdentity {
|
|
20
|
+
userId: string
|
|
21
|
+
email: string | null
|
|
22
|
+
displayName: string | null
|
|
23
|
+
isPlatformAdmin: boolean
|
|
24
|
+
isPlatformOwner: boolean
|
|
25
|
+
tenantId: string | null
|
|
26
|
+
memberships: Array<{ project_id: string; role: string }>
|
|
27
|
+
agentAssignments: Array<{
|
|
28
|
+
project_id: string
|
|
29
|
+
agent_id: string
|
|
30
|
+
agent_owner: string
|
|
31
|
+
}>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Module-level cache: resolved once at startup
|
|
35
|
+
let _identity: McpIdentity | null = null
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Public API
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the MCP server identity from NEXUS_PRIVATE_TOKEN.
|
|
43
|
+
* Called once at server startup. Caches the result.
|
|
44
|
+
* Throws if no valid token is available.
|
|
45
|
+
*/
|
|
46
|
+
export async function initIdentity(): Promise<McpIdentity> {
|
|
47
|
+
if (_identity) return _identity
|
|
48
|
+
|
|
49
|
+
const rawToken = process.env.NEXUS_PRIVATE_TOKEN
|
|
50
|
+
if (!rawToken) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'MCP: NEXUS_PRIVATE_TOKEN is not set. The MCP server requires a valid nxs_pat_* token.',
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const result = await nexusGet<McpIdentity>('/api/mcp/identity')
|
|
57
|
+
|
|
58
|
+
if (!result.ok || !result.data) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`MCP: Identity resolution failed: ${result.error ?? 'Unknown error'}. Check that the token is valid, not expired, and not revoked.`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_identity = result.data
|
|
65
|
+
|
|
66
|
+
console.error(
|
|
67
|
+
`[nexus-mcp] Identity resolved: ${_identity.displayName ?? _identity.email ?? _identity.userId} (admin=${_identity.isPlatformAdmin}, owner=${_identity.isPlatformOwner})`,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return _identity
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get the cached MCP identity. Must call initIdentity() first.
|
|
75
|
+
*/
|
|
76
|
+
export function getIdentity(): McpIdentity {
|
|
77
|
+
if (!_identity) {
|
|
78
|
+
throw new Error('MCP: Identity not initialized. Call initIdentity() first.')
|
|
79
|
+
}
|
|
80
|
+
return _identity
|
|
81
|
+
}
|
package/src/nexus-api.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nexus API client for MCP server context.
|
|
3
|
+
*
|
|
4
|
+
* Replaces direct Supabase access with HTTP calls to the Nexus API.
|
|
5
|
+
* All operations go through /api/mcp/* endpoints, authenticated
|
|
6
|
+
* via the NEXUS_PRIVATE_TOKEN (nxs_pat_*) Bearer token.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
let _baseUrl: string | null = null
|
|
10
|
+
let _token: string | null = null
|
|
11
|
+
|
|
12
|
+
function getConfig(): { baseUrl: string; token: string } {
|
|
13
|
+
if (_baseUrl && _token) return { baseUrl: _baseUrl, token: _token }
|
|
14
|
+
|
|
15
|
+
const url = process.env.NEXUS_API_URL ?? process.env.NEXUS_URL
|
|
16
|
+
const token = process.env.NEXUS_PRIVATE_TOKEN
|
|
17
|
+
|
|
18
|
+
if (!url) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'MCP: Missing NEXUS_API_URL. Set the base URL of the Nexus app (e.g. https://nexus.mpowr.tech).',
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
if (!token) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
'MCP: Missing NEXUS_PRIVATE_TOKEN. The MCP server requires a valid nxs_pat_* token.',
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Normalize: strip trailing slash
|
|
30
|
+
_baseUrl = url.replace(/\/$/, '')
|
|
31
|
+
_token = token.trim()
|
|
32
|
+
|
|
33
|
+
return { baseUrl: _baseUrl, token: _token }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface NexusApiResponse<T = unknown> {
|
|
37
|
+
ok: boolean
|
|
38
|
+
status: number
|
|
39
|
+
data: T | null
|
|
40
|
+
error: string | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Make an authenticated request to the Nexus API.
|
|
45
|
+
*/
|
|
46
|
+
export async function nexusApi<T = unknown>(
|
|
47
|
+
path: string,
|
|
48
|
+
options: {
|
|
49
|
+
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE'
|
|
50
|
+
body?: unknown
|
|
51
|
+
} = {},
|
|
52
|
+
): Promise<NexusApiResponse<T>> {
|
|
53
|
+
const { baseUrl, token } = getConfig()
|
|
54
|
+
const method = options.method ?? 'GET'
|
|
55
|
+
const url = `${baseUrl}${path}`
|
|
56
|
+
|
|
57
|
+
const headers: Record<string, string> = {
|
|
58
|
+
Authorization: `Bearer ${token}`,
|
|
59
|
+
'Content-Type': 'application/json',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const fetchOpts: RequestInit = { method, headers }
|
|
64
|
+
if (options.body !== undefined) {
|
|
65
|
+
fetchOpts.body = JSON.stringify(options.body)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const response = await fetch(url, fetchOpts)
|
|
69
|
+
const data = (await response.json()) as T & { error?: string }
|
|
70
|
+
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
status: response.status,
|
|
75
|
+
data: null,
|
|
76
|
+
error:
|
|
77
|
+
(data as Record<string, unknown>)?.error as string ??
|
|
78
|
+
`HTTP ${response.status}`,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { ok: true, status: response.status, data, error: null }
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
status: 0,
|
|
87
|
+
data: null,
|
|
88
|
+
error: err instanceof Error ? err.message : 'Unknown fetch error',
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Convenience: POST to a Nexus MCP endpoint.
|
|
95
|
+
*/
|
|
96
|
+
export async function nexusPost<T = unknown>(
|
|
97
|
+
path: string,
|
|
98
|
+
body: unknown,
|
|
99
|
+
): Promise<NexusApiResponse<T>> {
|
|
100
|
+
return nexusApi<T>(path, { method: 'POST', body })
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Convenience: GET from a Nexus MCP endpoint.
|
|
105
|
+
*/
|
|
106
|
+
export async function nexusGet<T = unknown>(
|
|
107
|
+
path: string,
|
|
108
|
+
): Promise<NexusApiResponse<T>> {
|
|
109
|
+
return nexusApi<T>(path, { method: 'GET' })
|
|
110
|
+
}
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* nexus-mcp -- MCP Server for mpowr-nexus
|
|
4
|
+
*
|
|
5
|
+
* Provides Knowledge Access (Layer 1), Coordination (Layer 2),
|
|
6
|
+
* Governance (Layer 3), and Reviews (Layer 4) tools.
|
|
7
|
+
* Runs as a standalone stdio MCP server.
|
|
8
|
+
*
|
|
9
|
+
* Authentication:
|
|
10
|
+
* Identity is resolved once at startup from NEXUS_PRIVATE_TOKEN (nxs_pat_*).
|
|
11
|
+
* All write tools receive user_id automatically from the resolved identity.
|
|
12
|
+
* Callers no longer pass user_id as a parameter.
|
|
13
|
+
*
|
|
14
|
+
* Layer 1 - Knowledge Access:
|
|
15
|
+
* - kb_search: Search project knowledge (keyword/semantic/hybrid)
|
|
16
|
+
* - kb_memory: Curated project context for agent bootstrapping
|
|
17
|
+
* - kb_get: Fetch a single knowledge object
|
|
18
|
+
* - kb_related: Navigate entity relationships
|
|
19
|
+
* - project_list: List accessible projects
|
|
20
|
+
*
|
|
21
|
+
* Layer 2 - Coordination:
|
|
22
|
+
* - vl_create: Create a new vault letter
|
|
23
|
+
* - vl_reply: Reply to an existing vault letter
|
|
24
|
+
* - vl_inbox: List letters addressed to the calling agent/user
|
|
25
|
+
* - vl_outbox: List letters sent by the calling agent/user
|
|
26
|
+
* - vl_ack: Acknowledge receipt of a new vault letter
|
|
27
|
+
* - task_create: Create a task in a project
|
|
28
|
+
* - task_update: Update task status, priority, or assignee
|
|
29
|
+
* - task_note: Append a note to a task (append-only)
|
|
30
|
+
* - dc_add: Add a comment to an ADR (append-only)
|
|
31
|
+
* - dc_list: List comments for an ADR
|
|
32
|
+
* - sk_list: List skills for the current tenant
|
|
33
|
+
* - sk_get: Get full skill content by identifier
|
|
34
|
+
* - sk_create: Create a new skill in draft status
|
|
35
|
+
* - sk_update: Update skill content or metadata
|
|
36
|
+
* - sk_activate: Change skill status (draft/active/archived)
|
|
37
|
+
* - sk_assign: Assign a skill to a project
|
|
38
|
+
* - sk_unassign: Remove a skill assignment from a project
|
|
39
|
+
* - sk_export: Export all skill assignments for a project
|
|
40
|
+
* - doc_ingest: Push text/markdown content into project knowledge base
|
|
41
|
+
* - session_append: Append to a session (write-isolated)
|
|
42
|
+
* - session_create: Start a new work session
|
|
43
|
+
* - session_close: End a session with summary and next entry point
|
|
44
|
+
* - session_list: List open sessions for a project
|
|
45
|
+
*
|
|
46
|
+
* Layer 3 - Governance:
|
|
47
|
+
* - adr_create: Create a new ADR draft
|
|
48
|
+
* - adr_submit: Submit an ADR for review
|
|
49
|
+
* - adr_decide: Accept or reject an ADR
|
|
50
|
+
*
|
|
51
|
+
* Layer 4 - Reviews:
|
|
52
|
+
* - rv_list: List reviews with optional filters
|
|
53
|
+
* - rv_get: Get a review by ID or entity reference
|
|
54
|
+
* - rv_create: Create a new review for an entity
|
|
55
|
+
* - rv_decide: Transition a review state
|
|
56
|
+
* - rv_comment: Add a comment to a review
|
|
57
|
+
*
|
|
58
|
+
* Usage:
|
|
59
|
+
* npx tsx src/mcp/server.ts
|
|
60
|
+
*
|
|
61
|
+
* Or via .mcp.json configuration:
|
|
62
|
+
* { "command": "npx", "args": ["tsx", "src/mcp/server.ts"] }
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
66
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
67
|
+
|
|
68
|
+
import { getIdentity, initIdentity } from './auth.js'
|
|
69
|
+
|
|
70
|
+
// Layer 1: Knowledge Access
|
|
71
|
+
import { projectList, projectListSchema } from './tools/project-list.js'
|
|
72
|
+
import { getDocument, getDocumentSchema } from './tools/get-document.js'
|
|
73
|
+
import {
|
|
74
|
+
getProjectMemory,
|
|
75
|
+
getProjectMemorySchema,
|
|
76
|
+
} from './tools/get-project-memory.js'
|
|
77
|
+
import {
|
|
78
|
+
getRelatedEntities,
|
|
79
|
+
getRelatedEntitiesSchema,
|
|
80
|
+
} from './tools/get-related-entities.js'
|
|
81
|
+
import {
|
|
82
|
+
searchKnowledge,
|
|
83
|
+
searchKnowledgeSchema,
|
|
84
|
+
} from './tools/search-knowledge.js'
|
|
85
|
+
|
|
86
|
+
// Layer 2: Coordination
|
|
87
|
+
import { addTaskNote, addTaskNoteSchema } from './tools/add-task-note.js'
|
|
88
|
+
import {
|
|
89
|
+
appendSessionEntry,
|
|
90
|
+
appendSessionEntrySchema,
|
|
91
|
+
} from './tools/append-session-entry.js'
|
|
92
|
+
import { createTask, createTaskSchema } from './tools/create-task.js'
|
|
93
|
+
import {
|
|
94
|
+
addDecisionComment,
|
|
95
|
+
addDecisionCommentSchema,
|
|
96
|
+
listDecisionComments,
|
|
97
|
+
listDecisionCommentsSchema,
|
|
98
|
+
} from './tools/decision-comments.js'
|
|
99
|
+
import {
|
|
100
|
+
ingestDocument,
|
|
101
|
+
ingestDocumentSchema,
|
|
102
|
+
} from './tools/ingest-document.js'
|
|
103
|
+
import {
|
|
104
|
+
acknowledgeLetter,
|
|
105
|
+
acknowledgeLetterSchema,
|
|
106
|
+
listInbox,
|
|
107
|
+
listInboxSchema,
|
|
108
|
+
listOutbox,
|
|
109
|
+
listOutboxSchema,
|
|
110
|
+
} from './tools/letter-inbox.js'
|
|
111
|
+
import {
|
|
112
|
+
createLetter,
|
|
113
|
+
createLetterSchema,
|
|
114
|
+
replyLetter,
|
|
115
|
+
replyLetterSchema,
|
|
116
|
+
} from './tools/letters.js'
|
|
117
|
+
import {
|
|
118
|
+
closeSession,
|
|
119
|
+
closeSessionSchema,
|
|
120
|
+
createSession,
|
|
121
|
+
createSessionSchema,
|
|
122
|
+
listOpenSessions,
|
|
123
|
+
listOpenSessionsSchema,
|
|
124
|
+
} from './tools/sessions.js'
|
|
125
|
+
import {
|
|
126
|
+
skActivate,
|
|
127
|
+
skActivateSchema,
|
|
128
|
+
skCreate,
|
|
129
|
+
skCreateSchema,
|
|
130
|
+
skGet,
|
|
131
|
+
skGetSchema,
|
|
132
|
+
skList,
|
|
133
|
+
skListSchema,
|
|
134
|
+
skUpdate,
|
|
135
|
+
skUpdateSchema,
|
|
136
|
+
} from './tools/skills.js'
|
|
137
|
+
import {
|
|
138
|
+
skAssign,
|
|
139
|
+
skAssignSchema,
|
|
140
|
+
skExport,
|
|
141
|
+
skExportSchema,
|
|
142
|
+
skUnassign,
|
|
143
|
+
skUnassignSchema,
|
|
144
|
+
} from './tools/skill-assign.js'
|
|
145
|
+
import {
|
|
146
|
+
updateTaskStatus,
|
|
147
|
+
updateTaskStatusSchema,
|
|
148
|
+
} from './tools/update-task-status.js'
|
|
149
|
+
|
|
150
|
+
// Layer 3: Governance
|
|
151
|
+
import {
|
|
152
|
+
createAdrDraft,
|
|
153
|
+
createAdrDraftSchema,
|
|
154
|
+
recordAdrDecision,
|
|
155
|
+
recordAdrDecisionSchema,
|
|
156
|
+
submitAdrReview,
|
|
157
|
+
submitAdrReviewSchema,
|
|
158
|
+
} from './tools/governance.js'
|
|
159
|
+
|
|
160
|
+
// Layer 4: Reviews
|
|
161
|
+
import {
|
|
162
|
+
rvComment,
|
|
163
|
+
rvCommentSchema,
|
|
164
|
+
rvCreate,
|
|
165
|
+
rvCreateSchema,
|
|
166
|
+
rvDecide,
|
|
167
|
+
rvDecideSchema,
|
|
168
|
+
rvGet,
|
|
169
|
+
rvGetSchema,
|
|
170
|
+
rvList,
|
|
171
|
+
rvListSchema,
|
|
172
|
+
} from './tools/reviews.js'
|
|
173
|
+
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// Identity injection helper
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Wrap a write-tool handler to inject user_id from the resolved identity.
|
|
180
|
+
* The caller does not need to pass user_id — it comes from the token.
|
|
181
|
+
*/
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
|
+
function withIdentity(handler: (args: any) => Promise<any>) {
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
+
return async (args: any) => {
|
|
186
|
+
const identity = getIdentity()
|
|
187
|
+
return handler({ ...args, user_id: identity.userId })
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Server setup
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
const server = new McpServer(
|
|
196
|
+
{
|
|
197
|
+
name: 'nexus-mcp',
|
|
198
|
+
version: '0.5.0',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
capabilities: {
|
|
202
|
+
tools: {},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Layer 1: Knowledge Access tools
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
server.tool(
|
|
212
|
+
'kb_search',
|
|
213
|
+
'Search project knowledge using keyword, semantic, or hybrid mode. Applies project scope filters before retrieval. Returns matching entities with relevance ranking.',
|
|
214
|
+
searchKnowledgeSchema,
|
|
215
|
+
async (args) => searchKnowledge(args),
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
server.tool(
|
|
219
|
+
'kb_memory',
|
|
220
|
+
'Get curated project context for agent bootstrapping. Returns ADRs, active tasks, recent sessions, open letters, and other project knowledge based on selected categories and depth.',
|
|
221
|
+
getProjectMemorySchema,
|
|
222
|
+
async (args) => getProjectMemory(args),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
server.tool(
|
|
226
|
+
'kb_get',
|
|
227
|
+
'Fetch a single knowledge object (session, decision, letter, task, etc.) in structured, markdown, or summary format. Includes child entries for sessions and letters.',
|
|
228
|
+
getDocumentSchema,
|
|
229
|
+
async (args) => getDocument(args),
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
server.tool(
|
|
233
|
+
'kb_related',
|
|
234
|
+
'Navigate entity relationships. Returns graph-neighbor entities related to a given item, such as supersession chains for ADRs, thread siblings for letters, or tasks created during sessions.',
|
|
235
|
+
getRelatedEntitiesSchema,
|
|
236
|
+
async (args) => getRelatedEntities(args),
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
server.tool(
|
|
240
|
+
'project_list',
|
|
241
|
+
'List accessible projects for the authenticated user or agent. Returns project metadata ordered by name.',
|
|
242
|
+
projectListSchema,
|
|
243
|
+
async (args) => projectList(args),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
// Layer 2: Coordination tools
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
server.tool(
|
|
251
|
+
'vl_create',
|
|
252
|
+
'Create a new vault letter for agent-to-agent or agent-to-human coordination. Returns the new letter ID and status.',
|
|
253
|
+
createLetterSchema,
|
|
254
|
+
withIdentity(createLetter),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
server.tool(
|
|
258
|
+
'vl_reply',
|
|
259
|
+
'Reply to an existing vault letter with a new message. Optionally update the letter status. Enforces append-only semantics.',
|
|
260
|
+
replyLetterSchema,
|
|
261
|
+
withIdentity(replyLetter),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
server.tool(
|
|
265
|
+
'vl_inbox',
|
|
266
|
+
'List vault letters addressed to the calling agent or user. Returns letters scoped to the given project, ordered by blocking status and recency. Supports status filtering.',
|
|
267
|
+
listInboxSchema,
|
|
268
|
+
withIdentity(listInbox),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
server.tool(
|
|
272
|
+
'vl_outbox',
|
|
273
|
+
'List vault letters sent by the calling agent or user. Returns letters scoped to the given project, ordered by recency. Supports status filtering.',
|
|
274
|
+
listOutboxSchema,
|
|
275
|
+
withIdentity(listOutbox),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
server.tool(
|
|
279
|
+
'vl_ack',
|
|
280
|
+
'Acknowledge receipt of a new vault letter. Transitions the letter from new to acknowledged status and appends an acknowledgment message.',
|
|
281
|
+
acknowledgeLetterSchema,
|
|
282
|
+
withIdentity(acknowledgeLetter),
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
server.tool(
|
|
286
|
+
'task_create',
|
|
287
|
+
'Create a new task within a project scope. Returns the new task ID.',
|
|
288
|
+
createTaskSchema,
|
|
289
|
+
withIdentity(createTask),
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
server.tool(
|
|
293
|
+
'task_update',
|
|
294
|
+
'Update the status of an existing task. Optionally change priority or assignee. Automatically records a status-change note for audit trail.',
|
|
295
|
+
updateTaskStatusSchema,
|
|
296
|
+
withIdentity(updateTaskStatus),
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
server.tool(
|
|
300
|
+
'task_note',
|
|
301
|
+
'Append a note to an existing task. Notes are append-only and maintain a chronological audit trail. Useful for recording progress, blockers, or decisions.',
|
|
302
|
+
addTaskNoteSchema,
|
|
303
|
+
withIdentity(addTaskNote),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
server.tool(
|
|
307
|
+
'doc_ingest',
|
|
308
|
+
'Push text or markdown content into a project knowledge base. Creates an ingest item that can later be classified. Useful for agents to persist research results, generated documents, or extracted knowledge.',
|
|
309
|
+
ingestDocumentSchema,
|
|
310
|
+
withIdentity(ingestDocument),
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
server.tool(
|
|
314
|
+
'session_append',
|
|
315
|
+
'Append an entry to an existing session. Enforces session write isolation: only the session creator can append entries.',
|
|
316
|
+
appendSessionEntrySchema,
|
|
317
|
+
withIdentity(appendSessionEntry),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
server.tool(
|
|
321
|
+
'session_create',
|
|
322
|
+
'Create a new work session for a project. Returns the session ID. The session starts in open status and must be closed explicitly via session_close.',
|
|
323
|
+
createSessionSchema,
|
|
324
|
+
withIdentity(createSession),
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
server.tool(
|
|
328
|
+
'session_close',
|
|
329
|
+
'Close an open session. Sets status to closed, optionally records a summary and next entry point. Only the session creator can close it.',
|
|
330
|
+
closeSessionSchema,
|
|
331
|
+
withIdentity(closeSession),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
server.tool(
|
|
335
|
+
'session_list',
|
|
336
|
+
'List open sessions for a project. Returns sessions ordered by creation date (newest first). Useful for checking active work before starting a new session.',
|
|
337
|
+
listOpenSessionsSchema,
|
|
338
|
+
async (args) => listOpenSessions(args),
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// Layer 2 (continued): Decision comment tools
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
|
|
345
|
+
server.tool(
|
|
346
|
+
'dc_add',
|
|
347
|
+
'Add a comment to an ADR decision. Comments are append-only and support both human and agent actors.',
|
|
348
|
+
addDecisionCommentSchema,
|
|
349
|
+
withIdentity(addDecisionComment),
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
server.tool(
|
|
353
|
+
'dc_list',
|
|
354
|
+
'List comments for an ADR decision in chronological order.',
|
|
355
|
+
listDecisionCommentsSchema,
|
|
356
|
+
async (args) => listDecisionComments(args),
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
360
|
+
// Layer 2 (continued): Skill management tools
|
|
361
|
+
// ---------------------------------------------------------------------------
|
|
362
|
+
|
|
363
|
+
server.tool(
|
|
364
|
+
'sk_list',
|
|
365
|
+
'List skills for the current tenant. Supports status filtering (draft, active, archived). Returns skill metadata without full body content.',
|
|
366
|
+
skListSchema,
|
|
367
|
+
withIdentity(skList),
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
server.tool(
|
|
371
|
+
'sk_get',
|
|
372
|
+
'Get full skill content by skill identifier or UUID. Includes associated command information.',
|
|
373
|
+
skGetSchema,
|
|
374
|
+
withIdentity(skGet),
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
server.tool(
|
|
378
|
+
'sk_create',
|
|
379
|
+
'Create a new skill in draft status. Optionally auto-generates an OpenCode command. Skill content is markdown-based instruction text.',
|
|
380
|
+
skCreateSchema,
|
|
381
|
+
withIdentity(skCreate),
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
server.tool(
|
|
385
|
+
'sk_update',
|
|
386
|
+
'Update an existing skill content, metadata, or command auto-generation setting. Increments version when body changes.',
|
|
387
|
+
skUpdateSchema,
|
|
388
|
+
withIdentity(skUpdate),
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
server.tool(
|
|
392
|
+
'sk_activate',
|
|
393
|
+
'Change a skill status (draft, active, archived). Active skills are available for agent loading and project selection.',
|
|
394
|
+
skActivateSchema,
|
|
395
|
+
withIdentity(skActivate),
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
server.tool(
|
|
399
|
+
'sk_assign',
|
|
400
|
+
'Assign a skill to a project. Optionally pin to a specific version and set enabled state.',
|
|
401
|
+
skAssignSchema,
|
|
402
|
+
withIdentity(skAssign),
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
server.tool(
|
|
406
|
+
'sk_unassign',
|
|
407
|
+
'Remove a skill assignment from a project.',
|
|
408
|
+
skUnassignSchema,
|
|
409
|
+
withIdentity(skUnassign),
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
server.tool(
|
|
413
|
+
'sk_export',
|
|
414
|
+
'Export all skill assignments for a project. Returns the full assignment list with pinned versions and enabled states.',
|
|
415
|
+
skExportSchema,
|
|
416
|
+
withIdentity(skExport),
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
// Layer 3: Governance tools
|
|
421
|
+
// ---------------------------------------------------------------------------
|
|
422
|
+
|
|
423
|
+
server.tool(
|
|
424
|
+
'adr_create',
|
|
425
|
+
'Create a new ADR (Architecture Decision Record) in draft state. Auto-assigns the next ADR number for the project. Optionally links to a superseded ADR.',
|
|
426
|
+
createAdrDraftSchema,
|
|
427
|
+
withIdentity(createAdrDraft),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
server.tool(
|
|
431
|
+
'adr_submit',
|
|
432
|
+
'Submit an ADR for review. Transitions an ADR from draft to under_review state. Only drafts can be submitted.',
|
|
433
|
+
submitAdrReviewSchema,
|
|
434
|
+
withIdentity(submitAdrReview),
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
server.tool(
|
|
438
|
+
'adr_decide',
|
|
439
|
+
'Accept or reject an ADR that is under review. If accepted and it supersedes another ADR, the superseded ADR is automatically marked. Optional rationale is appended to the ADR body.',
|
|
440
|
+
recordAdrDecisionSchema,
|
|
441
|
+
withIdentity(recordAdrDecision),
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
// ---------------------------------------------------------------------------
|
|
445
|
+
// Layer 4: Review tools
|
|
446
|
+
// ---------------------------------------------------------------------------
|
|
447
|
+
|
|
448
|
+
server.tool(
|
|
449
|
+
'rv_list',
|
|
450
|
+
'List reviews with optional filters by entity type and status. Returns reviews ordered by recency.',
|
|
451
|
+
rvListSchema,
|
|
452
|
+
withIdentity(rvList),
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
server.tool(
|
|
456
|
+
'rv_get',
|
|
457
|
+
'Get a review by review ID, or by entity type and entity ID. Returns full review details including status and history.',
|
|
458
|
+
rvGetSchema,
|
|
459
|
+
withIdentity(rvGet),
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
server.tool(
|
|
463
|
+
'rv_create',
|
|
464
|
+
'Create a new review for a skill or agent entity. Returns the new review ID and initial status.',
|
|
465
|
+
rvCreateSchema,
|
|
466
|
+
withIdentity(rvCreate),
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
server.tool(
|
|
470
|
+
'rv_decide',
|
|
471
|
+
'Transition a review state (submit, accept, reject, request_revision, resubmit, archive). Enforces valid state transitions. Optional rationale is recorded.',
|
|
472
|
+
rvDecideSchema,
|
|
473
|
+
withIdentity(rvDecide),
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
server.tool(
|
|
477
|
+
'rv_comment',
|
|
478
|
+
'Add a comment to a review. Supports inline comments with optional line range. Comments are append-only and maintain a chronological audit trail.',
|
|
479
|
+
rvCommentSchema,
|
|
480
|
+
withIdentity(rvComment),
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
// ---------------------------------------------------------------------------
|
|
484
|
+
// Start
|
|
485
|
+
// ---------------------------------------------------------------------------
|
|
486
|
+
|
|
487
|
+
async function main() {
|
|
488
|
+
// Resolve identity from NEXUS_PRIVATE_TOKEN before accepting connections
|
|
489
|
+
await initIdentity()
|
|
490
|
+
|
|
491
|
+
const transport = new StdioServerTransport()
|
|
492
|
+
await server.connect(transport)
|
|
493
|
+
console.error('[nexus-mcp] Server started on stdio')
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
main().catch((err) => {
|
|
497
|
+
console.error('[nexus-mcp] Fatal error:', err)
|
|
498
|
+
process.exit(1)
|
|
499
|
+
})
|