@mcp-ts/sdk 2.4.4 → 2.5.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/dist/adapters/agui-adapter.d.mts +3 -3
- package/dist/adapters/agui-adapter.d.ts +3 -3
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +3 -3
- package/dist/adapters/agui-middleware.d.ts +3 -3
- package/dist/adapters/agui-middleware.js.map +1 -1
- package/dist/adapters/agui-middleware.mjs.map +1 -1
- package/dist/adapters/ai-adapter.d.mts +3 -3
- package/dist/adapters/ai-adapter.d.ts +3 -3
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +3 -3
- package/dist/adapters/langchain-adapter.d.ts +3 -3
- package/dist/adapters/langchain-adapter.js +2 -2
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +2 -2
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/adapters/mastra-adapter.d.mts +2 -2
- package/dist/adapters/mastra-adapter.d.ts +2 -2
- package/dist/adapters/mastra-adapter.js +2 -2
- package/dist/adapters/mastra-adapter.js.map +1 -1
- package/dist/adapters/mastra-adapter.mjs +2 -2
- package/dist/adapters/mastra-adapter.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +6 -0
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/react.d.mts +15 -4
- package/dist/client/react.d.ts +15 -4
- package/dist/client/react.js +36 -6
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +36 -6
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -4
- package/dist/client/vue.d.ts +4 -4
- package/dist/client/vue.js +6 -0
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs +6 -0
- package/dist/client/vue.mjs.map +1 -1
- package/dist/{index-CkM3p0eE.d.mts → index-CTURVnom.d.mts} +5 -1
- package/dist/{index-CZk2gu2E.d.ts → index-sVcqrhf7.d.ts} +5 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +374 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +370 -130
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-ChQrBZhF.d.mts → multi-session-client-CSPSHHla.d.ts} +14 -2
- package/dist/{multi-session-client-QOOPdEVp.d.ts → multi-session-client-DMZGVABI.d.mts} +14 -2
- package/dist/server/index.d.mts +13 -4
- package/dist/server/index.d.ts +13 -4
- package/dist/server/index.js +368 -130
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +364 -130
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +4 -4
- package/dist/shared/index.d.ts +4 -4
- package/dist/shared/index.js +2 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +2 -6
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-DQ-HrD7W.d.ts → tool-router-CS9l0w4a.d.ts} +1 -1
- package/dist/{tool-router-CGs3IDOJ.d.mts → tool-router-CVLBaCwH.d.mts} +1 -1
- package/dist/{types-Bf-7GOLW.d.mts → types-DK_NGWd4.d.mts} +37 -3
- package/dist/{types-Bf-7GOLW.d.ts → types-DK_NGWd4.d.ts} +37 -3
- package/migrations/neon/20260513010000_install_mcp_sessions.sql +1 -0
- package/migrations/supabase/20260330195700_install_mcp_sessions.sql +1 -0
- package/package.json +1 -1
- package/src/adapters/agui-adapter.ts +6 -2
- package/src/adapters/ai-adapter.ts +3 -1
- package/src/adapters/langchain-adapter.ts +5 -3
- package/src/adapters/mastra-adapter.ts +5 -3
- package/src/client/core/sse-client.ts +17 -0
- package/src/client/react/use-mcp.ts +63 -0
- package/src/server/handlers/sse-handler.ts +117 -10
- package/src/server/mcp/multi-session-client.ts +7 -3
- package/src/server/mcp/oauth-client.ts +78 -55
- package/src/server/mcp/tool-policy-gateway.ts +90 -0
- package/src/server/storage/index.ts +1 -1
- package/src/server/storage/neon-backend.ts +65 -60
- package/src/server/storage/session-lifecycle.ts +5 -0
- package/src/server/storage/supabase-backend.ts +27 -15
- package/src/server/storage/tool-policy.ts +89 -0
- package/src/server/storage/types.ts +11 -0
- package/src/shared/types.ts +48 -1
- package/src/shared/utils.ts +16 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { A as ToolClientProvider, T as ToolClient } from './types-
|
|
2
|
+
import { A as ToolClientProvider, T as ToolClient } from './types-DK_NGWd4.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolIndex — Lightweight in-memory search index for MCP tool discovery.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { A as ToolClientProvider, T as ToolClient } from './types-
|
|
2
|
+
import { A as ToolClientProvider, T as ToolClient } from './types-DK_NGWd4.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolIndex — Lightweight in-memory search index for MCP tool discovery.
|
|
@@ -138,6 +138,7 @@ interface ToolClient {
|
|
|
138
138
|
callTool(name: string, args: Record<string, unknown>): Promise<any>;
|
|
139
139
|
getServerId?(): string | undefined;
|
|
140
140
|
getServerName?(): string | undefined;
|
|
141
|
+
getServerUrl?(): string | undefined;
|
|
141
142
|
getSessionId?(): string;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
@@ -203,7 +204,13 @@ type ToolInfo = {
|
|
|
203
204
|
};
|
|
204
205
|
type TransportType = 'sse' | 'streamable-http';
|
|
205
206
|
type SessionStatus = 'pending' | 'active';
|
|
206
|
-
type
|
|
207
|
+
type ToolPolicyMode = 'all' | 'allowlist' | 'denylist';
|
|
208
|
+
interface ToolPolicy {
|
|
209
|
+
mode: ToolPolicyMode;
|
|
210
|
+
toolIds: string[];
|
|
211
|
+
updatedAt: number;
|
|
212
|
+
}
|
|
213
|
+
type McpRpcMethod = 'connect' | 'disconnect' | 'listTools' | 'callTool' | 'listSessions' | 'getSession' | 'finishAuth' | 'listPrompts' | 'getPrompt' | 'listResources' | 'readResource' | 'setToolPolicy' | 'getToolPolicy';
|
|
207
214
|
interface McpRpcRequest {
|
|
208
215
|
id: string;
|
|
209
216
|
method: McpRpcMethod;
|
|
@@ -249,7 +256,17 @@ interface FinishAuthParams {
|
|
|
249
256
|
state: string;
|
|
250
257
|
code: string;
|
|
251
258
|
}
|
|
252
|
-
|
|
259
|
+
interface SetToolPolicyParams {
|
|
260
|
+
sessionId: string;
|
|
261
|
+
toolPolicy: {
|
|
262
|
+
mode: ToolPolicyMode;
|
|
263
|
+
toolIds?: string[];
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
interface GetToolPolicyParams {
|
|
267
|
+
sessionId: string;
|
|
268
|
+
}
|
|
269
|
+
type McpRpcParams = ConnectParams | DisconnectParams | SessionParams | CallToolParams | GetPromptParams | ReadResourceParams | FinishAuthParams | SetToolPolicyParams | GetToolPolicyParams | undefined;
|
|
253
270
|
interface SessionInfo {
|
|
254
271
|
sessionId: string;
|
|
255
272
|
serverId?: string;
|
|
@@ -263,6 +280,7 @@ interface SessionInfo {
|
|
|
263
280
|
* `pending` means auth is in progress and should be resumed explicitly by user action.
|
|
264
281
|
*/
|
|
265
282
|
status: SessionStatus;
|
|
283
|
+
toolPolicy?: ToolPolicy;
|
|
266
284
|
}
|
|
267
285
|
interface SessionListResult {
|
|
268
286
|
sessions: SessionInfo[];
|
|
@@ -285,6 +303,22 @@ interface FinishAuthResult {
|
|
|
285
303
|
interface ListToolsRpcResult {
|
|
286
304
|
tools: Tool[];
|
|
287
305
|
}
|
|
306
|
+
interface SetToolPolicyResult {
|
|
307
|
+
success: boolean;
|
|
308
|
+
toolPolicy: ToolPolicy;
|
|
309
|
+
tools: Tool[];
|
|
310
|
+
toolCount: number;
|
|
311
|
+
}
|
|
312
|
+
type ToolAccessInfo = Tool & {
|
|
313
|
+
toolId: string;
|
|
314
|
+
allowed: boolean;
|
|
315
|
+
};
|
|
316
|
+
interface GetToolPolicyResult {
|
|
317
|
+
toolPolicy: ToolPolicy;
|
|
318
|
+
tools: ToolAccessInfo[];
|
|
319
|
+
toolCount: number;
|
|
320
|
+
allowedToolCount: number;
|
|
321
|
+
}
|
|
288
322
|
interface ListPromptsResult {
|
|
289
323
|
prompts: Array<{
|
|
290
324
|
name: string;
|
|
@@ -305,4 +339,4 @@ interface ListResourcesResult {
|
|
|
305
339
|
}>;
|
|
306
340
|
}
|
|
307
341
|
|
|
308
|
-
export { type ToolClientProvider as A, type ToolInfo as B, type CallToolParams as C, type DisconnectParams as D, Emitter as E, type FinishAuthParams as F, type GetPromptParams as G, type TransportType as H, isCallToolSuccess as I, isConnectAuthRequired as J, isConnectError as K, type ListPromptsResult as L, type McpConnectionEvent as M, isConnectSuccess as N, isListToolsSuccess as O, type
|
|
342
|
+
export { type ToolClientProvider as A, type ToolInfo as B, type CallToolParams as C, type DisconnectParams as D, Emitter as E, type FinishAuthParams as F, type GetPromptParams as G, type TransportType as H, isCallToolSuccess as I, isConnectAuthRequired as J, isConnectError as K, type ListPromptsResult as L, type McpConnectionEvent as M, isConnectSuccess as N, isListToolsSuccess as O, type ToolPolicy as P, type SetToolPolicyResult as Q, type ReadResourceParams as R, type SessionInfo as S, type ToolClient as T, type GetToolPolicyResult as U, type McpAppsUIEvent as V, type CallToolRequest as a, type CallToolResponse as b, type ConnectAuthRequiredResponse as c, type ConnectErrorResponse as d, type ConnectParams as e, type ConnectRequest as f, type ConnectResponse as g, type ConnectResult as h, type ConnectSuccessResponse as i, type DisconnectResult as j, type Disposable as k, DisposableStore as l, type Event as m, type FinishAuthResult as n, type GetSessionResult as o, type ListResourcesResult as p, type ListToolsResponse as q, type ListToolsRpcResult as r, type McpConnectionState as s, type McpObservabilityEvent as t, type McpRpcMethod as u, type McpRpcParams as v, type McpRpcRequest as w, type McpRpcResponse as x, type SessionListResult as y, type SessionParams as z };
|
|
@@ -138,6 +138,7 @@ interface ToolClient {
|
|
|
138
138
|
callTool(name: string, args: Record<string, unknown>): Promise<any>;
|
|
139
139
|
getServerId?(): string | undefined;
|
|
140
140
|
getServerName?(): string | undefined;
|
|
141
|
+
getServerUrl?(): string | undefined;
|
|
141
142
|
getSessionId?(): string;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
@@ -203,7 +204,13 @@ type ToolInfo = {
|
|
|
203
204
|
};
|
|
204
205
|
type TransportType = 'sse' | 'streamable-http';
|
|
205
206
|
type SessionStatus = 'pending' | 'active';
|
|
206
|
-
type
|
|
207
|
+
type ToolPolicyMode = 'all' | 'allowlist' | 'denylist';
|
|
208
|
+
interface ToolPolicy {
|
|
209
|
+
mode: ToolPolicyMode;
|
|
210
|
+
toolIds: string[];
|
|
211
|
+
updatedAt: number;
|
|
212
|
+
}
|
|
213
|
+
type McpRpcMethod = 'connect' | 'disconnect' | 'listTools' | 'callTool' | 'listSessions' | 'getSession' | 'finishAuth' | 'listPrompts' | 'getPrompt' | 'listResources' | 'readResource' | 'setToolPolicy' | 'getToolPolicy';
|
|
207
214
|
interface McpRpcRequest {
|
|
208
215
|
id: string;
|
|
209
216
|
method: McpRpcMethod;
|
|
@@ -249,7 +256,17 @@ interface FinishAuthParams {
|
|
|
249
256
|
state: string;
|
|
250
257
|
code: string;
|
|
251
258
|
}
|
|
252
|
-
|
|
259
|
+
interface SetToolPolicyParams {
|
|
260
|
+
sessionId: string;
|
|
261
|
+
toolPolicy: {
|
|
262
|
+
mode: ToolPolicyMode;
|
|
263
|
+
toolIds?: string[];
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
interface GetToolPolicyParams {
|
|
267
|
+
sessionId: string;
|
|
268
|
+
}
|
|
269
|
+
type McpRpcParams = ConnectParams | DisconnectParams | SessionParams | CallToolParams | GetPromptParams | ReadResourceParams | FinishAuthParams | SetToolPolicyParams | GetToolPolicyParams | undefined;
|
|
253
270
|
interface SessionInfo {
|
|
254
271
|
sessionId: string;
|
|
255
272
|
serverId?: string;
|
|
@@ -263,6 +280,7 @@ interface SessionInfo {
|
|
|
263
280
|
* `pending` means auth is in progress and should be resumed explicitly by user action.
|
|
264
281
|
*/
|
|
265
282
|
status: SessionStatus;
|
|
283
|
+
toolPolicy?: ToolPolicy;
|
|
266
284
|
}
|
|
267
285
|
interface SessionListResult {
|
|
268
286
|
sessions: SessionInfo[];
|
|
@@ -285,6 +303,22 @@ interface FinishAuthResult {
|
|
|
285
303
|
interface ListToolsRpcResult {
|
|
286
304
|
tools: Tool[];
|
|
287
305
|
}
|
|
306
|
+
interface SetToolPolicyResult {
|
|
307
|
+
success: boolean;
|
|
308
|
+
toolPolicy: ToolPolicy;
|
|
309
|
+
tools: Tool[];
|
|
310
|
+
toolCount: number;
|
|
311
|
+
}
|
|
312
|
+
type ToolAccessInfo = Tool & {
|
|
313
|
+
toolId: string;
|
|
314
|
+
allowed: boolean;
|
|
315
|
+
};
|
|
316
|
+
interface GetToolPolicyResult {
|
|
317
|
+
toolPolicy: ToolPolicy;
|
|
318
|
+
tools: ToolAccessInfo[];
|
|
319
|
+
toolCount: number;
|
|
320
|
+
allowedToolCount: number;
|
|
321
|
+
}
|
|
288
322
|
interface ListPromptsResult {
|
|
289
323
|
prompts: Array<{
|
|
290
324
|
name: string;
|
|
@@ -305,4 +339,4 @@ interface ListResourcesResult {
|
|
|
305
339
|
}>;
|
|
306
340
|
}
|
|
307
341
|
|
|
308
|
-
export { type ToolClientProvider as A, type ToolInfo as B, type CallToolParams as C, type DisconnectParams as D, Emitter as E, type FinishAuthParams as F, type GetPromptParams as G, type TransportType as H, isCallToolSuccess as I, isConnectAuthRequired as J, isConnectError as K, type ListPromptsResult as L, type McpConnectionEvent as M, isConnectSuccess as N, isListToolsSuccess as O, type
|
|
342
|
+
export { type ToolClientProvider as A, type ToolInfo as B, type CallToolParams as C, type DisconnectParams as D, Emitter as E, type FinishAuthParams as F, type GetPromptParams as G, type TransportType as H, isCallToolSuccess as I, isConnectAuthRequired as J, isConnectError as K, type ListPromptsResult as L, type McpConnectionEvent as M, isConnectSuccess as N, isListToolsSuccess as O, type ToolPolicy as P, type SetToolPolicyResult as Q, type ReadResourceParams as R, type SessionInfo as S, type ToolClient as T, type GetToolPolicyResult as U, type McpAppsUIEvent as V, type CallToolRequest as a, type CallToolResponse as b, type ConnectAuthRequiredResponse as c, type ConnectErrorResponse as d, type ConnectParams as e, type ConnectRequest as f, type ConnectResponse as g, type ConnectResult as h, type ConnectSuccessResponse as i, type DisconnectResult as j, type Disposable as k, DisposableStore as l, type Event as m, type FinishAuthResult as n, type GetSessionResult as o, type ListResourcesResult as p, type ListToolsResponse as q, type ListToolsRpcResult as r, type McpConnectionState as s, type McpObservabilityEvent as t, type McpRpcMethod as u, type McpRpcParams as v, type McpRpcRequest as w, type McpRpcResponse as x, type SessionListResult as y, type SessionParams as z };
|
|
@@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS public.mcp_sessions (
|
|
|
17
17
|
CHECK (status IN ('pending', 'active')),
|
|
18
18
|
headers JSONB,
|
|
19
19
|
auth_url TEXT,
|
|
20
|
+
-- tool_policy JSONB -- optional, see docs/tool-policy
|
|
20
21
|
CONSTRAINT mcp_sessions_user_session_unique
|
|
21
22
|
UNIQUE (user_id, session_id)
|
|
22
23
|
);
|
|
@@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS public.mcp_sessions (
|
|
|
15
15
|
CHECK (status IN ('pending', 'active')),
|
|
16
16
|
headers JSONB,
|
|
17
17
|
auth_url TEXT,
|
|
18
|
+
-- tool_policy JSONB -- optional, see docs/tool-policy
|
|
18
19
|
CONSTRAINT mcp_sessions_user_session_unique
|
|
19
20
|
UNIQUE (user_id, session_id)
|
|
20
21
|
);
|
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import { MCPClient } from '../server/mcp/oauth-client.js';
|
|
30
30
|
import { MultiSessionClient } from '../server/mcp/multi-session-client.js';
|
|
31
31
|
import { ToolRouter } from '../shared/tool-router.js';
|
|
32
|
+
import type { ToolClient } from '../shared/types.js';
|
|
32
33
|
import { executeMetaTool, isMetaTool } from '../shared/meta-tools.js';
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -184,7 +185,7 @@ export class AguiAdapter {
|
|
|
184
185
|
return typeof (this.client as any).getClients === 'function';
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
private async transformTools(client:
|
|
188
|
+
private async transformTools(client: ToolClient): Promise<AguiTool[]> {
|
|
188
189
|
if (!client.isConnected()) return [];
|
|
189
190
|
|
|
190
191
|
const result = await client.listTools();
|
|
@@ -214,7 +215,7 @@ export class AguiAdapter {
|
|
|
214
215
|
});
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
private async transformToolDefinitions(client:
|
|
218
|
+
private async transformToolDefinitions(client: ToolClient): Promise<AguiToolDefinition[]> {
|
|
218
219
|
if (!client.isConnected()) return [];
|
|
219
220
|
|
|
220
221
|
const result = await client.listTools();
|
|
@@ -299,3 +300,6 @@ export class AguiAdapter {
|
|
|
299
300
|
return `tool_${normalized}_${toolName}`;
|
|
300
301
|
}
|
|
301
302
|
}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
@@ -3,6 +3,7 @@ import { MultiSessionClient } from '../server/mcp/multi-session-client';
|
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import type { ToolSet } from 'ai';
|
|
5
5
|
import { ToolRouter } from '../shared/tool-router.js';
|
|
6
|
+
import type { ToolClient } from '../shared/types.js';
|
|
6
7
|
import { executeMetaTool, isMetaTool } from '../shared/meta-tools.js';
|
|
7
8
|
|
|
8
9
|
export interface AIAdapterOptions {
|
|
@@ -54,7 +55,7 @@ export class AIAdapter {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
private async transformTools(client:
|
|
58
|
+
private async transformTools(client: ToolClient): Promise<ToolSet> {
|
|
58
59
|
// Safe check for isConnected method (duck typing for bundler compatibility)
|
|
59
60
|
const isConnected = typeof client.isConnected === 'function'
|
|
60
61
|
? client.isConnected()
|
|
@@ -217,3 +218,4 @@ export class AIAdapter {
|
|
|
217
218
|
return new AIAdapter(client, options).getTools();
|
|
218
219
|
}
|
|
219
220
|
}
|
|
221
|
+
|
|
@@ -3,6 +3,7 @@ import { MultiSessionClient } from '../server/mcp/multi-session-client';
|
|
|
3
3
|
import type { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import type { z } from 'zod';
|
|
5
5
|
import { ToolRouter } from '../shared/tool-router.js';
|
|
6
|
+
import type { ToolClient } from '../shared/types.js';
|
|
6
7
|
import { executeMetaTool, isMetaTool } from '../shared/meta-tools.js';
|
|
7
8
|
|
|
8
9
|
export interface LangChainAdapterOptions {
|
|
@@ -58,7 +59,7 @@ export class LangChainAdapter {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
private async transformTools(client:
|
|
62
|
+
private async transformTools(client: ToolClient): Promise<StructuredTool[]> {
|
|
62
63
|
if (!client.isConnected()) {
|
|
63
64
|
return [];
|
|
64
65
|
}
|
|
@@ -66,7 +67,7 @@ export class LangChainAdapter {
|
|
|
66
67
|
await this.ensureDependencies();
|
|
67
68
|
|
|
68
69
|
const result = await client.listTools();
|
|
69
|
-
const prefix = this.options.prefix ?? client.getServerId()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';
|
|
70
|
+
const prefix = this.options.prefix ?? client.getServerId?.()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';
|
|
70
71
|
|
|
71
72
|
return result.tools.map((tool) => {
|
|
72
73
|
// In a real implementation, you would use a library like 'json-schema-to-zod'
|
|
@@ -127,7 +128,7 @@ export class LangChainAdapter {
|
|
|
127
128
|
try {
|
|
128
129
|
return await this.transformTools(client);
|
|
129
130
|
} catch (error) {
|
|
130
|
-
console.error(`[LangChainAdapter] Failed to fetch tools from ${client.getServerId()}:`, error);
|
|
131
|
+
console.error(`[LangChainAdapter] Failed to fetch tools from ${client.getServerId?.() ?? "unknown"}:`, error);
|
|
131
132
|
return [];
|
|
132
133
|
}
|
|
133
134
|
})
|
|
@@ -203,3 +204,4 @@ export class LangChainAdapter {
|
|
|
203
204
|
return new LangChainAdapter(client, options).getTools();
|
|
204
205
|
}
|
|
205
206
|
}
|
|
207
|
+
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MCPClient } from '../server/mcp/oauth-client';
|
|
2
2
|
import { MultiSessionClient } from '../server/mcp/multi-session-client';
|
|
3
|
+
import type { ToolClient } from '../shared/types.js';
|
|
3
4
|
import type { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
export interface MastraAdapterOptions {
|
|
@@ -51,7 +52,7 @@ export class MastraAdapter {
|
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
|
|
54
|
-
private async transformTools(client:
|
|
55
|
+
private async transformTools(client: ToolClient): Promise<Record<string, MastraTool>> {
|
|
55
56
|
if (!client.isConnected()) {
|
|
56
57
|
return {};
|
|
57
58
|
}
|
|
@@ -59,7 +60,7 @@ export class MastraAdapter {
|
|
|
59
60
|
await this.ensureZod();
|
|
60
61
|
|
|
61
62
|
const result = await client.listTools();
|
|
62
|
-
const prefix = this.options.prefix ?? client.getServerId()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';
|
|
63
|
+
const prefix = this.options.prefix ?? client.getServerId?.()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';
|
|
63
64
|
const tools: Record<string, MastraTool> = {};
|
|
64
65
|
|
|
65
66
|
for (const tool of result.tools) {
|
|
@@ -113,7 +114,7 @@ export class MastraAdapter {
|
|
|
113
114
|
try {
|
|
114
115
|
return await this.transformTools(client);
|
|
115
116
|
} catch (error) {
|
|
116
|
-
console.error(`[MastraAdapter] Failed to fetch tools from ${client.getServerId()}:`, error);
|
|
117
|
+
console.error(`[MastraAdapter] Failed to fetch tools from ${client.getServerId?.() ?? "unknown"}:`, error);
|
|
117
118
|
return {};
|
|
118
119
|
}
|
|
119
120
|
})
|
|
@@ -128,3 +129,4 @@ export class MastraAdapter {
|
|
|
128
129
|
return new MastraAdapter(client, options).getTools();
|
|
129
130
|
}
|
|
130
131
|
}
|
|
132
|
+
|
|
@@ -25,6 +25,9 @@ import type {
|
|
|
25
25
|
ListToolsRpcResult,
|
|
26
26
|
ListPromptsResult,
|
|
27
27
|
ListResourcesResult,
|
|
28
|
+
SetToolPolicyResult,
|
|
29
|
+
GetToolPolicyResult,
|
|
30
|
+
ToolPolicy,
|
|
28
31
|
} from '../../shared/types.js';
|
|
29
32
|
|
|
30
33
|
export interface SSEClientOptions {
|
|
@@ -99,6 +102,17 @@ export class SSEClient {
|
|
|
99
102
|
return this.sendRequest<DisconnectResult>('disconnect', { sessionId });
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
async setToolPolicy(
|
|
106
|
+
sessionId: string,
|
|
107
|
+
toolPolicy: Pick<ToolPolicy, 'mode'> & { toolIds?: string[] }
|
|
108
|
+
): Promise<SetToolPolicyResult> {
|
|
109
|
+
return this.sendRequest<SetToolPolicyResult>('setToolPolicy', { sessionId, toolPolicy });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async getToolPolicy(sessionId: string): Promise<GetToolPolicyResult> {
|
|
113
|
+
return this.sendRequest<GetToolPolicyResult>('getToolPolicy', { sessionId });
|
|
114
|
+
}
|
|
115
|
+
|
|
102
116
|
async listTools(sessionId: string): Promise<ListToolsRpcResult> {
|
|
103
117
|
return this.sendRequest<ListToolsRpcResult>('listTools', { sessionId });
|
|
104
118
|
}
|
|
@@ -367,3 +381,6 @@ export class SSEClient {
|
|
|
367
381
|
}
|
|
368
382
|
}
|
|
369
383
|
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
@@ -18,6 +18,9 @@ import type {
|
|
|
18
18
|
ListPromptsResult,
|
|
19
19
|
ListResourcesResult,
|
|
20
20
|
SessionInfo,
|
|
21
|
+
ToolPolicy,
|
|
22
|
+
SetToolPolicyResult,
|
|
23
|
+
GetToolPolicyResult,
|
|
21
24
|
} from '../../shared/types';
|
|
22
25
|
|
|
23
26
|
export interface UseMcpOptions {
|
|
@@ -89,6 +92,7 @@ export interface McpConnection {
|
|
|
89
92
|
error?: string;
|
|
90
93
|
createdAt?: Date;
|
|
91
94
|
updatedAt?: Date;
|
|
95
|
+
toolPolicy?: ToolPolicy;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
export interface McpClient {
|
|
@@ -193,6 +197,19 @@ export interface McpClient {
|
|
|
193
197
|
*/
|
|
194
198
|
listTools: (sessionId: string) => Promise<ListToolsRpcResult>;
|
|
195
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Update per-session tool access policy
|
|
202
|
+
*/
|
|
203
|
+
updateToolPolicy: (
|
|
204
|
+
sessionId: string,
|
|
205
|
+
toolPolicy: Pick<ToolPolicy, 'mode'> & { toolIds?: string[] }
|
|
206
|
+
) => Promise<SetToolPolicyResult>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get all tools and effective policy state for access management
|
|
210
|
+
*/
|
|
211
|
+
getToolAccess: (sessionId: string) => Promise<GetToolPolicyResult>;
|
|
212
|
+
|
|
196
213
|
/**
|
|
197
214
|
* List available prompts for a session
|
|
198
215
|
*/
|
|
@@ -428,6 +445,7 @@ export function useMcp(options: UseMcpOptions): McpClient {
|
|
|
428
445
|
state: getInitialConnectionState(s.status),
|
|
429
446
|
createdAt: new Date(s.createdAt),
|
|
430
447
|
updatedAt: new Date(s.updatedAt ?? s.createdAt),
|
|
448
|
+
toolPolicy: s.toolPolicy,
|
|
431
449
|
tools: [],
|
|
432
450
|
}))
|
|
433
451
|
);
|
|
@@ -607,6 +625,42 @@ export function useMcp(options: UseMcpOptions): McpClient {
|
|
|
607
625
|
return await clientRef.current.listTools(sessionId);
|
|
608
626
|
}, []);
|
|
609
627
|
|
|
628
|
+
/**
|
|
629
|
+
* Update tool access policy for a session
|
|
630
|
+
*/
|
|
631
|
+
const updateToolPolicy = useCallback(async (
|
|
632
|
+
sessionId: string,
|
|
633
|
+
toolPolicy: Pick<ToolPolicy, 'mode'> & { toolIds?: string[] }
|
|
634
|
+
): Promise<SetToolPolicyResult> => {
|
|
635
|
+
if (!clientRef.current) {
|
|
636
|
+
throw new Error('SSE client not initialized');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const result = await clientRef.current.setToolPolicy(sessionId, toolPolicy);
|
|
640
|
+
if (isMountedRef.current) {
|
|
641
|
+
setConnections((prev: McpConnection[]) => prev.map((connection) =>
|
|
642
|
+
connection.sessionId === sessionId
|
|
643
|
+
? {
|
|
644
|
+
...connection,
|
|
645
|
+
toolPolicy: result.toolPolicy,
|
|
646
|
+
tools: result.tools,
|
|
647
|
+
updatedAt: new Date(),
|
|
648
|
+
}
|
|
649
|
+
: connection
|
|
650
|
+
));
|
|
651
|
+
}
|
|
652
|
+
return result;
|
|
653
|
+
}, []);
|
|
654
|
+
/**
|
|
655
|
+
* Get all tools with effective access state for a session
|
|
656
|
+
*/
|
|
657
|
+
const getToolAccess = useCallback(async (sessionId: string): Promise<GetToolPolicyResult> => {
|
|
658
|
+
if (!clientRef.current) {
|
|
659
|
+
throw new Error('SSE client not initialized');
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
return await clientRef.current.getToolPolicy(sessionId);
|
|
663
|
+
}, []);
|
|
610
664
|
/**
|
|
611
665
|
* List prompts
|
|
612
666
|
*/
|
|
@@ -700,6 +754,8 @@ export function useMcp(options: UseMcpOptions): McpClient {
|
|
|
700
754
|
resumeAuth,
|
|
701
755
|
callTool,
|
|
702
756
|
listTools,
|
|
757
|
+
updateToolPolicy,
|
|
758
|
+
getToolAccess,
|
|
703
759
|
listPrompts,
|
|
704
760
|
getPrompt,
|
|
705
761
|
listResources,
|
|
@@ -724,6 +780,8 @@ export function useMcp(options: UseMcpOptions): McpClient {
|
|
|
724
780
|
resumeAuth,
|
|
725
781
|
callTool,
|
|
726
782
|
listTools,
|
|
783
|
+
updateToolPolicy,
|
|
784
|
+
getToolAccess,
|
|
727
785
|
listPrompts,
|
|
728
786
|
getPrompt,
|
|
729
787
|
listResources,
|
|
@@ -732,3 +790,8 @@ export function useMcp(options: UseMcpOptions): McpClient {
|
|
|
732
790
|
]
|
|
733
791
|
);
|
|
734
792
|
}
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|