@astratra/ai 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/mcpClient.js +9 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astratra/ai",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Generic AI provider routing, tool registry, and agent loop utilities for Astratra, plus agent guards (@astratra/ai/guards): outbound masking, prompt-injection handling for untrusted tool results, reply checks.",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@astratra/core": "^1.0.0",
40
- "@modelcontextprotocol/sdk": "^1.32.1"
40
+ "@astratra/mcp": "^1.0.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@astratra/rag": ">=1.0.0",
package/src/mcpClient.js CHANGED
@@ -35,11 +35,7 @@ function resultValue(result, max) {
35
35
  try { return JSON.parse(texte); } catch { return texte; }
36
36
  }
37
37
 
38
- async function chargerSdk() {
39
- const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
40
- const { StreamableHTTPClientTransport } = require('@modelcontextprotocol/sdk/client/streamableHttp.js');
41
- return { Client, StreamableHTTPClientTransport };
42
- }
38
+ const { createMcpClient, createStreamableHttpClientTransport } = require('@astratra/mcp');
43
39
 
44
40
  /**
45
41
  * Se connecte à un serveur MCP et rend ses outils au format des outils natifs.
@@ -60,21 +56,13 @@ async function chargerSdk() {
60
56
  async function connectMcpServer(options = {}) {
61
57
  const { url, headers = {}, prefix = '', allow = null, kinds = {}, timeoutMs = DEFAULT_TIMEOUT_MS, resultMax = DEFAULT_RESULT_MAX } = options;
62
58
  if (!options.transport && !url) throw new Error('connectMcpServer: url is required');
63
- const { Client, StreamableHTTPClientTransport } = await chargerSdk();
64
- const transport = options.transport || new StreamableHTTPClientTransport(new URL(url), {
65
- requestInit: { headers },
66
- ...(options.fetch ? { fetch: options.fetch } : {})
67
- });
68
- const client = new Client(options.client || { name: 'astratra-ai', version: '1.0.0' });
59
+ // Le client de @astratra/mcp : https:// seulement (http:// vers la machine), aucune redirection suivie, réponses
60
+ // plafonnées. Un transport du SDK officiel peut aussi être donné dans options.transport.
61
+ const transport = options.transport || createStreamableHttpClientTransport(url, { headers, ...(options.fetch ? { fetch: options.fetch } : {}) });
62
+ const client = createMcpClient(options.client || { name: 'astratra-ai', version: '1.0.0' }, { timeoutMs });
69
63
  await client.connect(transport);
70
64
 
71
- const decrits = [];
72
- let curseur;
73
- do {
74
- const page = await client.listTools(curseur ? { cursor: curseur } : {});
75
- decrits.push(...(page.tools || []));
76
- curseur = page.nextCursor;
77
- } while (curseur);
65
+ const decrits = await client.listAllTools();
78
66
 
79
67
  const permis = allow ? new Set(allow) : null;
80
68
  const tools = decrits
@@ -94,8 +82,8 @@ async function connectMcpServer(options = {}) {
94
82
  mcp: { name: t.name },
95
83
  summary: () => ({}),
96
84
  async run(args, ctx = {}) {
97
- const result = await client.callTool({ name: t.name, arguments: args || {} }, undefined, {
98
- timeout: timeoutMs,
85
+ const result = await client.callTool({ name: t.name, arguments: args || {} }, {
86
+ timeoutMs,
99
87
  ...(ctx.signal ? { signal: ctx.signal } : {})
100
88
  });
101
89
  const data = resultValue(result, resultMax);
@@ -106,7 +94,7 @@ async function connectMcpServer(options = {}) {
106
94
  })
107
95
  .filter(Boolean);
108
96
 
109
- const instructions = typeof client.getInstructions === 'function' ? (client.getInstructions() || null) : null;
97
+ const instructions = client.getInstructions() || null;
110
98
  return {
111
99
  tools,
112
100
  instructions,