@animalabs/agent-framework 0.1.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/LICENSE +21 -0
- package/README.md +233 -0
- package/dist/src/agent.d.ts +130 -0
- package/dist/src/agent.d.ts.map +1 -0
- package/dist/src/agent.js +406 -0
- package/dist/src/agent.js.map +1 -0
- package/dist/src/api/mcp-server.d.ts +37 -0
- package/dist/src/api/mcp-server.d.ts.map +1 -0
- package/dist/src/api/mcp-server.js +598 -0
- package/dist/src/api/mcp-server.js.map +1 -0
- package/dist/src/api/server.d.ts +83 -0
- package/dist/src/api/server.d.ts.map +1 -0
- package/dist/src/api/server.js +785 -0
- package/dist/src/api/server.js.map +1 -0
- package/dist/src/api/types.d.ts +395 -0
- package/dist/src/api/types.d.ts.map +1 -0
- package/dist/src/api/types.js +5 -0
- package/dist/src/api/types.js.map +1 -0
- package/dist/src/framework.d.ts +309 -0
- package/dist/src/framework.d.ts.map +1 -0
- package/dist/src/framework.js +2309 -0
- package/dist/src/framework.js.map +1 -0
- package/dist/src/gate/event-gate.d.ts +75 -0
- package/dist/src/gate/event-gate.d.ts.map +1 -0
- package/dist/src/gate/event-gate.js +503 -0
- package/dist/src/gate/event-gate.js.map +1 -0
- package/dist/src/gate/index.d.ts +3 -0
- package/dist/src/gate/index.d.ts.map +1 -0
- package/dist/src/gate/index.js +2 -0
- package/dist/src/gate/index.js.map +1 -0
- package/dist/src/gate/types.d.ts +82 -0
- package/dist/src/gate/types.d.ts.map +1 -0
- package/dist/src/gate/types.js +9 -0
- package/dist/src/gate/types.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +141 -0
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -0
- package/dist/src/mcpl/channel-registry.js +647 -0
- package/dist/src/mcpl/channel-registry.js.map +1 -0
- package/dist/src/mcpl/checkpoint-manager.d.ts +79 -0
- package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -0
- package/dist/src/mcpl/checkpoint-manager.js +430 -0
- package/dist/src/mcpl/checkpoint-manager.js.map +1 -0
- package/dist/src/mcpl/errors.d.ts +52 -0
- package/dist/src/mcpl/errors.d.ts.map +1 -0
- package/dist/src/mcpl/errors.js +93 -0
- package/dist/src/mcpl/errors.js.map +1 -0
- package/dist/src/mcpl/feature-set-manager.d.ts +91 -0
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -0
- package/dist/src/mcpl/feature-set-manager.js +250 -0
- package/dist/src/mcpl/feature-set-manager.js.map +1 -0
- package/dist/src/mcpl/hook-orchestrator.d.ts +51 -0
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -0
- package/dist/src/mcpl/hook-orchestrator.js +217 -0
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -0
- package/dist/src/mcpl/index.d.ts +14 -0
- package/dist/src/mcpl/index.d.ts.map +1 -0
- package/dist/src/mcpl/index.js +21 -0
- package/dist/src/mcpl/index.js.map +1 -0
- package/dist/src/mcpl/inference-router.d.ts +67 -0
- package/dist/src/mcpl/inference-router.d.ts.map +1 -0
- package/dist/src/mcpl/inference-router.js +249 -0
- package/dist/src/mcpl/inference-router.js.map +1 -0
- package/dist/src/mcpl/push-handler.d.ts +60 -0
- package/dist/src/mcpl/push-handler.d.ts.map +1 -0
- package/dist/src/mcpl/push-handler.js +162 -0
- package/dist/src/mcpl/push-handler.js.map +1 -0
- package/dist/src/mcpl/scope-manager.d.ts +76 -0
- package/dist/src/mcpl/scope-manager.d.ts.map +1 -0
- package/dist/src/mcpl/scope-manager.js +213 -0
- package/dist/src/mcpl/scope-manager.js.map +1 -0
- package/dist/src/mcpl/server-connection.d.ts +174 -0
- package/dist/src/mcpl/server-connection.d.ts.map +1 -0
- package/dist/src/mcpl/server-connection.js +559 -0
- package/dist/src/mcpl/server-connection.js.map +1 -0
- package/dist/src/mcpl/server-registry.d.ts +63 -0
- package/dist/src/mcpl/server-registry.d.ts.map +1 -0
- package/dist/src/mcpl/server-registry.js +119 -0
- package/dist/src/mcpl/server-registry.js.map +1 -0
- package/dist/src/mcpl/types.d.ts +755 -0
- package/dist/src/mcpl/types.d.ts.map +1 -0
- package/dist/src/mcpl/types.js +48 -0
- package/dist/src/mcpl/types.js.map +1 -0
- package/dist/src/module-registry.d.ts +93 -0
- package/dist/src/module-registry.d.ts.map +1 -0
- package/dist/src/module-registry.js +386 -0
- package/dist/src/module-registry.js.map +1 -0
- package/dist/src/modules/api/index.d.ts +22 -0
- package/dist/src/modules/api/index.d.ts.map +1 -0
- package/dist/src/modules/api/index.js +63 -0
- package/dist/src/modules/api/index.js.map +1 -0
- package/dist/src/modules/discord/discord-js-client.d.ts +58 -0
- package/dist/src/modules/discord/discord-js-client.d.ts.map +1 -0
- package/dist/src/modules/discord/discord-js-client.js +273 -0
- package/dist/src/modules/discord/discord-js-client.js.map +1 -0
- package/dist/src/modules/discord/index.d.ts +82 -0
- package/dist/src/modules/discord/index.d.ts.map +1 -0
- package/dist/src/modules/discord/index.js +959 -0
- package/dist/src/modules/discord/index.js.map +1 -0
- package/dist/src/modules/discord/types.d.ts +327 -0
- package/dist/src/modules/discord/types.d.ts.map +1 -0
- package/dist/src/modules/discord/types.js +5 -0
- package/dist/src/modules/discord/types.js.map +1 -0
- package/dist/src/modules/index.d.ts +11 -0
- package/dist/src/modules/index.d.ts.map +1 -0
- package/dist/src/modules/index.js +7 -0
- package/dist/src/modules/index.js.map +1 -0
- package/dist/src/modules/workspace/index.d.ts +59 -0
- package/dist/src/modules/workspace/index.d.ts.map +1 -0
- package/dist/src/modules/workspace/index.js +831 -0
- package/dist/src/modules/workspace/index.js.map +1 -0
- package/dist/src/modules/workspace/sync.d.ts +48 -0
- package/dist/src/modules/workspace/sync.d.ts.map +1 -0
- package/dist/src/modules/workspace/sync.js +253 -0
- package/dist/src/modules/workspace/sync.js.map +1 -0
- package/dist/src/modules/workspace/types.d.ts +166 -0
- package/dist/src/modules/workspace/types.d.ts.map +1 -0
- package/dist/src/modules/workspace/types.js +5 -0
- package/dist/src/modules/workspace/types.js.map +1 -0
- package/dist/src/modules/workspace/watcher.d.ts +43 -0
- package/dist/src/modules/workspace/watcher.d.ts.map +1 -0
- package/dist/src/modules/workspace/watcher.js +120 -0
- package/dist/src/modules/workspace/watcher.js.map +1 -0
- package/dist/src/queue.d.ts +50 -0
- package/dist/src/queue.d.ts.map +1 -0
- package/dist/src/queue.js +95 -0
- package/dist/src/queue.js.map +1 -0
- package/dist/src/safe-slice.d.ts +8 -0
- package/dist/src/safe-slice.d.ts.map +1 -0
- package/dist/src/safe-slice.js +18 -0
- package/dist/src/safe-slice.js.map +1 -0
- package/dist/src/types/agent.d.ts +118 -0
- package/dist/src/types/agent.d.ts.map +1 -0
- package/dist/src/types/agent.js +2 -0
- package/dist/src/types/agent.js.map +1 -0
- package/dist/src/types/events.d.ts +220 -0
- package/dist/src/types/events.d.ts.map +1 -0
- package/dist/src/types/events.js +2 -0
- package/dist/src/types/events.js.map +1 -0
- package/dist/src/types/framework.d.ts +184 -0
- package/dist/src/types/framework.d.ts.map +1 -0
- package/dist/src/types/framework.js +2 -0
- package/dist/src/types/framework.js.map +1 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +7 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/inference-log.d.ts +64 -0
- package/dist/src/types/inference-log.d.ts.map +1 -0
- package/dist/src/types/inference-log.js +5 -0
- package/dist/src/types/inference-log.js.map +1 -0
- package/dist/src/types/module.d.ts +302 -0
- package/dist/src/types/module.d.ts.map +1 -0
- package/dist/src/types/module.js +2 -0
- package/dist/src/types/module.js.map +1 -0
- package/dist/src/types/trace.d.ts +173 -0
- package/dist/src/types/trace.d.ts.map +1 -0
- package/dist/src/types/trace.js +2 -0
- package/dist/src/types/trace.js.map +1 -0
- package/dist/test/event-gate.test.d.ts +2 -0
- package/dist/test/event-gate.test.d.ts.map +1 -0
- package/dist/test/event-gate.test.js +535 -0
- package/dist/test/event-gate.test.js.map +1 -0
- package/dist/test/framework.test.d.ts +5 -0
- package/dist/test/framework.test.d.ts.map +1 -0
- package/dist/test/framework.test.js +738 -0
- package/dist/test/framework.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +58 -0
- package/src/agent.ts +512 -0
- package/src/api/mcp-server.ts +687 -0
- package/src/api/server.ts +1023 -0
- package/src/api/types.ts +542 -0
- package/src/framework.ts +2784 -0
- package/src/gate/event-gate.ts +623 -0
- package/src/gate/index.ts +12 -0
- package/src/gate/types.ts +112 -0
- package/src/index.ts +63 -0
- package/src/mcpl/channel-registry.ts +824 -0
- package/src/mcpl/checkpoint-manager.ts +545 -0
- package/src/mcpl/errors.ts +114 -0
- package/src/mcpl/feature-set-manager.ts +333 -0
- package/src/mcpl/hook-orchestrator.ts +281 -0
- package/src/mcpl/index.ts +134 -0
- package/src/mcpl/inference-router.ts +335 -0
- package/src/mcpl/push-handler.ts +232 -0
- package/src/mcpl/scope-manager.ts +262 -0
- package/src/mcpl/server-connection.ts +694 -0
- package/src/mcpl/server-registry.ts +144 -0
- package/src/mcpl/types.ts +991 -0
- package/src/module-registry.ts +547 -0
- package/src/modules/api/index.ts +94 -0
- package/src/modules/discord/discord-js-client.ts +353 -0
- package/src/modules/discord/index.ts +1146 -0
- package/src/modules/discord/types.ts +465 -0
- package/src/modules/index.ts +43 -0
- package/src/modules/workspace/index.ts +969 -0
- package/src/modules/workspace/sync.ts +314 -0
- package/src/modules/workspace/types.ts +202 -0
- package/src/modules/workspace/watcher.ts +142 -0
- package/src/queue.ts +106 -0
- package/src/safe-slice.ts +18 -0
- package/src/types/agent.ts +119 -0
- package/src/types/events.ts +252 -0
- package/src/types/framework.ts +211 -0
- package/src/types/index.ts +6 -0
- package/src/types/inference-log.ts +64 -0
- package/src/types/module.ts +367 -0
- package/src/types/trace.ts +196 -0
|
@@ -0,0 +1,991 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCPL (MCP Live) Protocol Types — v0.4.0-draft
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the host-side implementation of the MCPL protocol.
|
|
5
|
+
* Organized by spec section for easy cross-referencing with mcpl/SPEC.md.
|
|
6
|
+
*
|
|
7
|
+
* Naming conventions:
|
|
8
|
+
* - Types prefixed with `Mcpl` when they collide with existing framework/membrane
|
|
9
|
+
* types (e.g., McplContentBlock vs membrane's ContentBlock, McplModelInfo vs
|
|
10
|
+
* membrane's ModelInfo, McplInferenceRequestParams vs API's InferenceRequestParams).
|
|
11
|
+
* - All other types use plain names — they live in the mcpl/ module and are
|
|
12
|
+
* unambiguous when imported from here.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// JSON-RPC 2.0 (Transport Layer)
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* JSON-RPC 2.0 request. Notifications omit `id`.
|
|
21
|
+
*/
|
|
22
|
+
export interface JsonRpcRequest {
|
|
23
|
+
jsonrpc: '2.0';
|
|
24
|
+
method: string;
|
|
25
|
+
id?: string | number;
|
|
26
|
+
params?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* JSON-RPC 2.0 successful response.
|
|
31
|
+
*/
|
|
32
|
+
export interface JsonRpcResponse {
|
|
33
|
+
jsonrpc: '2.0';
|
|
34
|
+
id: string | number;
|
|
35
|
+
result?: unknown;
|
|
36
|
+
error?: JsonRpcError;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* JSON-RPC 2.0 error object.
|
|
41
|
+
*/
|
|
42
|
+
export interface JsonRpcError {
|
|
43
|
+
code: number;
|
|
44
|
+
message: string;
|
|
45
|
+
data?: unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Section 4 — MCPL Content Blocks (Wire Format)
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// These represent content as it travels over the MCPL protocol.
|
|
52
|
+
// They differ from membrane's ContentBlock (which is LLM-provider-oriented).
|
|
53
|
+
// Conversion between McplContentBlock and membrane ContentBlock happens in
|
|
54
|
+
// the host when bridging protocol ↔ inference pipeline.
|
|
55
|
+
|
|
56
|
+
export type McplContentBlock =
|
|
57
|
+
| McplTextContent
|
|
58
|
+
| McplImageContent
|
|
59
|
+
| McplAudioContent
|
|
60
|
+
| McplResourceContent;
|
|
61
|
+
|
|
62
|
+
export interface McplTextContent {
|
|
63
|
+
type: 'text';
|
|
64
|
+
text: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface McplImageContent {
|
|
68
|
+
type: 'image';
|
|
69
|
+
/** Base64-encoded image data (present when using inline form) */
|
|
70
|
+
data?: string;
|
|
71
|
+
/** MIME type (present when using inline form) */
|
|
72
|
+
mimeType?: string;
|
|
73
|
+
/** URI reference (present when using URI form) */
|
|
74
|
+
uri?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface McplAudioContent {
|
|
78
|
+
type: 'audio';
|
|
79
|
+
/** Base64-encoded audio data (present when using inline form) */
|
|
80
|
+
data?: string;
|
|
81
|
+
/** MIME type (present when using inline form) */
|
|
82
|
+
mimeType?: string;
|
|
83
|
+
/** URI reference (present when using URI form) */
|
|
84
|
+
uri?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface McplResourceContent {
|
|
88
|
+
type: 'resource';
|
|
89
|
+
/** Resource URI (e.g., "memory://facts/12345") */
|
|
90
|
+
uri: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ============================================================================
|
|
94
|
+
// Section 5 — Capability Negotiation
|
|
95
|
+
// ============================================================================
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* MCPL capabilities as advertised by a server in `experimental.mcpl`.
|
|
99
|
+
* Parsed from the server's `initialize` response.
|
|
100
|
+
*/
|
|
101
|
+
export interface McplCapabilities {
|
|
102
|
+
/** MCPL protocol version (e.g., "0.4") */
|
|
103
|
+
version: string;
|
|
104
|
+
|
|
105
|
+
/** Server supports push/event */
|
|
106
|
+
pushEvents?: boolean;
|
|
107
|
+
|
|
108
|
+
/** Context hook capabilities */
|
|
109
|
+
contextHooks?: {
|
|
110
|
+
beforeInference?: boolean;
|
|
111
|
+
afterInference?: boolean | { blocking: boolean };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Server-initiated inference capabilities */
|
|
115
|
+
inferenceRequest?: {
|
|
116
|
+
streaming?: boolean;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Server supports model/info requests */
|
|
120
|
+
modelInfo?: boolean;
|
|
121
|
+
|
|
122
|
+
/** Declared feature sets (keyed by feature set name) */
|
|
123
|
+
featureSets?: Record<string, FeatureSetDeclaration>;
|
|
124
|
+
|
|
125
|
+
/** Channel capabilities */
|
|
126
|
+
channels?: McplChannelCapabilities;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* MCPL capabilities that the host advertises to servers.
|
|
131
|
+
* Sent in the host's `initialize` response under `capabilities.experimental.mcpl`.
|
|
132
|
+
*/
|
|
133
|
+
export interface McplHostCapabilities {
|
|
134
|
+
version: string;
|
|
135
|
+
pushEvents?: boolean;
|
|
136
|
+
contextHooks?: {
|
|
137
|
+
beforeInference?: boolean;
|
|
138
|
+
afterInference?: boolean | { blocking: boolean };
|
|
139
|
+
};
|
|
140
|
+
inferenceRequest?: {
|
|
141
|
+
streaming?: boolean;
|
|
142
|
+
};
|
|
143
|
+
featureSets?: boolean;
|
|
144
|
+
channels?: McplChannelCapabilities;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Channel-specific capability flags. */
|
|
148
|
+
export interface McplChannelCapabilities {
|
|
149
|
+
register?: boolean;
|
|
150
|
+
publish?: boolean;
|
|
151
|
+
observe?: boolean;
|
|
152
|
+
lifecycle?: boolean;
|
|
153
|
+
streaming?: boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ============================================================================
|
|
157
|
+
// Section 5 — Server Configuration (Host-Side)
|
|
158
|
+
// ============================================================================
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Configuration for connecting to a single MCPL server.
|
|
162
|
+
* Provided in FrameworkConfig.mcplServers[].
|
|
163
|
+
*/
|
|
164
|
+
export interface McplServerConfig {
|
|
165
|
+
/** Unique server identifier */
|
|
166
|
+
id: string;
|
|
167
|
+
|
|
168
|
+
/** Command to spawn the server process (stdio transport) */
|
|
169
|
+
command: string;
|
|
170
|
+
|
|
171
|
+
/** Arguments for the command */
|
|
172
|
+
args?: string[];
|
|
173
|
+
|
|
174
|
+
/** Environment variables for the child process */
|
|
175
|
+
env?: Record<string, string>;
|
|
176
|
+
|
|
177
|
+
/** Feature sets to enable on connect */
|
|
178
|
+
enabledFeatureSets?: string[];
|
|
179
|
+
|
|
180
|
+
/** Feature sets to explicitly disable on connect */
|
|
181
|
+
disabledFeatureSets?: string[];
|
|
182
|
+
|
|
183
|
+
/** Scope configurations per feature set */
|
|
184
|
+
scopes?: Record<string, ScopeConfig>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Enable automatic reconnection on unexpected disconnect or handshake failure.
|
|
188
|
+
* When true, connect() resolves immediately (with null capabilities) if the
|
|
189
|
+
* server is unavailable, and retries in the background.
|
|
190
|
+
* Adapted from Anarchid/agent-framework@mcpl-module-proto.
|
|
191
|
+
*/
|
|
192
|
+
reconnect?: boolean;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Interval between reconnection attempts in milliseconds.
|
|
196
|
+
* Default: 5000 (5 seconds).
|
|
197
|
+
*/
|
|
198
|
+
reconnectIntervalMs?: number;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Optional callback to filter which incoming channel messages should trigger
|
|
202
|
+
* agent inference. Receives the text content and message metadata.
|
|
203
|
+
* Return true to trigger inference, false to silently accept the message.
|
|
204
|
+
*
|
|
205
|
+
* Common metadata fields servers may provide:
|
|
206
|
+
* - mentionIds: string[] — user IDs mentioned in the message
|
|
207
|
+
* - replyToAuthorId: string — user ID of the author being replied to
|
|
208
|
+
* - botUserId: string — the server's bot/self user ID
|
|
209
|
+
*
|
|
210
|
+
* If not provided, all incoming messages trigger inference.
|
|
211
|
+
*/
|
|
212
|
+
shouldTriggerInference?: (content: string, metadata: Record<string, unknown>) => boolean;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Tool name prefix for this server's tools.
|
|
216
|
+
* Tools are exposed as `{toolPrefix}:{toolName}`.
|
|
217
|
+
*
|
|
218
|
+
* Default: `mcpl:{id}` (e.g., `mcpl:zk:lobby_start_game`).
|
|
219
|
+
* Set to the server ID for cleaner names (e.g., `toolPrefix: 'zk'`
|
|
220
|
+
* gives `zk:lobby_start_game`).
|
|
221
|
+
*
|
|
222
|
+
* Must not collide with any module name or another server's prefix.
|
|
223
|
+
*/
|
|
224
|
+
toolPrefix?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ============================================================================
|
|
228
|
+
// Section 6 — Feature Sets
|
|
229
|
+
// ============================================================================
|
|
230
|
+
|
|
231
|
+
/** What a feature set can use. Maps to spec Section 6.2. */
|
|
232
|
+
export type FeatureSetUse =
|
|
233
|
+
| 'pushEvents'
|
|
234
|
+
| 'contextHooks.beforeInference'
|
|
235
|
+
| 'contextHooks.afterInference'
|
|
236
|
+
| 'inferenceRequest'
|
|
237
|
+
| 'tools'
|
|
238
|
+
| 'channels.publish'
|
|
239
|
+
| 'channels.observe';
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* A feature set declaration as advertised by a server.
|
|
243
|
+
* Spec Section 6.1.
|
|
244
|
+
*/
|
|
245
|
+
export interface FeatureSetDeclaration {
|
|
246
|
+
/** Human-readable description */
|
|
247
|
+
description: string;
|
|
248
|
+
|
|
249
|
+
/** Capabilities this feature set uses */
|
|
250
|
+
uses: FeatureSetUse[];
|
|
251
|
+
|
|
252
|
+
/** Whether this feature set uses scoped access (Section 7) */
|
|
253
|
+
scoped?: boolean;
|
|
254
|
+
|
|
255
|
+
/** Whether server supports rollback for this feature set (Section 8.1) */
|
|
256
|
+
rollback?: boolean;
|
|
257
|
+
|
|
258
|
+
/** Whether host manages state persistence for this feature set (Section 8.1) */
|
|
259
|
+
hostState?: boolean;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* featureSets/update params (Host → Server, Notification).
|
|
264
|
+
* Spec Section 6.7.
|
|
265
|
+
*/
|
|
266
|
+
export interface FeatureSetsUpdateParams {
|
|
267
|
+
/** Feature sets to enable */
|
|
268
|
+
enabled?: string[];
|
|
269
|
+
|
|
270
|
+
/** Feature sets to disable */
|
|
271
|
+
disabled?: string[];
|
|
272
|
+
|
|
273
|
+
/** Scope configurations per feature set */
|
|
274
|
+
scopes?: Record<string, ScopeConfig>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* featureSets/changed params (Server → Host, Notification).
|
|
279
|
+
* Spec Section 6.7.
|
|
280
|
+
*/
|
|
281
|
+
export interface FeatureSetsChangedParams {
|
|
282
|
+
/** Newly available feature sets */
|
|
283
|
+
added?: Record<string, FeatureSetDeclaration>;
|
|
284
|
+
|
|
285
|
+
/** Removed feature set names */
|
|
286
|
+
removed?: string[];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ============================================================================
|
|
290
|
+
// Section 7 — Scoped Access
|
|
291
|
+
// ============================================================================
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Scope configuration for a feature set — whitelist/blacklist patterns.
|
|
295
|
+
* Pattern matching semantics (glob, regex, exact) are host-defined.
|
|
296
|
+
*/
|
|
297
|
+
export interface ScopeConfig {
|
|
298
|
+
/** Patterns that are pre-approved */
|
|
299
|
+
whitelist?: string[];
|
|
300
|
+
|
|
301
|
+
/** Patterns that are always denied */
|
|
302
|
+
blacklist?: string[];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* A scope label with optional payload, as used in scope/elevate and tools/call.
|
|
307
|
+
* Spec Section 7.3.
|
|
308
|
+
*/
|
|
309
|
+
export interface ScopeLabel {
|
|
310
|
+
/** Human-readable identifier for whitelist/blacklist matching */
|
|
311
|
+
label: string;
|
|
312
|
+
|
|
313
|
+
/** Arbitrary data passed back to server when approved */
|
|
314
|
+
payload?: Record<string, unknown>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* scope/elevate params (Server → Host, Request).
|
|
319
|
+
* Spec Section 7.4.
|
|
320
|
+
*/
|
|
321
|
+
export interface ScopeElevateParams {
|
|
322
|
+
/** Feature set requesting elevation */
|
|
323
|
+
featureSet: string;
|
|
324
|
+
|
|
325
|
+
/** The scope being requested */
|
|
326
|
+
scope: ScopeLabel;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* scope/elevate result (Host → Server).
|
|
331
|
+
* Spec Section 7.5.
|
|
332
|
+
*/
|
|
333
|
+
export interface ScopeElevateResult {
|
|
334
|
+
/** Whether the scope was approved */
|
|
335
|
+
approved: boolean;
|
|
336
|
+
|
|
337
|
+
/** The payload from the request, returned on approval */
|
|
338
|
+
payload?: Record<string, unknown>;
|
|
339
|
+
|
|
340
|
+
/** Present if approved: false */
|
|
341
|
+
reason?: string;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ============================================================================
|
|
345
|
+
// Section 8 — State Management
|
|
346
|
+
// ============================================================================
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Checkpoint information returned in tool call responses.
|
|
350
|
+
* Spec Section 8.2.
|
|
351
|
+
*/
|
|
352
|
+
export interface StateCheckpoint {
|
|
353
|
+
/** Checkpoint identifier */
|
|
354
|
+
checkpoint: string;
|
|
355
|
+
|
|
356
|
+
/** Parent checkpoint (null for root) */
|
|
357
|
+
parent: string | null;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Full state data (for host-managed state).
|
|
361
|
+
* Mutually exclusive with `patch`.
|
|
362
|
+
*/
|
|
363
|
+
data?: unknown;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* JSON Patch (RFC 6902) delta from parent (for host-managed state).
|
|
367
|
+
* Mutually exclusive with `data`.
|
|
368
|
+
*/
|
|
369
|
+
patch?: JsonPatchOperation[];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* JSON Patch operation (RFC 6902).
|
|
374
|
+
*/
|
|
375
|
+
export interface JsonPatchOperation {
|
|
376
|
+
op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test';
|
|
377
|
+
path: string;
|
|
378
|
+
value?: unknown;
|
|
379
|
+
from?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* state/rollback params (Host → Server, Request).
|
|
384
|
+
* Spec Section 8.5.
|
|
385
|
+
*/
|
|
386
|
+
export interface StateRollbackParams {
|
|
387
|
+
/** Feature set to rollback */
|
|
388
|
+
featureSet: string;
|
|
389
|
+
|
|
390
|
+
/** Checkpoint to rollback to */
|
|
391
|
+
checkpoint: string;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* state/rollback result (Server → Host).
|
|
396
|
+
* Spec Section 8.6.
|
|
397
|
+
*/
|
|
398
|
+
export interface StateRollbackResult {
|
|
399
|
+
/** Checkpoint that was rolled back to */
|
|
400
|
+
checkpoint: string;
|
|
401
|
+
|
|
402
|
+
/** Whether rollback succeeded */
|
|
403
|
+
success: boolean;
|
|
404
|
+
|
|
405
|
+
/** Reason for failure (present if success: false) */
|
|
406
|
+
reason?: string;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// ============================================================================
|
|
410
|
+
// Section 9 — Push Events
|
|
411
|
+
// ============================================================================
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* push/event params (Server → Host, Request).
|
|
415
|
+
* Spec Section 9.1.
|
|
416
|
+
*/
|
|
417
|
+
export interface PushEventParams {
|
|
418
|
+
/** Declaring feature set */
|
|
419
|
+
featureSet: string;
|
|
420
|
+
|
|
421
|
+
/** Unique event identifier (for idempotency) */
|
|
422
|
+
eventId: string;
|
|
423
|
+
|
|
424
|
+
/** When the event occurred (ISO 8601) */
|
|
425
|
+
timestamp: string;
|
|
426
|
+
|
|
427
|
+
/** Provenance metadata (server-defined) */
|
|
428
|
+
origin?: Record<string, unknown>;
|
|
429
|
+
|
|
430
|
+
/** Event payload */
|
|
431
|
+
payload: {
|
|
432
|
+
/** Content for the model to interpret */
|
|
433
|
+
content: McplContentBlock[];
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* push/event result (Host → Server).
|
|
439
|
+
* Spec Section 9.3.
|
|
440
|
+
*/
|
|
441
|
+
export interface PushEventResult {
|
|
442
|
+
/** Whether the event was accepted */
|
|
443
|
+
accepted: boolean;
|
|
444
|
+
|
|
445
|
+
/** Present if inference was triggered */
|
|
446
|
+
inferenceId?: string;
|
|
447
|
+
|
|
448
|
+
/** Present if accepted: false */
|
|
449
|
+
reason?: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ============================================================================
|
|
453
|
+
// Section 10 — Context Hooks
|
|
454
|
+
// ============================================================================
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Model information as provided in context hook calls.
|
|
458
|
+
* Distinct from membrane's ModelInfo which tracks requested vs actual model.
|
|
459
|
+
* Spec Section 10.1.
|
|
460
|
+
*/
|
|
461
|
+
export interface McplModelInfo {
|
|
462
|
+
/** Model identifier (e.g., "claude-opus-4-5-20251101") */
|
|
463
|
+
id: string;
|
|
464
|
+
|
|
465
|
+
/** Model vendor (e.g., "anthropic") */
|
|
466
|
+
vendor: string;
|
|
467
|
+
|
|
468
|
+
/** Context window size in tokens */
|
|
469
|
+
contextWindow: number;
|
|
470
|
+
|
|
471
|
+
/** Model capabilities (e.g., ["vision", "tools"]) */
|
|
472
|
+
capabilities: string[];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* context/beforeInference params (Host → Server, Request).
|
|
477
|
+
* Spec Section 10.1.
|
|
478
|
+
*/
|
|
479
|
+
export interface BeforeInferenceParams {
|
|
480
|
+
/** Unique identifier for this inference */
|
|
481
|
+
inferenceId: string;
|
|
482
|
+
|
|
483
|
+
/** Persistent across turns */
|
|
484
|
+
conversationId: string;
|
|
485
|
+
|
|
486
|
+
/** 0-indexed turn number */
|
|
487
|
+
turnIndex: number;
|
|
488
|
+
|
|
489
|
+
/** User input (null for continued generation) */
|
|
490
|
+
userMessage: string | null;
|
|
491
|
+
|
|
492
|
+
/** Current model metadata */
|
|
493
|
+
model: McplModelInfo;
|
|
494
|
+
|
|
495
|
+
/** Channel context (Section 14.4, optional) */
|
|
496
|
+
channels?: ChannelContext;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* A context injection as returned by an MCPL server.
|
|
501
|
+
* This is the wire format — it gets converted to context-manager's
|
|
502
|
+
* ContextInjection (which uses membrane ContentBlock[]) by the host.
|
|
503
|
+
* Spec Section 10.4.
|
|
504
|
+
*/
|
|
505
|
+
export interface McplContextInjection {
|
|
506
|
+
/** Server-defined namespace */
|
|
507
|
+
namespace: string;
|
|
508
|
+
|
|
509
|
+
/** Where to inject */
|
|
510
|
+
position: 'system' | 'beforeUser' | 'afterUser';
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Content to inject.
|
|
514
|
+
* May be a plain string (shorthand for a single text block) or content blocks.
|
|
515
|
+
*/
|
|
516
|
+
content: string | McplContentBlock[];
|
|
517
|
+
|
|
518
|
+
/** Arbitrary metadata (passed through) */
|
|
519
|
+
metadata?: Record<string, unknown>;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* context/beforeInference result (Server → Host).
|
|
524
|
+
* Spec Section 10.2.
|
|
525
|
+
*/
|
|
526
|
+
export interface BeforeInferenceResult {
|
|
527
|
+
/** Feature set that provided this response */
|
|
528
|
+
featureSet: string;
|
|
529
|
+
|
|
530
|
+
/** Context injections to apply */
|
|
531
|
+
contextInjections: McplContextInjection[];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* context/afterInference params (Host → Server, Request or Notification).
|
|
536
|
+
* Spec Section 10.5.
|
|
537
|
+
*/
|
|
538
|
+
export interface AfterInferenceParams {
|
|
539
|
+
/** Inference identifier (matches beforeInference) */
|
|
540
|
+
inferenceId: string;
|
|
541
|
+
|
|
542
|
+
/** Persistent across turns */
|
|
543
|
+
conversationId: string;
|
|
544
|
+
|
|
545
|
+
/** 0-indexed turn number */
|
|
546
|
+
turnIndex: number;
|
|
547
|
+
|
|
548
|
+
/** Original user input */
|
|
549
|
+
userMessage: string | null;
|
|
550
|
+
|
|
551
|
+
/** Generated assistant response */
|
|
552
|
+
assistantMessage: string;
|
|
553
|
+
|
|
554
|
+
/** Model metadata */
|
|
555
|
+
model: McplModelInfo;
|
|
556
|
+
|
|
557
|
+
/** Token usage */
|
|
558
|
+
usage: {
|
|
559
|
+
inputTokens: number;
|
|
560
|
+
outputTokens: number;
|
|
561
|
+
cacheCreationTokens?: number;
|
|
562
|
+
cacheReadTokens?: number;
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* context/afterInference result (Server → Host, only for blocking hooks).
|
|
568
|
+
* Spec Section 10.5.
|
|
569
|
+
*/
|
|
570
|
+
export interface AfterInferenceResult {
|
|
571
|
+
/** Feature set that provided this response */
|
|
572
|
+
featureSet: string;
|
|
573
|
+
|
|
574
|
+
/** Modified response text (replaces assistantMessage if present) */
|
|
575
|
+
modifiedResponse?: string;
|
|
576
|
+
|
|
577
|
+
/** Arbitrary metadata */
|
|
578
|
+
metadata?: Record<string, unknown>;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// ============================================================================
|
|
582
|
+
// Section 11 — Server-Initiated Inference
|
|
583
|
+
// ============================================================================
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* A message in an MCPL inference request.
|
|
587
|
+
* Simpler than membrane's NormalizedMessage — just role + content string.
|
|
588
|
+
*/
|
|
589
|
+
export interface McplMessage {
|
|
590
|
+
role: 'user' | 'assistant';
|
|
591
|
+
content: string;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* inference/request params (Server → Host, Request).
|
|
596
|
+
* Prefixed to avoid collision with API's InferenceRequestParams.
|
|
597
|
+
* Spec Section 11.1.
|
|
598
|
+
*/
|
|
599
|
+
export interface McplInferenceRequestParams {
|
|
600
|
+
/** Declaring feature set */
|
|
601
|
+
featureSet: string;
|
|
602
|
+
|
|
603
|
+
/** Associate with conversation (optional) */
|
|
604
|
+
conversationId?: string;
|
|
605
|
+
|
|
606
|
+
/** Stream response (default: false) */
|
|
607
|
+
stream?: boolean;
|
|
608
|
+
|
|
609
|
+
/** Messages for inference */
|
|
610
|
+
messages: McplMessage[];
|
|
611
|
+
|
|
612
|
+
/** Advisory preferences (host may ignore) */
|
|
613
|
+
preferences?: McplInferencePreferences;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Advisory preferences for server-initiated inference.
|
|
618
|
+
* Spec Section 11.2.
|
|
619
|
+
*/
|
|
620
|
+
export interface McplInferencePreferences {
|
|
621
|
+
/** Max output tokens */
|
|
622
|
+
maxTokens?: number;
|
|
623
|
+
|
|
624
|
+
/** Sampling temperature */
|
|
625
|
+
temperature?: number;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Additional advisory keys (e.g., model, modelTier, costTier).
|
|
629
|
+
* Host-defined and not guaranteed to be honored.
|
|
630
|
+
*/
|
|
631
|
+
[key: string]: unknown;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* inference/request result (Host → Server).
|
|
636
|
+
* Spec Section 11.3.
|
|
637
|
+
*/
|
|
638
|
+
export interface McplInferenceRequestResult {
|
|
639
|
+
/** Generated content */
|
|
640
|
+
content: string;
|
|
641
|
+
|
|
642
|
+
/** Actual model used */
|
|
643
|
+
model: string;
|
|
644
|
+
|
|
645
|
+
/** Why generation stopped */
|
|
646
|
+
finishReason: 'end_turn' | 'max_tokens' | 'stop_sequence';
|
|
647
|
+
|
|
648
|
+
/** Token usage */
|
|
649
|
+
usage: {
|
|
650
|
+
inputTokens: number;
|
|
651
|
+
outputTokens: number;
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* inference/chunk params (Host → Server, Notification).
|
|
657
|
+
* Sent during streaming inference.
|
|
658
|
+
* Spec Section 11.4.
|
|
659
|
+
*/
|
|
660
|
+
export interface InferenceChunkParams {
|
|
661
|
+
/** ID of the original inference/request */
|
|
662
|
+
requestId: string | number;
|
|
663
|
+
|
|
664
|
+
/** Chunk index (0-based) */
|
|
665
|
+
index: number;
|
|
666
|
+
|
|
667
|
+
/** Text delta */
|
|
668
|
+
delta: string;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// ============================================================================
|
|
672
|
+
// Section 12 — Model Information
|
|
673
|
+
// ============================================================================
|
|
674
|
+
|
|
675
|
+
// model/info has no params (empty object).
|
|
676
|
+
// The result reuses McplModelInfo.
|
|
677
|
+
|
|
678
|
+
// ============================================================================
|
|
679
|
+
// Section 14 — Channels
|
|
680
|
+
// ============================================================================
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Descriptor for a channel registered by an MCPL server.
|
|
684
|
+
* Spec Section 14.2.
|
|
685
|
+
*/
|
|
686
|
+
export interface ChannelDescriptor {
|
|
687
|
+
/** Unique within this connection (e.g., "discord:#general") */
|
|
688
|
+
id: string;
|
|
689
|
+
|
|
690
|
+
/** Platform/provider type (e.g., "discord", "telegram", "ui") */
|
|
691
|
+
type: string;
|
|
692
|
+
|
|
693
|
+
/** Human-readable label */
|
|
694
|
+
label: string;
|
|
695
|
+
|
|
696
|
+
/** Message direction */
|
|
697
|
+
direction: 'outbound' | 'inbound' | 'bidirectional';
|
|
698
|
+
|
|
699
|
+
/** Platform-specific address (e.g., { guild: "acme", channel: "#general" }) */
|
|
700
|
+
address?: Record<string, unknown>;
|
|
701
|
+
|
|
702
|
+
/** Arbitrary metadata */
|
|
703
|
+
metadata?: Record<string, unknown>;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Channel context included in beforeInference params.
|
|
708
|
+
* Spec Section 14.4.
|
|
709
|
+
*/
|
|
710
|
+
export interface ChannelContext {
|
|
711
|
+
/** Channel that triggered this inference */
|
|
712
|
+
incoming?: {
|
|
713
|
+
channelId: string;
|
|
714
|
+
messageId: string;
|
|
715
|
+
threadId?: string;
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
/** Default channel for outgoing messages */
|
|
719
|
+
defaultOutgoing?: {
|
|
720
|
+
channelId: string;
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
/** All candidate channels for this inference */
|
|
724
|
+
candidates?: string[];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* channels/register params (Server → Host, Request).
|
|
729
|
+
* Spec Section 14.3.
|
|
730
|
+
*/
|
|
731
|
+
export interface ChannelsRegisterParams {
|
|
732
|
+
channels: ChannelDescriptor[];
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* channels/register result (Host → Server).
|
|
737
|
+
*/
|
|
738
|
+
export interface ChannelsRegisterResult {
|
|
739
|
+
registered: string[];
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* channels/changed params (Server → Host, Notification).
|
|
744
|
+
* Spec Section 14.3.
|
|
745
|
+
*/
|
|
746
|
+
export interface ChannelsChangedParams {
|
|
747
|
+
added?: ChannelDescriptor[];
|
|
748
|
+
removed?: string[];
|
|
749
|
+
updated?: ChannelDescriptor[];
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* channels/list result (Either direction, Request).
|
|
754
|
+
* Spec Section 14.3.
|
|
755
|
+
*/
|
|
756
|
+
export interface ChannelsListResult {
|
|
757
|
+
channels: ChannelDescriptor[];
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* channels/open params (Host → Server, Request).
|
|
762
|
+
* Spec Section 14.3.
|
|
763
|
+
*/
|
|
764
|
+
export interface ChannelsOpenParams {
|
|
765
|
+
type: string;
|
|
766
|
+
address?: Record<string, unknown>;
|
|
767
|
+
metadata?: Record<string, unknown>;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* channels/open result (Server → Host).
|
|
772
|
+
*/
|
|
773
|
+
export interface ChannelsOpenResult {
|
|
774
|
+
channel: ChannelDescriptor;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* channels/close params (Host → Server, Request).
|
|
779
|
+
* Spec Section 14.3.
|
|
780
|
+
*/
|
|
781
|
+
export interface ChannelsCloseParams {
|
|
782
|
+
channelId: string;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* channels/close result (Server → Host).
|
|
787
|
+
*/
|
|
788
|
+
export interface ChannelsCloseResult {
|
|
789
|
+
closed: boolean;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* channels/outgoing/chunk params (Host → Server, Notification).
|
|
794
|
+
* For observers receiving moderated deltas.
|
|
795
|
+
* Spec Section 14.3.
|
|
796
|
+
*/
|
|
797
|
+
export interface ChannelsOutgoingChunkParams {
|
|
798
|
+
inferenceId: string;
|
|
799
|
+
conversationId: string;
|
|
800
|
+
channelId: string;
|
|
801
|
+
index: number;
|
|
802
|
+
delta: string;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* channels/outgoing/complete params (Host → Server, Notification).
|
|
807
|
+
* For observers receiving final moderated content.
|
|
808
|
+
* Spec Section 14.3.
|
|
809
|
+
*/
|
|
810
|
+
export interface ChannelsOutgoingCompleteParams {
|
|
811
|
+
inferenceId: string;
|
|
812
|
+
conversationId: string;
|
|
813
|
+
channelId: string;
|
|
814
|
+
content: McplContentBlock[];
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* channels/publish params (Host → Server, Notification or Request).
|
|
819
|
+
* Asks connector server to deliver content to a channel.
|
|
820
|
+
* Spec Section 14.3.
|
|
821
|
+
*/
|
|
822
|
+
export interface ChannelsPublishParams {
|
|
823
|
+
conversationId: string;
|
|
824
|
+
channelId: string;
|
|
825
|
+
stream?: boolean;
|
|
826
|
+
content: McplContentBlock[];
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* channels/publish result (Server → Host, when sent as Request).
|
|
831
|
+
*/
|
|
832
|
+
export interface ChannelsPublishResult {
|
|
833
|
+
delivered: boolean;
|
|
834
|
+
messageId?: string;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* A single inbound message from a channel.
|
|
839
|
+
* Used inside channels/incoming params.
|
|
840
|
+
* Spec Section 14.3.
|
|
841
|
+
*/
|
|
842
|
+
export interface ChannelIncomingMessage {
|
|
843
|
+
/** Channel this message came from */
|
|
844
|
+
channelId: string;
|
|
845
|
+
|
|
846
|
+
/** Unique message ID from the platform */
|
|
847
|
+
messageId: string;
|
|
848
|
+
|
|
849
|
+
/** Thread/conversation ID within the channel */
|
|
850
|
+
threadId?: string;
|
|
851
|
+
|
|
852
|
+
/** Message author */
|
|
853
|
+
author: {
|
|
854
|
+
id: string;
|
|
855
|
+
name: string;
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
/** When the message was sent (ISO 8601) */
|
|
859
|
+
timestamp: string;
|
|
860
|
+
|
|
861
|
+
/** Message content */
|
|
862
|
+
content: McplContentBlock[];
|
|
863
|
+
|
|
864
|
+
/** Platform-specific metadata */
|
|
865
|
+
metadata?: Record<string, unknown>;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* channels/incoming params (Server → Host, Request).
|
|
870
|
+
* Supports batching for busy channels.
|
|
871
|
+
* Spec Section 14.3.
|
|
872
|
+
*/
|
|
873
|
+
export interface ChannelsIncomingParams {
|
|
874
|
+
messages: ChannelIncomingMessage[];
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* channels/incoming result (Host → Server).
|
|
879
|
+
* Per-message results for partial acceptance.
|
|
880
|
+
*/
|
|
881
|
+
export interface ChannelsIncomingResult {
|
|
882
|
+
results: ChannelIncomingMessageResult[];
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/** Result for a single incoming message. */
|
|
886
|
+
export interface ChannelIncomingMessageResult {
|
|
887
|
+
messageId: string;
|
|
888
|
+
accepted: boolean;
|
|
889
|
+
conversationId?: string;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// ============================================================================
|
|
893
|
+
// Section 11.5 — Inference Routing Policy (Host Configuration)
|
|
894
|
+
// ============================================================================
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Policy for routing server-initiated inference requests to models.
|
|
898
|
+
* Non-normative; host-defined. See Spec Section 11.5.
|
|
899
|
+
*/
|
|
900
|
+
export interface InferenceRoutingPolicy {
|
|
901
|
+
/** Default model for all inference requests */
|
|
902
|
+
default: string;
|
|
903
|
+
|
|
904
|
+
/** Model override per feature set name */
|
|
905
|
+
byFeature?: Record<string, string>;
|
|
906
|
+
|
|
907
|
+
/** Model override per pattern (e.g., "memory.*" → "claude-haiku-4-5") */
|
|
908
|
+
wildcards?: Record<string, string>;
|
|
909
|
+
|
|
910
|
+
/** Model override per conversation ID */
|
|
911
|
+
overrides?: Record<string, string>;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// ============================================================================
|
|
915
|
+
// MCPL Method Names (string constants for routing)
|
|
916
|
+
// ============================================================================
|
|
917
|
+
|
|
918
|
+
/** All MCPL method names as defined in the spec. */
|
|
919
|
+
export const McplMethod = {
|
|
920
|
+
// Push events (Server → Host)
|
|
921
|
+
PushEvent: 'push/event',
|
|
922
|
+
|
|
923
|
+
// Context hooks (Host → Server)
|
|
924
|
+
BeforeInference: 'context/beforeInference',
|
|
925
|
+
AfterInference: 'context/afterInference',
|
|
926
|
+
|
|
927
|
+
// Server-initiated inference (Server → Host / Host → Server)
|
|
928
|
+
InferenceRequest: 'inference/request',
|
|
929
|
+
InferenceChunk: 'inference/chunk',
|
|
930
|
+
|
|
931
|
+
// Model info (Server → Host)
|
|
932
|
+
ModelInfo: 'model/info',
|
|
933
|
+
|
|
934
|
+
// Feature sets
|
|
935
|
+
FeatureSetsUpdate: 'featureSets/update',
|
|
936
|
+
FeatureSetsChanged: 'featureSets/changed',
|
|
937
|
+
|
|
938
|
+
// Scoped access (Server → Host)
|
|
939
|
+
ScopeElevate: 'scope/elevate',
|
|
940
|
+
|
|
941
|
+
// State management (Host → Server)
|
|
942
|
+
StateRollback: 'state/rollback',
|
|
943
|
+
|
|
944
|
+
// Channels
|
|
945
|
+
ChannelsRegister: 'channels/register',
|
|
946
|
+
ChannelsChanged: 'channels/changed',
|
|
947
|
+
ChannelsList: 'channels/list',
|
|
948
|
+
ChannelsOpen: 'channels/open',
|
|
949
|
+
ChannelsClose: 'channels/close',
|
|
950
|
+
ChannelsOutgoingChunk: 'channels/outgoing/chunk',
|
|
951
|
+
ChannelsOutgoingComplete: 'channels/outgoing/complete',
|
|
952
|
+
ChannelsPublish: 'channels/publish',
|
|
953
|
+
ChannelsIncoming: 'channels/incoming',
|
|
954
|
+
ChannelsTyping: 'channels/typing',
|
|
955
|
+
} as const;
|
|
956
|
+
|
|
957
|
+
export type McplMethodName = (typeof McplMethod)[keyof typeof McplMethod];
|
|
958
|
+
|
|
959
|
+
// ============================================================================
|
|
960
|
+
// MCP Standard Methods (not MCPL-specific, but needed for tool integration)
|
|
961
|
+
// ============================================================================
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Standard MCP tool definition as returned by `tools/list`.
|
|
965
|
+
*/
|
|
966
|
+
export interface McpToolDefinition {
|
|
967
|
+
name: string;
|
|
968
|
+
description?: string;
|
|
969
|
+
inputSchema: Record<string, unknown>;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Standard MCP `tools/call` result.
|
|
974
|
+
*/
|
|
975
|
+
export interface McpToolCallResult {
|
|
976
|
+
content: McpToolResultContent[];
|
|
977
|
+
isError?: boolean;
|
|
978
|
+
/** State checkpoint returned by stateful tools (Section 8.2). */
|
|
979
|
+
state?: StateCheckpoint;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* A single content block in an MCP tool result.
|
|
984
|
+
*/
|
|
985
|
+
export interface McpToolResultContent {
|
|
986
|
+
type: 'text' | 'image' | 'resource';
|
|
987
|
+
text?: string;
|
|
988
|
+
data?: string;
|
|
989
|
+
mimeType?: string;
|
|
990
|
+
uri?: string;
|
|
991
|
+
}
|