@meridian-flow/runtime 0.1.2 → 0.3.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 +7 -6
- package/dist/gateway/adapters/anthropic/request-map.js +4 -6
- package/dist/gateway/adapters/anthropic/stream-collect.d.ts +0 -9
- package/dist/gateway/adapters/anthropic/stream-collect.js +0 -5
- package/dist/gateway/adapters/openai/stream-collect.js +1 -2
- package/dist/gateway/adapters/provider-http-error.d.ts +5 -1
- package/dist/gateway/adapters/provider-http-error.js +9 -2
- package/dist/gateway/domain/types.d.ts +14 -8
- package/dist/gateway/helpers/messages.d.ts +2 -2
- package/dist/gateway/mock-script.d.ts +36 -36
- package/dist/mcp/client.d.ts +2 -0
- package/dist/mcp/client.js +279 -0
- package/dist/mcp/content.d.ts +7 -0
- package/dist/mcp/content.js +54 -0
- package/dist/mcp/fault.d.ts +6 -0
- package/dist/mcp/fault.js +48 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/pin.d.ts +31 -0
- package/dist/mcp/pin.js +153 -0
- package/dist/mcp/reply-limit.d.ts +14 -0
- package/dist/mcp/reply-limit.js +59 -0
- package/dist/mcp/session.d.ts +96 -0
- package/dist/mcp/session.js +280 -0
- package/dist/mcp/types.d.ts +182 -0
- package/dist/mcp/types.js +1 -0
- package/package.json +19 -12
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { Client, SdkError, SdkErrorCode, StreamableHTTPClientTransport, } from "@modelcontextprotocol/client";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
3
|
+
import { limitReplies } from "./reply-limit.js";
|
|
4
|
+
// The SDK's own timeout would otherwise default to 60 s; every call's deadline is the client's.
|
|
5
|
+
const NO_SDK_TIMEOUT = 2 ** 31 - 1;
|
|
6
|
+
const BUFFER_EXCEEDED = "ReadBuffer exceeded";
|
|
7
|
+
// Marks a list or ping request: the SDK may rebuild `params` but keeps what is in `_meta`.
|
|
8
|
+
const REF_KEY = "io.meridian-flow/ref";
|
|
9
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
function lines(onLine) {
|
|
11
|
+
let rest = "";
|
|
12
|
+
return (chunk) => {
|
|
13
|
+
const parts = (rest + chunk.toString("utf8")).split("\n");
|
|
14
|
+
rest = parts.pop() ?? "";
|
|
15
|
+
for (const part of parts)
|
|
16
|
+
if (part.trim() !== "")
|
|
17
|
+
onLine(part.replace(/\r$/, ""));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A live link to one MCP server. It reads each reply under the SDK: the transport's `send` names
|
|
22
|
+
* the request id of the request being made (a call is matched through the identity of its
|
|
23
|
+
* `arguments`, which reaches `send` unchanged; a list or ping through a reference in `_meta`,
|
|
24
|
+
* which survives the SDK rebuilding `params`), and the incoming-message hook keeps the raw
|
|
25
|
+
* response for that id. The outcome is decided from that raw message, not from what the SDK made
|
|
26
|
+
* of it.
|
|
27
|
+
*
|
|
28
|
+
* A session is `ended` from the moment anything starts ending it (close, idle timer, a reply over
|
|
29
|
+
* the limit, the transport closing), and leaves its registry then: the teardown that follows may
|
|
30
|
+
* take seconds and must not receive new requests.
|
|
31
|
+
*/
|
|
32
|
+
export class Session {
|
|
33
|
+
key;
|
|
34
|
+
cfg;
|
|
35
|
+
idleCloseMs;
|
|
36
|
+
/** Set by the registry; called once, when the session starts ending. */
|
|
37
|
+
onEnded;
|
|
38
|
+
ended = false;
|
|
39
|
+
server = { name: "", version: "" };
|
|
40
|
+
protocolVersion = "";
|
|
41
|
+
instructions;
|
|
42
|
+
client;
|
|
43
|
+
transport;
|
|
44
|
+
waiting = new Map();
|
|
45
|
+
byId = new Map();
|
|
46
|
+
aborts = new Map();
|
|
47
|
+
closing;
|
|
48
|
+
refs = 0;
|
|
49
|
+
active = 0;
|
|
50
|
+
idleTimer;
|
|
51
|
+
constructor(key, spec, cfg, idleCloseMs) {
|
|
52
|
+
this.key = key;
|
|
53
|
+
this.cfg = cfg;
|
|
54
|
+
this.idleCloseMs = idleCloseMs;
|
|
55
|
+
this.transport = this.makeTransport(spec);
|
|
56
|
+
this.client = new Client(cfg.clientInfo, {
|
|
57
|
+
// Announces no sampling, elicitation or roots: a server cannot ask the model or the user.
|
|
58
|
+
capabilities: {},
|
|
59
|
+
versionNegotiation: { mode: "legacy" },
|
|
60
|
+
});
|
|
61
|
+
this.tap();
|
|
62
|
+
}
|
|
63
|
+
/** Starts the process or the HTTP session and does the handshake. Throws what the SDK threw. */
|
|
64
|
+
static async open(server, cfg, opts) {
|
|
65
|
+
const session = new Session(server.key, server.spec, cfg, opts.idleCloseMs);
|
|
66
|
+
try {
|
|
67
|
+
await session.client.connect(session.transport, {
|
|
68
|
+
timeout: opts.timeoutMs,
|
|
69
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
session.ended = true;
|
|
74
|
+
clearTimeout(session.idleTimer);
|
|
75
|
+
await session.client.close().catch(() => { });
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
const info = session.client.getServerVersion();
|
|
79
|
+
session.server = { name: info?.name ?? "", version: info?.version ?? "" };
|
|
80
|
+
session.protocolVersion = session.client.getNegotiatedProtocolVersion() ?? "";
|
|
81
|
+
session.instructions = session.client.getInstructions();
|
|
82
|
+
cfg.onEvent?.({
|
|
83
|
+
type: "session_started",
|
|
84
|
+
key: server.key,
|
|
85
|
+
transport: server.spec.transport,
|
|
86
|
+
});
|
|
87
|
+
session.armIdle();
|
|
88
|
+
return session;
|
|
89
|
+
}
|
|
90
|
+
get transportKind() {
|
|
91
|
+
return this.transport instanceof StreamableHTTPClientTransport ? "http" : "stdio";
|
|
92
|
+
}
|
|
93
|
+
/** An HTTP server that issued a session id can forget it; a stateless one cannot. */
|
|
94
|
+
get hasServerSession() {
|
|
95
|
+
return this.transport instanceof StreamableHTTPClientTransport && !!this.transport.sessionId;
|
|
96
|
+
}
|
|
97
|
+
makeTransport(spec) {
|
|
98
|
+
const { cfg, key } = this;
|
|
99
|
+
if (spec.transport === "stdio") {
|
|
100
|
+
const transport = new StdioClientTransport({
|
|
101
|
+
command: spec.command,
|
|
102
|
+
...(spec.args ? { args: spec.args } : {}),
|
|
103
|
+
...(spec.env ? { env: spec.env } : {}),
|
|
104
|
+
...(spec.cwd ? { cwd: spec.cwd } : {}),
|
|
105
|
+
stderr: "pipe",
|
|
106
|
+
maxBufferSize: cfg.maxReplyBytes,
|
|
107
|
+
});
|
|
108
|
+
transport.stderr?.on("data", lines((line) => cfg.onEvent?.({ type: "stderr", key, line })));
|
|
109
|
+
return transport;
|
|
110
|
+
}
|
|
111
|
+
const { auth, headers } = spec;
|
|
112
|
+
return new StreamableHTTPClientTransport(new URL(spec.url), {
|
|
113
|
+
fetch: limitReplies(cfg.fetch, cfg.maxReplyBytes, (id, bytes) => this.replyTooLarge(id, bytes)),
|
|
114
|
+
...(headers ? { requestInit: { headers } } : {}),
|
|
115
|
+
...(auth
|
|
116
|
+
? {
|
|
117
|
+
authProvider: {
|
|
118
|
+
token: () => auth.token(),
|
|
119
|
+
...(auth.refresh
|
|
120
|
+
? { onUnauthorized: async () => void (await auth.refresh?.()) }
|
|
121
|
+
: {}),
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
: {}),
|
|
125
|
+
// Never "follow": fetch would carry the token and custom headers to another origin.
|
|
126
|
+
redirectPolicy: "same-origin",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
tap() {
|
|
130
|
+
const { transport } = this;
|
|
131
|
+
// Set before connect(): the SDK chains the hooks it finds and runs ours first.
|
|
132
|
+
transport.onmessage = (message) => {
|
|
133
|
+
if (!("id" in message) || message.id === undefined || "method" in message)
|
|
134
|
+
return;
|
|
135
|
+
const exchange = this.byId.get(message.id);
|
|
136
|
+
if (!exchange)
|
|
137
|
+
return;
|
|
138
|
+
if ("result" in message && isObject(message.result))
|
|
139
|
+
exchange.raw = { result: message.result };
|
|
140
|
+
else if ("error" in message)
|
|
141
|
+
exchange.raw = { error: message.error };
|
|
142
|
+
};
|
|
143
|
+
transport.onerror = (error) => {
|
|
144
|
+
// The stdio reader closes the transport when a line passes the limit, and says so only here.
|
|
145
|
+
if (error.message.startsWith(BUFFER_EXCEEDED))
|
|
146
|
+
this.stdioReplyTooLarge();
|
|
147
|
+
};
|
|
148
|
+
this.client.onclose = () => this.finish("disconnected");
|
|
149
|
+
const send = transport.send.bind(transport);
|
|
150
|
+
transport.send = async (message, options) => {
|
|
151
|
+
let exchange;
|
|
152
|
+
if ("method" in message && "id" in message && message.id !== undefined) {
|
|
153
|
+
const params = message.params;
|
|
154
|
+
const token = message.method === "tools/call" ? params?.arguments : params?._meta?.[REF_KEY];
|
|
155
|
+
exchange =
|
|
156
|
+
typeof token === "string" || isObject(token) ? this.waiting.get(token) : undefined;
|
|
157
|
+
if (exchange) {
|
|
158
|
+
exchange.sent = true;
|
|
159
|
+
exchange.id = message.id;
|
|
160
|
+
this.byId.set(message.id, exchange);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
await send(message, options);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
// Not connected means nothing was written, so the request can safely go to a new session.
|
|
168
|
+
if (exchange && error instanceof SdkError && error.code === SdkErrorCode.NotConnected)
|
|
169
|
+
exchange.sent = false;
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
replyTooLarge(id, bytes) {
|
|
175
|
+
const exchange = this.byId.get(id);
|
|
176
|
+
if (!exchange)
|
|
177
|
+
return;
|
|
178
|
+
exchange.tooLarge = bytes;
|
|
179
|
+
this.aborts.get(exchange)?.();
|
|
180
|
+
}
|
|
181
|
+
stdioReplyTooLarge() {
|
|
182
|
+
// Which call's reply it was is known only when one call is in flight.
|
|
183
|
+
const only = this.byId.size === 1 ? [...this.byId.values()][0] : undefined;
|
|
184
|
+
if (only)
|
|
185
|
+
only.tooLarge = this.cfg.maxReplyBytes + 1;
|
|
186
|
+
void this.close("too_large");
|
|
187
|
+
}
|
|
188
|
+
/** The one place a session starts ending. Synchronous, so no later request can reach it. */
|
|
189
|
+
finish(reason) {
|
|
190
|
+
if (this.ended)
|
|
191
|
+
return;
|
|
192
|
+
this.ended = true;
|
|
193
|
+
clearTimeout(this.idleTimer);
|
|
194
|
+
this.cfg.onEvent?.({ type: "session_ended", key: this.key, reason });
|
|
195
|
+
this.onEnded?.(reason);
|
|
196
|
+
// No more replies are coming, so the calls in flight settle now, not when a child process
|
|
197
|
+
// finally exits. A forgotten session is different: each call's own reply is still on the wire.
|
|
198
|
+
if (reason === "forgotten")
|
|
199
|
+
return;
|
|
200
|
+
for (const [exchange, abort] of this.aborts) {
|
|
201
|
+
exchange.lost = true;
|
|
202
|
+
abort();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
armIdle() {
|
|
206
|
+
clearTimeout(this.idleTimer);
|
|
207
|
+
if (this.idleCloseMs <= 0 || this.active > 0 || this.ended)
|
|
208
|
+
return;
|
|
209
|
+
this.idleTimer = setTimeout(() => void this.close("idle"), this.idleCloseMs);
|
|
210
|
+
this.idleTimer.unref();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Runs one request. `token` is what `send` will see to tell it from the others: the `arguments`
|
|
214
|
+
* object of a call, or the reference `run` put in a list or ping's `_meta`. Never throws: the
|
|
215
|
+
* Exchange says what happened.
|
|
216
|
+
*/
|
|
217
|
+
async exchange(token, signal, run) {
|
|
218
|
+
const exchange = { sent: false };
|
|
219
|
+
const own = new AbortController();
|
|
220
|
+
this.active++;
|
|
221
|
+
clearTimeout(this.idleTimer);
|
|
222
|
+
this.waiting.set(token, exchange);
|
|
223
|
+
this.aborts.set(exchange, () => own.abort());
|
|
224
|
+
try {
|
|
225
|
+
await run(AbortSignal.any([signal, own.signal]), NO_SDK_TIMEOUT);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
exchange.error = error;
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
this.waiting.delete(token);
|
|
232
|
+
if (exchange.id !== undefined)
|
|
233
|
+
this.byId.delete(exchange.id);
|
|
234
|
+
this.aborts.delete(exchange);
|
|
235
|
+
this.active--;
|
|
236
|
+
this.armIdle();
|
|
237
|
+
}
|
|
238
|
+
return exchange;
|
|
239
|
+
}
|
|
240
|
+
async call(tool, name, args, signal) {
|
|
241
|
+
// The pinned tool, without outputSchema: handing it over also makes the SDK check the reply
|
|
242
|
+
// against that schema, which would throw away a reply from a tool that ran.
|
|
243
|
+
const { outputSchema: _dropped, ...definition } = tool;
|
|
244
|
+
const params = { name, arguments: args };
|
|
245
|
+
return this.exchange(args, signal, (signal, timeout) => this.client.callTool(params, {
|
|
246
|
+
signal,
|
|
247
|
+
timeout,
|
|
248
|
+
toolDefinition: definition,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
/** A request without arguments of its own: `_meta` carries what tells it from the others. */
|
|
252
|
+
plain(method, params, signal) {
|
|
253
|
+
const ref = `${++this.refs}`;
|
|
254
|
+
const withRef = { ...params, _meta: { [REF_KEY]: ref } };
|
|
255
|
+
return this.exchange(ref, signal, (signal, timeout) => this.client.request({ method, params: withRef }, { signal, timeout }));
|
|
256
|
+
}
|
|
257
|
+
listPage(cursor, signal) {
|
|
258
|
+
return this.plain("tools/list", cursor === undefined ? {} : { cursor }, signal);
|
|
259
|
+
}
|
|
260
|
+
ping(signal) {
|
|
261
|
+
return this.plain("ping", {}, signal);
|
|
262
|
+
}
|
|
263
|
+
close(reason = "closed") {
|
|
264
|
+
if (!this.closing) {
|
|
265
|
+
this.finish(reason);
|
|
266
|
+
this.closing = this.shutDown();
|
|
267
|
+
}
|
|
268
|
+
return this.closing;
|
|
269
|
+
}
|
|
270
|
+
async shutDown() {
|
|
271
|
+
if (this.transport instanceof StreamableHTTPClientTransport) {
|
|
272
|
+
// Courtesy to the server, which may keep the session in memory until told.
|
|
273
|
+
await Promise.race([
|
|
274
|
+
this.transport.terminateSession().catch(() => { }),
|
|
275
|
+
new Promise((resolve) => setTimeout(resolve, 1000).unref()),
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
await this.client.close().catch(() => { });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type JsonObject = {
|
|
5
|
+
[key: string]: JsonValue;
|
|
6
|
+
};
|
|
7
|
+
export type ServerSpec = {
|
|
8
|
+
transport: "stdio";
|
|
9
|
+
/** A path the host resolved; the package runs no package manager. */
|
|
10
|
+
command: string;
|
|
11
|
+
args?: string[];
|
|
12
|
+
/** Added on top of the six variables the SDK copies from the host process. */
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
} | {
|
|
16
|
+
transport: "http";
|
|
17
|
+
url: string;
|
|
18
|
+
/** Sent on every request to `url`'s origin, and to no other origin. */
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
auth?: TokenSource;
|
|
21
|
+
};
|
|
22
|
+
export interface TokenSource {
|
|
23
|
+
/** Asked before every request. */
|
|
24
|
+
token(): Promise<string | undefined>;
|
|
25
|
+
/** Called once after a 401; the request is then sent once more. */
|
|
26
|
+
refresh?(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export interface Server {
|
|
29
|
+
/** The host's name for one session. The client keeps one session per key. */
|
|
30
|
+
key: string;
|
|
31
|
+
spec: ServerSpec;
|
|
32
|
+
}
|
|
33
|
+
export interface McpClientOptions {
|
|
34
|
+
/** Sent to servers in the handshake. */
|
|
35
|
+
clientInfo: {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
};
|
|
39
|
+
/** The handshake's limit. Default 30 s. */
|
|
40
|
+
connectTimeoutMs?: number;
|
|
41
|
+
/** Close a session unused this long. Default 5 min; 0 keeps it. */
|
|
42
|
+
idleCloseMs?: number;
|
|
43
|
+
/** After a failed start, calls fail at once for this long. Default 10 s. */
|
|
44
|
+
failFastMs?: number;
|
|
45
|
+
/** A larger reply is a `too_large` outcome. Default 10 MB. */
|
|
46
|
+
maxReplyBytes?: number;
|
|
47
|
+
/** Used for every HTTP request, so the host can limit where requests go. Default: global `fetch`. */
|
|
48
|
+
fetch?: typeof fetch;
|
|
49
|
+
/** Session started, session ended, a child's stderr line: for the host's logs. */
|
|
50
|
+
onEvent?: (event: McpEvent) => void;
|
|
51
|
+
}
|
|
52
|
+
export type McpEvent = {
|
|
53
|
+
type: "session_started";
|
|
54
|
+
key: string;
|
|
55
|
+
transport: "stdio" | "http";
|
|
56
|
+
} | {
|
|
57
|
+
type: "session_ended";
|
|
58
|
+
key: string;
|
|
59
|
+
reason: "closed" | "idle" | "disconnected" | "forgotten" | "too_large";
|
|
60
|
+
} | {
|
|
61
|
+
type: "stderr";
|
|
62
|
+
key: string;
|
|
63
|
+
line: string;
|
|
64
|
+
};
|
|
65
|
+
export interface McpClient {
|
|
66
|
+
list(server: Server, opts?: {
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
}): Promise<Listing | Rejected | Unreachable | Aborted>;
|
|
70
|
+
call(server: Server, call: {
|
|
71
|
+
tool: PinnedTool;
|
|
72
|
+
arguments: JsonObject;
|
|
73
|
+
}, opts: {
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
timeoutMs: number;
|
|
76
|
+
}): Promise<CallOutcome>;
|
|
77
|
+
check(server: Server, opts?: {
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
timeoutMs?: number;
|
|
80
|
+
}): Promise<Reachable | Unreachable | Aborted>;
|
|
81
|
+
/** One session, or all of them. */
|
|
82
|
+
close(key?: string): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export interface Reachable {
|
|
85
|
+
kind: "reachable";
|
|
86
|
+
server: {
|
|
87
|
+
name: string;
|
|
88
|
+
version: string;
|
|
89
|
+
};
|
|
90
|
+
ms: number;
|
|
91
|
+
}
|
|
92
|
+
export interface Listing {
|
|
93
|
+
/** What the server says it is. */
|
|
94
|
+
server: {
|
|
95
|
+
name: string;
|
|
96
|
+
version: string;
|
|
97
|
+
};
|
|
98
|
+
protocolVersion: string;
|
|
99
|
+
/** The server's own text for a model, if it sends one. */
|
|
100
|
+
instructions?: string;
|
|
101
|
+
/** Every tool, exactly as the server listed it. */
|
|
102
|
+
tools: JsonObject[];
|
|
103
|
+
}
|
|
104
|
+
export interface PinnedTool {
|
|
105
|
+
/** The server's name for the tool, sent when it is called. */
|
|
106
|
+
name: string;
|
|
107
|
+
/** The server's tool object, unchanged: description, inputSchema, annotations, ... */
|
|
108
|
+
listed: JsonObject;
|
|
109
|
+
}
|
|
110
|
+
export interface Pin {
|
|
111
|
+
format: 1;
|
|
112
|
+
server: {
|
|
113
|
+
name: string;
|
|
114
|
+
version: string;
|
|
115
|
+
protocolVersion: string;
|
|
116
|
+
};
|
|
117
|
+
pinnedAt: string;
|
|
118
|
+
instructions?: string;
|
|
119
|
+
tools: PinnedTool[];
|
|
120
|
+
}
|
|
121
|
+
export interface PinProblem {
|
|
122
|
+
/** The tool the problem is about, when it has a name. */
|
|
123
|
+
tool?: string;
|
|
124
|
+
problem: "not_listed" | "invalid_tool" | "task_required" | "duplicate_choice" | "bad_model_name" | "duplicate_model_name";
|
|
125
|
+
message: string;
|
|
126
|
+
}
|
|
127
|
+
/** What the model is sent for one tool. Structurally the gateway's `Tool`. */
|
|
128
|
+
export interface ToolDefinition {
|
|
129
|
+
type: "function";
|
|
130
|
+
name: string;
|
|
131
|
+
description: string;
|
|
132
|
+
inputSchema: JsonObject;
|
|
133
|
+
}
|
|
134
|
+
/** Structurally the gateway's `TextPart` and `MediaPart`. */
|
|
135
|
+
export type ContentPart = {
|
|
136
|
+
type: "text";
|
|
137
|
+
text: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: "media";
|
|
140
|
+
mediaType: string;
|
|
141
|
+
source: {
|
|
142
|
+
data: string;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
export type CallOutcome = Answered | Rejected | TooLarge | Unreachable | Aborted;
|
|
146
|
+
/** The tool ran. `isError` is the server's own flag. `reply` is the raw `result` off the wire. */
|
|
147
|
+
export interface Answered {
|
|
148
|
+
kind: "answered";
|
|
149
|
+
isError: boolean;
|
|
150
|
+
reply: JsonObject;
|
|
151
|
+
ms: number;
|
|
152
|
+
}
|
|
153
|
+
/** The server is up and refused the request. `reply` is the raw JSON-RPC error object. */
|
|
154
|
+
export interface Rejected {
|
|
155
|
+
kind: "rejected";
|
|
156
|
+
code: number;
|
|
157
|
+
message: string;
|
|
158
|
+
reply: JsonObject;
|
|
159
|
+
ms: number;
|
|
160
|
+
}
|
|
161
|
+
/** The server answered; the reply was not kept. `bytes` is a lower bound: what was known when reading stopped. */
|
|
162
|
+
export interface TooLarge {
|
|
163
|
+
kind: "too_large";
|
|
164
|
+
bytes: number;
|
|
165
|
+
limit: number;
|
|
166
|
+
ms: number;
|
|
167
|
+
}
|
|
168
|
+
/** The host's signal fired. */
|
|
169
|
+
export interface Aborted {
|
|
170
|
+
kind: "aborted";
|
|
171
|
+
sent: boolean;
|
|
172
|
+
ms: number;
|
|
173
|
+
}
|
|
174
|
+
export interface Unreachable {
|
|
175
|
+
kind: "unreachable";
|
|
176
|
+
reason: "start_failed" | "connect_timeout" | "disconnected" | "call_timeout" | "unauthorized" | "forbidden" | "rate_limited" | "server_error" | "bad_reply";
|
|
177
|
+
httpStatus?: number;
|
|
178
|
+
message: string;
|
|
179
|
+
/** False only when nothing can have left. */
|
|
180
|
+
sent: boolean;
|
|
181
|
+
ms: number;
|
|
182
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meridian-flow/runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "What an AI product needs to run models: a provider-neutral streaming model gateway (Anthropic, OpenAI, Gemini, OpenAI-compatible) with retry, deadlines and usage normalization.",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "What an AI product needs to run models: a provider-neutral streaming model gateway (Anthropic, OpenAI, Gemini, OpenAI-compatible) with retry, deadlines and usage normalization, and an MCP client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llm",
|
|
7
7
|
"ai",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"openai",
|
|
11
11
|
"gemini",
|
|
12
12
|
"streaming",
|
|
13
|
-
"workload-identity-federation"
|
|
13
|
+
"workload-identity-federation",
|
|
14
|
+
"mcp",
|
|
15
|
+
"model-context-protocol"
|
|
14
16
|
],
|
|
15
17
|
"license": "Apache-2.0",
|
|
16
18
|
"repository": {
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"type": "module",
|
|
25
27
|
"sideEffects": false,
|
|
26
28
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
29
|
+
"node": ">=22"
|
|
28
30
|
},
|
|
29
31
|
"files": [
|
|
30
32
|
"dist"
|
|
@@ -45,6 +47,10 @@
|
|
|
45
47
|
"./gateway/mock-script": {
|
|
46
48
|
"types": "./dist/gateway/mock-script.d.ts",
|
|
47
49
|
"default": "./dist/gateway/mock-script.js"
|
|
50
|
+
},
|
|
51
|
+
"./mcp": {
|
|
52
|
+
"types": "./dist/mcp/index.d.ts",
|
|
53
|
+
"default": "./dist/mcp/index.js"
|
|
48
54
|
}
|
|
49
55
|
},
|
|
50
56
|
"meridianRuntime": {
|
|
@@ -54,17 +60,18 @@
|
|
|
54
60
|
]
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
57
|
-
"@anthropic-ai/sdk": "^
|
|
63
|
+
"@anthropic-ai/sdk": "^1.8.0",
|
|
58
64
|
"@google/genai": "^3.3.0",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
65
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
66
|
+
"jsonrepair": "^3.15.0",
|
|
67
|
+
"openai": "^7.57.0",
|
|
68
|
+
"zod": "^4.6.7"
|
|
62
69
|
},
|
|
63
70
|
"devDependencies": {
|
|
64
|
-
"@biomejs/biome": "^2.
|
|
65
|
-
"@types/node": "^
|
|
66
|
-
"typescript": "^
|
|
67
|
-
"vitest": "^
|
|
71
|
+
"@biomejs/biome": "^2.6.7",
|
|
72
|
+
"@types/node": "^26",
|
|
73
|
+
"typescript": "^7.0.2",
|
|
74
|
+
"vitest": "^5.1.0"
|
|
68
75
|
},
|
|
69
76
|
"scripts": {
|
|
70
77
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|