mindgraph-mcp 0.21.0 → 0.23.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.
@@ -0,0 +1,133 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { MindGraph } from 'mindgraph';
3
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
4
+
5
+ interface GeneratedToolDescriptor {
6
+ name: string;
7
+ description: string;
8
+ schema_id: string;
9
+ object_type: string;
10
+ maps_to: string;
11
+ relation?: string;
12
+ entry_role?: "source" | "target";
13
+ far_type?: string;
14
+ input_schema: Record<string, unknown>;
15
+ }
16
+ interface Cache {
17
+ tools: Tool[];
18
+ byName: Map<string, GeneratedToolDescriptor>;
19
+ fetchedAt: number;
20
+ }
21
+ /**
22
+ * One manifest cache. The stdio server owns a single process-wide entry (one
23
+ * key, one org); the hosted server keeps one per org in a Map so tenants never
24
+ * see each other's ontology tools.
25
+ */
26
+ interface GeneratedToolsEntry {
27
+ /** Last manifest the server actually answered with. */
28
+ cache: Cache | null;
29
+ retryNotBefore: number;
30
+ }
31
+
32
+ type Capability = "unknown" | "supported" | "unsupported";
33
+ /**
34
+ * The capability latch. The stdio server has one per process; the hosted
35
+ * server keeps one per org so a governance-less tenant never fails another
36
+ * tenant open.
37
+ */
38
+ interface GovernanceLatch {
39
+ capability: Capability;
40
+ unsupportedUntil: number;
41
+ unsupportedLogged: boolean;
42
+ }
43
+ interface GovernanceConfig {
44
+ baseUrl: string;
45
+ apiKey: string;
46
+ orgId?: string;
47
+ agentId: string;
48
+ fetchImpl?: typeof fetch;
49
+ disabled?: boolean;
50
+ /** Extra audit context merged into the check — e.g. the resource URI. */
51
+ context?: Record<string, unknown>;
52
+ /** Overridden only by tests, to keep the retry path fast. */
53
+ retryDelaysMs?: number[];
54
+ /** Capability latch to use; defaults to the process-wide one. */
55
+ latch?: GovernanceLatch;
56
+ }
57
+
58
+ interface HostedIdentity {
59
+ user: {
60
+ id: string;
61
+ name?: string;
62
+ email?: string;
63
+ };
64
+ orgId: string;
65
+ orgName?: string;
66
+ }
67
+
68
+ interface MemoryRuntimeConfig {
69
+ serverVersion?: string;
70
+ baseUrl?: string;
71
+ profile?: string;
72
+ harness?: string;
73
+ orgId?: string;
74
+ agentId?: string;
75
+ }
76
+
77
+ /** Everything the request handlers close over. */
78
+ interface ServerWiring {
79
+ client: MindGraph;
80
+ serverVersion: string;
81
+ instructions: string;
82
+ profile: string;
83
+ /** Trusted agent identity: the default in stdio mode, the only one in hosted mode. */
84
+ agentId: string;
85
+ governance: GovernanceConfig;
86
+ memory: MemoryRuntimeConfig;
87
+ /** Manifest cache; omitted → the process-wide entry (stdio). */
88
+ generatedTools?: GeneratedToolsEntry;
89
+ /** Present in hosted mode: adds search/fetch/whoami and the attribution rule (D4). */
90
+ hosted?: HostedIdentity & {
91
+ log?: (event: Record<string, unknown>) => void;
92
+ };
93
+ }
94
+ declare function buildMindGraphServer(wiring: ServerWiring): Server;
95
+ interface MindGraphServerOptions {
96
+ /** SDK client already authenticated with the exchanged API token. */
97
+ client: MindGraph;
98
+ /** The exchanged API token; used by the governance probe in place of an API key. */
99
+ bearer: string;
100
+ baseUrl: string;
101
+ orgId: string;
102
+ orgName?: string;
103
+ /** `mcp:{client_host}:{user_id}`; overwrites agent_id on every call (D4). */
104
+ agentId: string;
105
+ user: {
106
+ id: string;
107
+ name?: string;
108
+ email?: string;
109
+ };
110
+ profile: "general";
111
+ harness: "hosted";
112
+ instructions?: string;
113
+ serverVersion: string;
114
+ /** Skip the governance checkpoint (the stdio MINDGRAPH_GOVERNANCE=off knob). */
115
+ governanceDisabled?: boolean;
116
+ /** Per-org caches owned by the route; one entry per org, same TTLs as stdio. */
117
+ caches: {
118
+ generatedTools: Map<string, GeneratedToolsEntry>;
119
+ governance: Map<string, GovernanceLatch>;
120
+ };
121
+ /** Structured call log (never receives the bearer). */
122
+ log?: (event: Record<string, unknown>) => void;
123
+ }
124
+ /** Build one hosted Server (one request, one member, one org). */
125
+ declare function createMindGraphServer(opts: MindGraphServerOptions): Server;
126
+ /**
127
+ * Serve one Streamable HTTP request statelessly (D6). The caller has already
128
+ * verified the bearer and resolved `opts`; this helper owns only the JSON-RPC
129
+ * surface: non-POST → 405, unparsable → 400, batches → 400, else the SDK.
130
+ */
131
+ declare function handleHostedRequest(request: Request, opts: MindGraphServerOptions): Promise<Response>;
132
+
133
+ export { type GeneratedToolsEntry, type GovernanceLatch, type MindGraphServerOptions, type ServerWiring, buildMindGraphServer, createMindGraphServer, handleHostedRequest };
@@ -0,0 +1,133 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { MindGraph } from 'mindgraph';
3
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
4
+
5
+ interface GeneratedToolDescriptor {
6
+ name: string;
7
+ description: string;
8
+ schema_id: string;
9
+ object_type: string;
10
+ maps_to: string;
11
+ relation?: string;
12
+ entry_role?: "source" | "target";
13
+ far_type?: string;
14
+ input_schema: Record<string, unknown>;
15
+ }
16
+ interface Cache {
17
+ tools: Tool[];
18
+ byName: Map<string, GeneratedToolDescriptor>;
19
+ fetchedAt: number;
20
+ }
21
+ /**
22
+ * One manifest cache. The stdio server owns a single process-wide entry (one
23
+ * key, one org); the hosted server keeps one per org in a Map so tenants never
24
+ * see each other's ontology tools.
25
+ */
26
+ interface GeneratedToolsEntry {
27
+ /** Last manifest the server actually answered with. */
28
+ cache: Cache | null;
29
+ retryNotBefore: number;
30
+ }
31
+
32
+ type Capability = "unknown" | "supported" | "unsupported";
33
+ /**
34
+ * The capability latch. The stdio server has one per process; the hosted
35
+ * server keeps one per org so a governance-less tenant never fails another
36
+ * tenant open.
37
+ */
38
+ interface GovernanceLatch {
39
+ capability: Capability;
40
+ unsupportedUntil: number;
41
+ unsupportedLogged: boolean;
42
+ }
43
+ interface GovernanceConfig {
44
+ baseUrl: string;
45
+ apiKey: string;
46
+ orgId?: string;
47
+ agentId: string;
48
+ fetchImpl?: typeof fetch;
49
+ disabled?: boolean;
50
+ /** Extra audit context merged into the check — e.g. the resource URI. */
51
+ context?: Record<string, unknown>;
52
+ /** Overridden only by tests, to keep the retry path fast. */
53
+ retryDelaysMs?: number[];
54
+ /** Capability latch to use; defaults to the process-wide one. */
55
+ latch?: GovernanceLatch;
56
+ }
57
+
58
+ interface HostedIdentity {
59
+ user: {
60
+ id: string;
61
+ name?: string;
62
+ email?: string;
63
+ };
64
+ orgId: string;
65
+ orgName?: string;
66
+ }
67
+
68
+ interface MemoryRuntimeConfig {
69
+ serverVersion?: string;
70
+ baseUrl?: string;
71
+ profile?: string;
72
+ harness?: string;
73
+ orgId?: string;
74
+ agentId?: string;
75
+ }
76
+
77
+ /** Everything the request handlers close over. */
78
+ interface ServerWiring {
79
+ client: MindGraph;
80
+ serverVersion: string;
81
+ instructions: string;
82
+ profile: string;
83
+ /** Trusted agent identity: the default in stdio mode, the only one in hosted mode. */
84
+ agentId: string;
85
+ governance: GovernanceConfig;
86
+ memory: MemoryRuntimeConfig;
87
+ /** Manifest cache; omitted → the process-wide entry (stdio). */
88
+ generatedTools?: GeneratedToolsEntry;
89
+ /** Present in hosted mode: adds search/fetch/whoami and the attribution rule (D4). */
90
+ hosted?: HostedIdentity & {
91
+ log?: (event: Record<string, unknown>) => void;
92
+ };
93
+ }
94
+ declare function buildMindGraphServer(wiring: ServerWiring): Server;
95
+ interface MindGraphServerOptions {
96
+ /** SDK client already authenticated with the exchanged API token. */
97
+ client: MindGraph;
98
+ /** The exchanged API token; used by the governance probe in place of an API key. */
99
+ bearer: string;
100
+ baseUrl: string;
101
+ orgId: string;
102
+ orgName?: string;
103
+ /** `mcp:{client_host}:{user_id}`; overwrites agent_id on every call (D4). */
104
+ agentId: string;
105
+ user: {
106
+ id: string;
107
+ name?: string;
108
+ email?: string;
109
+ };
110
+ profile: "general";
111
+ harness: "hosted";
112
+ instructions?: string;
113
+ serverVersion: string;
114
+ /** Skip the governance checkpoint (the stdio MINDGRAPH_GOVERNANCE=off knob). */
115
+ governanceDisabled?: boolean;
116
+ /** Per-org caches owned by the route; one entry per org, same TTLs as stdio. */
117
+ caches: {
118
+ generatedTools: Map<string, GeneratedToolsEntry>;
119
+ governance: Map<string, GovernanceLatch>;
120
+ };
121
+ /** Structured call log (never receives the bearer). */
122
+ log?: (event: Record<string, unknown>) => void;
123
+ }
124
+ /** Build one hosted Server (one request, one member, one org). */
125
+ declare function createMindGraphServer(opts: MindGraphServerOptions): Server;
126
+ /**
127
+ * Serve one Streamable HTTP request statelessly (D6). The caller has already
128
+ * verified the bearer and resolved `opts`; this helper owns only the JSON-RPC
129
+ * surface: non-POST → 405, unparsable → 400, batches → 400, else the SDK.
130
+ */
131
+ declare function handleHostedRequest(request: Request, opts: MindGraphServerOptions): Promise<Response>;
132
+
133
+ export { type GeneratedToolsEntry, type GovernanceLatch, type MindGraphServerOptions, type ServerWiring, buildMindGraphServer, createMindGraphServer, handleHostedRequest };