@lucern/mcp 0.2.0-alpha.1 → 0.2.0-alpha.3
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/dist/gateway.d.ts +771 -0
- package/dist/gateway.js +9545 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +307 -0
- package/dist/index.js +3009 -1303
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +111 -0
- package/dist/runtime.js +6244 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +19 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { McpToolContract, GatewayClientConfig, MCP_TOOL_CONTRACTS } from '@lucern/sdk';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
+
import { ConvexHttpClient } from 'convex/browser';
|
|
6
|
+
|
|
7
|
+
type ObservationKind = "claim" | "evidence" | "question" | "contradiction" | "judgment" | "note";
|
|
8
|
+
type ObservationRecord = {
|
|
9
|
+
observationId: string;
|
|
10
|
+
topicId: string;
|
|
11
|
+
observationType: ObservationKind;
|
|
12
|
+
summary: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
confidence?: number;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
createdAt: number;
|
|
18
|
+
};
|
|
19
|
+
type ObservationContext = {
|
|
20
|
+
topicId: string;
|
|
21
|
+
totalObservations: number;
|
|
22
|
+
latest: ObservationRecord[];
|
|
23
|
+
semanticMatches: ObservationRecord[];
|
|
24
|
+
byType: Record<ObservationKind, number>;
|
|
25
|
+
generatedAt: number;
|
|
26
|
+
};
|
|
27
|
+
type ObservationIngestInput = {
|
|
28
|
+
topicId: string;
|
|
29
|
+
observationType: ObservationKind;
|
|
30
|
+
summary: string;
|
|
31
|
+
source?: string;
|
|
32
|
+
confidence?: number;
|
|
33
|
+
tags?: string[];
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
type ObservationContextInput = {
|
|
37
|
+
topicId: string;
|
|
38
|
+
query?: string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
};
|
|
41
|
+
declare class McpObservationStore {
|
|
42
|
+
private readonly byTopic;
|
|
43
|
+
ingest(input: ObservationIngestInput): ObservationRecord;
|
|
44
|
+
list(topicId: string, limit?: number): ObservationRecord[];
|
|
45
|
+
search(topicId: string, query: string, limit?: number): ObservationRecord[];
|
|
46
|
+
getContext(input: ObservationContextInput): ObservationContext;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type McpTextContent = {
|
|
50
|
+
type: "text";
|
|
51
|
+
text: string;
|
|
52
|
+
};
|
|
53
|
+
type McpToolResult = {
|
|
54
|
+
content: McpTextContent[];
|
|
55
|
+
isError?: boolean;
|
|
56
|
+
};
|
|
57
|
+
type McpToolHandler = (params: Record<string, unknown>, contract: McpToolContract) => Promise<McpToolResult>;
|
|
58
|
+
type McpHandlerContext = {
|
|
59
|
+
sdkConfig: GatewayClientConfig;
|
|
60
|
+
observationStore?: McpObservationStore;
|
|
61
|
+
onObservationIngested?: (topicId: string) => Promise<void> | void;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type ToolExecutionTransportKind = "stdio" | "hosted" | "remote" | "chat" | (string & {});
|
|
65
|
+
type ToolExecutionAuthMode = "interactive_user" | "service_principal" | "tenant_api_key" | "session_token" | "unknown";
|
|
66
|
+
type ToolExecutionEnvelope = {
|
|
67
|
+
toolName: string;
|
|
68
|
+
params: Record<string, unknown>;
|
|
69
|
+
contract: McpToolContract;
|
|
70
|
+
transport: {
|
|
71
|
+
kind: ToolExecutionTransportKind;
|
|
72
|
+
surface: "mcp" | "chat";
|
|
73
|
+
normalizedAt: "handler_boundary";
|
|
74
|
+
};
|
|
75
|
+
auth: {
|
|
76
|
+
mode: ToolExecutionAuthMode;
|
|
77
|
+
};
|
|
78
|
+
policy: {
|
|
79
|
+
requiredScopes: readonly string[];
|
|
80
|
+
enforcement: "gateway";
|
|
81
|
+
};
|
|
82
|
+
audit: {
|
|
83
|
+
source: "gateway_envelope";
|
|
84
|
+
structuralFields: readonly [
|
|
85
|
+
"toolName",
|
|
86
|
+
"code",
|
|
87
|
+
"status",
|
|
88
|
+
"correlationId",
|
|
89
|
+
"policyTraceId",
|
|
90
|
+
"invariant"
|
|
91
|
+
];
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
type ToolExecutionAuditEvent = {
|
|
95
|
+
toolName: string;
|
|
96
|
+
contractName: string;
|
|
97
|
+
transportKind: ToolExecutionTransportKind;
|
|
98
|
+
authMode: ToolExecutionAuthMode;
|
|
99
|
+
requiredScopes: readonly string[];
|
|
100
|
+
source: "gateway_envelope";
|
|
101
|
+
isError: boolean;
|
|
102
|
+
code?: string;
|
|
103
|
+
status?: number;
|
|
104
|
+
correlationId?: string | null;
|
|
105
|
+
policyTraceId?: string | null;
|
|
106
|
+
invariant?: string | null;
|
|
107
|
+
};
|
|
108
|
+
type ToolExecutionHookSet = {
|
|
109
|
+
onEnvelope?: (envelope: ToolExecutionEnvelope) => Promise<void> | void;
|
|
110
|
+
onAuditEvent?: (event: ToolExecutionAuditEvent) => Promise<void> | void;
|
|
111
|
+
};
|
|
112
|
+
type TransportParityDriftKind = "missing_tool" | "degraded_behavior" | "audit_drift" | "policy_drift";
|
|
113
|
+
declare function classifyTransportParityDrift(kind: TransportParityDriftKind): "critical" | "high" | "medium";
|
|
114
|
+
declare function createToolExecutionEnvelope(args: {
|
|
115
|
+
toolName: string;
|
|
116
|
+
params: Record<string, unknown>;
|
|
117
|
+
contract: McpToolContract;
|
|
118
|
+
transportKind: ToolExecutionTransportKind;
|
|
119
|
+
authMode: ToolExecutionAuthMode;
|
|
120
|
+
requiredScopes: readonly string[];
|
|
121
|
+
}): ToolExecutionEnvelope;
|
|
122
|
+
declare function parseToolExecutionMetadata(result: McpToolResult): {
|
|
123
|
+
isError: boolean;
|
|
124
|
+
code?: string;
|
|
125
|
+
status?: number;
|
|
126
|
+
correlationId?: string | null;
|
|
127
|
+
policyTraceId?: string | null;
|
|
128
|
+
invariant?: string | null;
|
|
129
|
+
};
|
|
130
|
+
declare function executeToolWithEnvelope(args: {
|
|
131
|
+
envelope: ToolExecutionEnvelope;
|
|
132
|
+
execute: () => Promise<McpToolResult>;
|
|
133
|
+
hooks?: ToolExecutionHookSet;
|
|
134
|
+
}): Promise<McpToolResult>;
|
|
135
|
+
|
|
136
|
+
declare const LUCERN_OBSERVER_PROMPT_NAME = "lucern-observer";
|
|
137
|
+
declare const LUCERN_AGENT_MD = "# Lucern \u2014 Reasoning Intelligence\n\nYou are connected to a Lucern reasoning graph. Lucern tracks beliefs, evidence,\nquestions, judgments, and contradictions as structured reasoning state.\n\n## Behavioral Mode\n\nOperate in active observation mode:\n\n1. Watch for claims, evidence, questions, and contradictions.\n2. Suggest graph updates when reasoning-relevant events appear.\n3. Always request user confirmation before mutating graph state.\n4. Preserve uncertainty explicitly; unresolved contradictions are valid.\n\nUse this suggestion format:\n\n`\uD83D\uDD0D Lucern detected: [what changed] -> Want me to log this?`\n\n## Tool Use Defaults\n\n1. Read context first for substantive questions.\n2. Prefer atomic writes: create belief/evidence/question separately, then link edges.\n3. Use worktree lifecycle for investigations: add_worktree -> merge -> push.\n4. Never auto-score confidence without explicit rationale.\n\n## Safety Defaults\n\n1. Do not fabricate evidence.\n2. Do not collapse contradictions automatically.\n3. Keep provenance and rationale in every write path.\n";
|
|
138
|
+
declare function buildLucernObserverPrompt(topicId?: string): string;
|
|
139
|
+
|
|
140
|
+
declare function runLucernMcpCli(argv?: readonly string[]): Promise<void>;
|
|
141
|
+
|
|
142
|
+
type ResourceUri = (typeof LUCERN_MCP_RESOURCE_URIS)[number];
|
|
143
|
+
type BuiltinToolName = keyof typeof MCP_TOOL_CONTRACTS;
|
|
144
|
+
type ToolName = string;
|
|
145
|
+
type McpToolExecutor = (toolName: ToolName, params: Record<string, unknown>, contract: McpToolContract) => Promise<unknown>;
|
|
146
|
+
type McpServerRuntime = {
|
|
147
|
+
registerResource?: (uri: string, handler: (params: Record<string, unknown>) => Promise<unknown>) => void;
|
|
148
|
+
registerTool?: (name: string, handler: (params: Record<string, unknown>) => Promise<unknown>) => void;
|
|
149
|
+
};
|
|
150
|
+
type McpResourceDescriptor = {
|
|
151
|
+
uri: ResourceUri;
|
|
152
|
+
requiredScopes: readonly string[];
|
|
153
|
+
};
|
|
154
|
+
type McpToolDescriptor = {
|
|
155
|
+
name: ToolName;
|
|
156
|
+
requiredScopes: readonly string[];
|
|
157
|
+
contract: McpToolContract;
|
|
158
|
+
implemented: boolean;
|
|
159
|
+
source: "platform" | "custom";
|
|
160
|
+
};
|
|
161
|
+
type AdditionalMcpTool = {
|
|
162
|
+
name: ToolName;
|
|
163
|
+
requiredScopes: readonly string[];
|
|
164
|
+
contract: McpToolContract;
|
|
165
|
+
handler: McpToolHandler;
|
|
166
|
+
implemented?: boolean;
|
|
167
|
+
source?: "platform" | "custom";
|
|
168
|
+
};
|
|
169
|
+
declare const LUCERN_MCP_RESOURCE_URIS: readonly ["lucern://schema/kernel", "lucern://schema/packs/{packId}", "lucern://schema/extensions", "lucern://graph/sample", "lucern://api/openapi", "lucern://sdk/examples", "lucern://docs/invariants"];
|
|
170
|
+
declare const LUCERN_MCP_TOOL_NAMES: BuiltinToolName[];
|
|
171
|
+
declare function createLucernMcpServer(options?: {
|
|
172
|
+
apiKey?: string;
|
|
173
|
+
sessionToken?: string;
|
|
174
|
+
baseUrl?: string;
|
|
175
|
+
fetchImpl?: typeof fetch;
|
|
176
|
+
toolExecutor?: McpToolExecutor;
|
|
177
|
+
observationStore?: McpObservationStore;
|
|
178
|
+
onObservationIngested?: (topicId: string) => Promise<void> | void;
|
|
179
|
+
transportKind?: ToolExecutionTransportKind;
|
|
180
|
+
authMode?: ToolExecutionAuthMode;
|
|
181
|
+
onEnvelope?: (envelope: ToolExecutionEnvelope) => Promise<void> | void;
|
|
182
|
+
onAuditEvent?: (event: ToolExecutionAuditEvent) => Promise<void> | void;
|
|
183
|
+
additionalTools?: readonly AdditionalMcpTool[];
|
|
184
|
+
}): {
|
|
185
|
+
server: McpServerRuntime;
|
|
186
|
+
resources: readonly McpResourceDescriptor[];
|
|
187
|
+
tools: readonly McpToolDescriptor[];
|
|
188
|
+
authErrorCodes: readonly string[];
|
|
189
|
+
rateLimitSignals: readonly string[];
|
|
190
|
+
handlers: Record<string, McpToolHandler>;
|
|
191
|
+
implementedToolNames: ToolName[];
|
|
192
|
+
unimplementedToolNames: ToolName[];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type StandaloneRuntime = ReturnType<typeof createLucernMcpServer>;
|
|
196
|
+
type StandaloneMcpServerOptions = {
|
|
197
|
+
apiKey?: string;
|
|
198
|
+
sessionToken?: string;
|
|
199
|
+
baseUrl?: string;
|
|
200
|
+
fetchImpl?: typeof fetch;
|
|
201
|
+
transportKind?: ToolExecutionTransportKind;
|
|
202
|
+
authMode?: ToolExecutionAuthMode;
|
|
203
|
+
onEnvelope?: (envelope: ToolExecutionEnvelope) => Promise<void> | void;
|
|
204
|
+
onAuditEvent?: (event: ToolExecutionAuditEvent) => Promise<void> | void;
|
|
205
|
+
additionalTools?: readonly AdditionalMcpTool[];
|
|
206
|
+
};
|
|
207
|
+
declare function createLucernStandaloneMcpServer(options?: StandaloneMcpServerOptions): {
|
|
208
|
+
server: McpServer;
|
|
209
|
+
runtime: StandaloneRuntime;
|
|
210
|
+
resourceUris: string[];
|
|
211
|
+
promptNames: string[];
|
|
212
|
+
};
|
|
213
|
+
declare function startLucernMcpStdioServer(options?: StandaloneMcpServerOptions): Promise<{
|
|
214
|
+
server: McpServer;
|
|
215
|
+
runtime: StandaloneRuntime;
|
|
216
|
+
resourceUris: string[];
|
|
217
|
+
promptNames: string[];
|
|
218
|
+
}>;
|
|
219
|
+
|
|
220
|
+
type RemoteMcpServerOptions = StandaloneMcpServerOptions & {
|
|
221
|
+
host?: string;
|
|
222
|
+
port?: number;
|
|
223
|
+
path?: string;
|
|
224
|
+
healthPath?: string;
|
|
225
|
+
serverAuthToken?: string;
|
|
226
|
+
allowApiKeyPassthrough?: boolean;
|
|
227
|
+
};
|
|
228
|
+
declare function createLucernMcpHttpRequestHandler(options?: RemoteMcpServerOptions): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
229
|
+
declare function startLucernMcpHttpServer(options?: RemoteMcpServerOptions): Promise<{
|
|
230
|
+
host: string;
|
|
231
|
+
port: number;
|
|
232
|
+
path: string;
|
|
233
|
+
healthPath: string;
|
|
234
|
+
close: () => Promise<void>;
|
|
235
|
+
}>;
|
|
236
|
+
|
|
237
|
+
declare function createMcpHandlerRegistry(context: McpHandlerContext): Record<string, McpToolHandler>;
|
|
238
|
+
|
|
239
|
+
declare function resolveCredentials(): {
|
|
240
|
+
lucernResolved: boolean;
|
|
241
|
+
stackResolved: boolean;
|
|
242
|
+
mcResolved: boolean;
|
|
243
|
+
source: string;
|
|
244
|
+
rawLucernApiKey?: string;
|
|
245
|
+
rawStackApiKey?: string;
|
|
246
|
+
rawUserToken?: string;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
type LegacyAuthContext = {
|
|
250
|
+
sessionType: "agent" | "user";
|
|
251
|
+
userId: string;
|
|
252
|
+
tenantId: string;
|
|
253
|
+
role: string;
|
|
254
|
+
allowedTopics: string[] | null;
|
|
255
|
+
groupIds: string[];
|
|
256
|
+
permittedPackKeys: string[];
|
|
257
|
+
sessionId: string;
|
|
258
|
+
principalId?: string;
|
|
259
|
+
principalType?: string;
|
|
260
|
+
workspaceId?: string;
|
|
261
|
+
scopes?: string[];
|
|
262
|
+
authMode?: string;
|
|
263
|
+
roles?: string[];
|
|
264
|
+
transportKind?: string;
|
|
265
|
+
useSdk?: boolean;
|
|
266
|
+
gatewayBaseUrl?: string;
|
|
267
|
+
getAuthHeaders?: () => Promise<Record<string, string>>;
|
|
268
|
+
lucernClient?: {
|
|
269
|
+
context: {
|
|
270
|
+
discover(input: {
|
|
271
|
+
query: string;
|
|
272
|
+
topK?: number;
|
|
273
|
+
includeNeighborhood?: boolean;
|
|
274
|
+
}): Promise<unknown>;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
declare function loadLegacyDiscoveryHandlers(): Promise<{
|
|
280
|
+
discover(args: Record<string, unknown>, ctx: LegacyAuthContext): Promise<Record<string, unknown>>;
|
|
281
|
+
}>;
|
|
282
|
+
|
|
283
|
+
type LegacyAuthenticatedHandler = (args: Record<string, unknown>, ctx: LegacyAuthContext) => Promise<Record<string, unknown>>;
|
|
284
|
+
declare function buildLegacyAuthenticatedHandlerMap(): Promise<Record<string, LegacyAuthenticatedHandler>>;
|
|
285
|
+
|
|
286
|
+
declare const BOOTSTRAP_MCP_TOOLS: Record<string, McpToolContract>;
|
|
287
|
+
declare const COORDINATION_MCP_TOOLS: Record<string, McpToolContract>;
|
|
288
|
+
declare const EPISTEMIC_CONTRACT_MCP_TOOLS: Record<string, McpToolContract>;
|
|
289
|
+
declare const SCOPE_MCP_TOOLS: Record<string, McpToolContract>;
|
|
290
|
+
|
|
291
|
+
type JsonRecord = Record<string, unknown>;
|
|
292
|
+
declare function initializeLucernScriptEnv(): void;
|
|
293
|
+
declare function readArg(name: string, fallback?: string): string | undefined;
|
|
294
|
+
declare function createLucernMcpClient(): Promise<Client>;
|
|
295
|
+
declare function createLucernAdminClient(): ConvexHttpClient;
|
|
296
|
+
declare function resolveMcpSessionTenantId(): Promise<string | undefined>;
|
|
297
|
+
declare function callMcpTool<T extends JsonRecord = JsonRecord>(client: Client, toolName: string, args: JsonRecord): Promise<T>;
|
|
298
|
+
declare function closeMcpClient(client: Client): Promise<void>;
|
|
299
|
+
|
|
300
|
+
type ContextRankingProfile = "baseline_v1" | "hybrid_v1" | "weighted_v1";
|
|
301
|
+
type ValidationResult = {
|
|
302
|
+
valid: boolean;
|
|
303
|
+
errors: string[];
|
|
304
|
+
};
|
|
305
|
+
declare function validateContextPackSchema(payload: unknown): ValidationResult;
|
|
306
|
+
|
|
307
|
+
export { BOOTSTRAP_MCP_TOOLS, COORDINATION_MCP_TOOLS, type ContextRankingProfile, EPISTEMIC_CONTRACT_MCP_TOOLS, type JsonRecord, LUCERN_AGENT_MD, LUCERN_MCP_RESOURCE_URIS, LUCERN_MCP_TOOL_NAMES, LUCERN_OBSERVER_PROMPT_NAME, type LegacyAuthContext, type LegacyAuthenticatedHandler, McpObservationStore, type RemoteMcpServerOptions, SCOPE_MCP_TOOLS, type StandaloneMcpServerOptions, type ToolExecutionAuditEvent, type ToolExecutionAuthMode, type ToolExecutionEnvelope, type ToolExecutionTransportKind, type TransportParityDriftKind, buildLegacyAuthenticatedHandlerMap, buildLucernObserverPrompt, callMcpTool, classifyTransportParityDrift, closeMcpClient, createLucernAdminClient, createLucernMcpClient, createLucernMcpHttpRequestHandler, createLucernMcpServer, createLucernStandaloneMcpServer, createMcpHandlerRegistry, createToolExecutionEnvelope, executeToolWithEnvelope, initializeLucernScriptEnv, loadLegacyDiscoveryHandlers, parseToolExecutionMetadata, readArg, resolveCredentials as resolveLegacyMcpCredentials, resolveMcpSessionTenantId, runLucernMcpCli, startLucernMcpHttpServer, startLucernMcpStdioServer, validateContextPackSchema };
|