@neutrome/open-ai-router 0.1.15 → 0.1.16
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/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/router/config.ts +1 -1
- package/src/router/execute.test.ts +2 -2
- package/src/router/index.ts +1 -1
- package/src/router/mcp.ts +6 -5
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/router/config.ts
CHANGED
|
@@ -118,8 +118,8 @@ describe("router execution", () => {
|
|
|
118
118
|
},
|
|
119
119
|
mcps: {
|
|
120
120
|
crm: {
|
|
121
|
-
type: "
|
|
122
|
-
url: "https://mcp.example.test/
|
|
121
|
+
type: "mcp_streamable_http",
|
|
122
|
+
url: "https://mcp.example.test/mcp",
|
|
123
123
|
headers: { authorization: "Bearer static" },
|
|
124
124
|
tools: [{
|
|
125
125
|
name: "lookup",
|
package/src/router/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export {
|
|
|
13
13
|
export { listConfiguredModels, resolveInvocationTarget, resolveInvocationTargets } from "./resolve.ts";
|
|
14
14
|
export {
|
|
15
15
|
createRemoteMcpToolSet,
|
|
16
|
-
|
|
16
|
+
createStreamableHttpMcpClient,
|
|
17
17
|
stringifyMcpToolResult,
|
|
18
18
|
wireToolName,
|
|
19
19
|
} from "./mcp.ts";
|
package/src/router/mcp.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
4
|
import type { ExecutionContext, Tool } from "@neutrome/lil-engine";
|
|
4
5
|
import type { RemoteMcpServerRuntime, RouterRuntime } from "./runtime.ts";
|
|
5
6
|
|
|
@@ -24,7 +25,7 @@ export function createRemoteMcpToolSet(
|
|
|
24
25
|
factory?: RemoteMcpClientFactory,
|
|
25
26
|
): RemoteMcpToolSet {
|
|
26
27
|
const pool = new RemoteMcpSessionPool(
|
|
27
|
-
factory ?? ((server, signal) =>
|
|
28
|
+
factory ?? ((server, signal) => createStreamableHttpMcpClient(server, signal, runtime.fetchImpl)),
|
|
28
29
|
);
|
|
29
30
|
const tools: Tool[] = [];
|
|
30
31
|
const usedNames = new Map<string, number>();
|
|
@@ -55,18 +56,18 @@ export function createRemoteMcpToolSet(
|
|
|
55
56
|
return { tools, close: () => pool.closeAll() };
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export async function
|
|
59
|
+
export async function createStreamableHttpMcpClient(
|
|
59
60
|
server: RemoteMcpServerRuntime,
|
|
60
61
|
signal?: AbortSignal,
|
|
61
62
|
fetchImpl?: typeof fetch,
|
|
62
63
|
): Promise<RemoteMcpToolCallClient> {
|
|
63
64
|
const client = new Client({ name: "open-ai-router", version: "0.1.0" });
|
|
64
|
-
const transport = new
|
|
65
|
+
const transport = new StreamableHTTPClientTransport(new URL(server.url), {
|
|
65
66
|
requestInit: { headers: server.headers ?? {} },
|
|
66
67
|
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
67
68
|
});
|
|
68
69
|
signal?.addEventListener("abort", () => void client.close(), { once: true });
|
|
69
|
-
await client.connect(transport);
|
|
70
|
+
await client.connect(transport as Transport);
|
|
70
71
|
return {
|
|
71
72
|
callTool(name, args) {
|
|
72
73
|
return client.callTool({ name, arguments: args });
|