@mcp-ts/sdk 1.3.7 → 1.3.10

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 (66) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +397 -404
  3. package/dist/adapters/agui-middleware.js.map +1 -1
  4. package/dist/adapters/agui-middleware.mjs.map +1 -1
  5. package/dist/bin/mcp-ts.js +0 -0
  6. package/dist/bin/mcp-ts.js.map +1 -1
  7. package/dist/bin/mcp-ts.mjs +0 -0
  8. package/dist/bin/mcp-ts.mjs.map +1 -1
  9. package/dist/client/index.js.map +1 -1
  10. package/dist/client/index.mjs.map +1 -1
  11. package/dist/client/react.d.mts +10 -28
  12. package/dist/client/react.d.ts +10 -28
  13. package/dist/client/react.js +101 -52
  14. package/dist/client/react.js.map +1 -1
  15. package/dist/client/react.mjs +102 -53
  16. package/dist/client/react.mjs.map +1 -1
  17. package/dist/client/vue.js.map +1 -1
  18. package/dist/client/vue.mjs.map +1 -1
  19. package/dist/index.js +78 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +73 -6
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/server/index.js +78 -6
  24. package/dist/server/index.js.map +1 -1
  25. package/dist/server/index.mjs +73 -6
  26. package/dist/server/index.mjs.map +1 -1
  27. package/dist/shared/index.js.map +1 -1
  28. package/dist/shared/index.mjs.map +1 -1
  29. package/package.json +185 -185
  30. package/src/adapters/agui-middleware.ts +382 -382
  31. package/src/bin/mcp-ts.ts +102 -102
  32. package/src/client/core/app-host.ts +417 -417
  33. package/src/client/core/sse-client.ts +371 -371
  34. package/src/client/core/types.ts +31 -31
  35. package/src/client/index.ts +27 -27
  36. package/src/client/react/index.ts +20 -16
  37. package/src/client/react/use-app-host.ts +74 -73
  38. package/src/client/react/use-mcp-apps.tsx +224 -214
  39. package/src/client/react/use-mcp.ts +669 -641
  40. package/src/client/vue/index.ts +10 -10
  41. package/src/client/vue/use-mcp.ts +617 -617
  42. package/src/index.ts +11 -11
  43. package/src/server/handlers/nextjs-handler.ts +204 -204
  44. package/src/server/handlers/sse-handler.ts +631 -631
  45. package/src/server/index.ts +57 -57
  46. package/src/server/mcp/multi-session-client.ts +228 -228
  47. package/src/server/mcp/oauth-client.ts +1188 -1188
  48. package/src/server/mcp/storage-oauth-provider.ts +272 -272
  49. package/src/server/storage/crypto.ts +92 -0
  50. package/src/server/storage/file-backend.ts +157 -157
  51. package/src/server/storage/index.ts +176 -176
  52. package/src/server/storage/memory-backend.ts +123 -123
  53. package/src/server/storage/redis-backend.ts +276 -276
  54. package/src/server/storage/redis.ts +160 -160
  55. package/src/server/storage/sqlite-backend.ts +182 -182
  56. package/src/server/storage/supabase-backend.ts +229 -228
  57. package/src/server/storage/types.ts +116 -116
  58. package/src/shared/constants.ts +29 -29
  59. package/src/shared/errors.ts +133 -133
  60. package/src/shared/event-routing.ts +28 -28
  61. package/src/shared/events.ts +180 -180
  62. package/src/shared/index.ts +75 -75
  63. package/src/shared/tool-utils.ts +61 -61
  64. package/src/shared/types.ts +282 -282
  65. package/src/shared/utils.ts +38 -38
  66. package/supabase/migrations/20260330195700_install_mcp_sessions.sql +84 -84
@@ -1,116 +1,116 @@
1
-
2
- import type { MCPClient } from '../mcp/oauth-client.js';
3
- import type {
4
- OAuthTokens,
5
- OAuthClientInformationMixed,
6
- } from '@modelcontextprotocol/sdk/shared/auth.js';
7
-
8
- export interface SessionData {
9
- sessionId: string;
10
- serverId?: string; // Database server ID for mapping
11
- serverName?: string;
12
- serverUrl: string;
13
- transportType: 'sse' | 'streamable_http';
14
- callbackUrl: string;
15
- createdAt: number;
16
- identity: string;
17
- headers?: Record<string, string>;
18
- /**
19
- * Session status marker used for TTL transitions:
20
- * - false: short-lived intermediate/error/auth-pending session state
21
- * (keep this value when connection/auth is incomplete or failed)
22
- * - true: active long-lived session state after successful connection/auth completion
23
- */
24
- active?: boolean;
25
- // OAuth data (consolidated)
26
- clientInformation?: OAuthClientInformationMixed;
27
- tokens?: OAuthTokens;
28
- codeVerifier?: string;
29
- clientId?: string;
30
- }
31
-
32
- export interface SetClientOptions {
33
- sessionId: string;
34
- serverId?: string; // Database server ID
35
- serverName?: string; // Human-readable server name
36
- client?: MCPClient;
37
- serverUrl?: string;
38
- callbackUrl?: string;
39
- transportType?: 'sse' | 'streamable_http';
40
- identity?: string;
41
- headers?: Record<string, string>;
42
- }
43
-
44
- /**
45
- * Interface for MCP Session Storage Backends
46
- */
47
- export interface StorageBackend {
48
- /**
49
- * Optional initialization (e.g., database connection)
50
- */
51
- init?(): Promise<void>;
52
-
53
- /**
54
- * Generates a unique session ID
55
- */
56
- generateSessionId(): string;
57
-
58
- /**
59
- * Stores or updates a session
60
- */
61
- /**
62
- * Creates a new session. Throws if session already exists.
63
- * @param session - Session data to create
64
- * @param ttl - Optional TTL in seconds (defaults to backend's default)
65
- */
66
- createSession(session: SessionData, ttl?: number): Promise<void>;
67
-
68
- /**
69
- * Updates an existing session with partial data. Throws if session does not exist.
70
- * @param identity - User identity
71
- * @param sessionId - Session identifier
72
- * @param data - Partial session data to update
73
- * @param ttl - Optional TTL in seconds (defaults to backend's default)
74
- */
75
- updateSession(identity: string, sessionId: string, data: Partial<SessionData>, ttl?: number): Promise<void>;
76
-
77
- /**
78
- * Retrieves a session
79
- */
80
- getSession(identity: string, sessionId: string): Promise<SessionData | null>;
81
-
82
- /**
83
- * Gets full session data for all of an identity's sessions
84
- */
85
- getIdentitySessionsData(identity: string): Promise<SessionData[]>;
86
-
87
- /**
88
- * Removes a session
89
- */
90
- removeSession(identity: string, sessionId: string): Promise<void>;
91
-
92
- /**
93
- * Gets all sessions IDs of an identity
94
- */
95
- getIdentityMcpSessions(identity: string): Promise<string[]>;
96
-
97
- /**
98
- * Gets all session IDs across all users (Admin)
99
- */
100
- getAllSessionIds(): Promise<string[]>;
101
-
102
- /**
103
- * Clears all sessions (Admin)
104
- */
105
- clearAll(): Promise<void>;
106
-
107
- /**
108
- * Clean up expired sessions
109
- */
110
- cleanupExpiredSessions(): Promise<void>;
111
-
112
- /**
113
- * Disconnect from storage backend
114
- */
115
- disconnect(): Promise<void>;
116
- }
1
+
2
+ import type { MCPClient } from '../mcp/oauth-client.js';
3
+ import type {
4
+ OAuthTokens,
5
+ OAuthClientInformationMixed,
6
+ } from '@modelcontextprotocol/sdk/shared/auth.js';
7
+
8
+ export interface SessionData {
9
+ sessionId: string;
10
+ serverId?: string; // Database server ID for mapping
11
+ serverName?: string;
12
+ serverUrl: string;
13
+ transportType: 'sse' | 'streamable_http';
14
+ callbackUrl: string;
15
+ createdAt: number;
16
+ identity: string;
17
+ headers?: Record<string, string>;
18
+ /**
19
+ * Session status marker used for TTL transitions:
20
+ * - false: short-lived intermediate/error/auth-pending session state
21
+ * (keep this value when connection/auth is incomplete or failed)
22
+ * - true: active long-lived session state after successful connection/auth completion
23
+ */
24
+ active?: boolean;
25
+ // OAuth data (consolidated)
26
+ clientInformation?: OAuthClientInformationMixed;
27
+ tokens?: OAuthTokens;
28
+ codeVerifier?: string;
29
+ clientId?: string;
30
+ }
31
+
32
+ export interface SetClientOptions {
33
+ sessionId: string;
34
+ serverId?: string; // Database server ID
35
+ serverName?: string; // Human-readable server name
36
+ client?: MCPClient;
37
+ serverUrl?: string;
38
+ callbackUrl?: string;
39
+ transportType?: 'sse' | 'streamable_http';
40
+ identity?: string;
41
+ headers?: Record<string, string>;
42
+ }
43
+
44
+ /**
45
+ * Interface for MCP Session Storage Backends
46
+ */
47
+ export interface StorageBackend {
48
+ /**
49
+ * Optional initialization (e.g., database connection)
50
+ */
51
+ init?(): Promise<void>;
52
+
53
+ /**
54
+ * Generates a unique session ID
55
+ */
56
+ generateSessionId(): string;
57
+
58
+ /**
59
+ * Stores or updates a session
60
+ */
61
+ /**
62
+ * Creates a new session. Throws if session already exists.
63
+ * @param session - Session data to create
64
+ * @param ttl - Optional TTL in seconds (defaults to backend's default)
65
+ */
66
+ createSession(session: SessionData, ttl?: number): Promise<void>;
67
+
68
+ /**
69
+ * Updates an existing session with partial data. Throws if session does not exist.
70
+ * @param identity - User identity
71
+ * @param sessionId - Session identifier
72
+ * @param data - Partial session data to update
73
+ * @param ttl - Optional TTL in seconds (defaults to backend's default)
74
+ */
75
+ updateSession(identity: string, sessionId: string, data: Partial<SessionData>, ttl?: number): Promise<void>;
76
+
77
+ /**
78
+ * Retrieves a session
79
+ */
80
+ getSession(identity: string, sessionId: string): Promise<SessionData | null>;
81
+
82
+ /**
83
+ * Gets full session data for all of an identity's sessions
84
+ */
85
+ getIdentitySessionsData(identity: string): Promise<SessionData[]>;
86
+
87
+ /**
88
+ * Removes a session
89
+ */
90
+ removeSession(identity: string, sessionId: string): Promise<void>;
91
+
92
+ /**
93
+ * Gets all sessions IDs of an identity
94
+ */
95
+ getIdentityMcpSessions(identity: string): Promise<string[]>;
96
+
97
+ /**
98
+ * Gets all session IDs across all users (Admin)
99
+ */
100
+ getAllSessionIds(): Promise<string[]>;
101
+
102
+ /**
103
+ * Clears all sessions (Admin)
104
+ */
105
+ clearAll(): Promise<void>;
106
+
107
+ /**
108
+ * Clean up expired sessions
109
+ */
110
+ cleanupExpiredSessions(): Promise<void>;
111
+
112
+ /**
113
+ * Disconnect from storage backend
114
+ */
115
+ disconnect(): Promise<void>;
116
+ }
@@ -1,29 +1,29 @@
1
- /**
2
- * Centralized constants for MCP Redis library
3
- * Eliminates magic numbers and enables consistent configuration
4
- */
5
-
6
- // Redis TTL and Session Management
7
- export const SESSION_TTL_SECONDS = 43200; // 12 hours
8
- export const STATE_EXPIRATION_MS = 10 * 60 * 1000; // 10 minutes for OAuth state
9
-
10
- // Heartbeat and Connection
11
- export const DEFAULT_HEARTBEAT_INTERVAL_MS = 30000; // 30 seconds
12
-
13
- // Redis Key Prefixes
14
- export const REDIS_KEY_PREFIX = 'mcp:session:';
15
-
16
- // Token Management
17
- export const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000; // 5 minute buffer before expiry
18
-
19
- // Client Information
20
- export const DEFAULT_CLIENT_NAME = 'MCP Assistant';
21
- export const DEFAULT_CLIENT_URI = 'https://mcp-assistant.in';
22
- export const DEFAULT_LOGO_URI = 'https://mcp-assistant.in/logo.svg';
23
- export const DEFAULT_POLICY_URI = 'https://mcp-assistant.in/privacy';
24
- export const SOFTWARE_ID = '@mcp-ts';
25
- export const SOFTWARE_VERSION = '1.3.4';
26
-
27
- // MCP Client Configuration
28
- export const MCP_CLIENT_NAME = 'mcp-ts-oauth-client';
29
- export const MCP_CLIENT_VERSION = '2.0';
1
+ /**
2
+ * Centralized constants for MCP Redis library
3
+ * Eliminates magic numbers and enables consistent configuration
4
+ */
5
+
6
+ // Redis TTL and Session Management
7
+ export const SESSION_TTL_SECONDS = 43200; // 12 hours
8
+ export const STATE_EXPIRATION_MS = 10 * 60 * 1000; // 10 minutes for OAuth state
9
+
10
+ // Heartbeat and Connection
11
+ export const DEFAULT_HEARTBEAT_INTERVAL_MS = 30000; // 30 seconds
12
+
13
+ // Redis Key Prefixes
14
+ export const REDIS_KEY_PREFIX = 'mcp:session:';
15
+
16
+ // Token Management
17
+ export const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000; // 5 minute buffer before expiry
18
+
19
+ // Client Information
20
+ export const DEFAULT_CLIENT_NAME = 'MCP Assistant';
21
+ export const DEFAULT_CLIENT_URI = 'https://mcp-assistant.in';
22
+ export const DEFAULT_LOGO_URI = 'https://mcp-assistant.in/logo.svg';
23
+ export const DEFAULT_POLICY_URI = 'https://mcp-assistant.in/privacy';
24
+ export const SOFTWARE_ID = '@mcp-ts';
25
+ export const SOFTWARE_VERSION = '1.3.4';
26
+
27
+ // MCP Client Configuration
28
+ export const MCP_CLIENT_NAME = 'mcp-ts-oauth-client';
29
+ export const MCP_CLIENT_VERSION = '2.0';
@@ -1,133 +1,133 @@
1
- /**
2
- * Standardized error classes for MCP Redis library
3
- * Provides consistent error handling across the codebase
4
- */
5
-
6
- /**
7
- * Base error class for all MCP-related errors
8
- */
9
- export class McpError extends Error {
10
- constructor(
11
- public readonly code: string,
12
- message: string,
13
- public readonly cause?: Error
14
- ) {
15
- super(message);
16
- this.name = 'McpError';
17
- // Maintain proper prototype chain for instanceof checks
18
- Object.setPrototypeOf(this, new.target.prototype);
19
- }
20
-
21
- toJSON() {
22
- return {
23
- name: this.name,
24
- code: this.code,
25
- message: this.message,
26
- ...(this.cause ? { cause: this.cause.message } : {}),
27
- };
28
- }
29
- }
30
-
31
- /**
32
- * Thrown when OAuth authorization is required
33
- */
34
- export class UnauthorizedError extends McpError {
35
- constructor(message: string = 'OAuth authorization required', cause?: Error) {
36
- super('UNAUTHORIZED', message, cause);
37
- this.name = 'UnauthorizedError';
38
- }
39
- }
40
-
41
- /**
42
- * Thrown when connection to MCP server fails
43
- */
44
- export class ConnectionError extends McpError {
45
- constructor(message: string, cause?: Error) {
46
- super('CONNECTION_ERROR', message, cause);
47
- this.name = 'ConnectionError';
48
- }
49
- }
50
-
51
- /**
52
- * Thrown when session is not found or expired
53
- */
54
- export class SessionNotFoundError extends McpError {
55
- constructor(sessionId: string, cause?: Error) {
56
- super('SESSION_NOT_FOUND', `Session not found: ${sessionId}`, cause);
57
- this.name = 'SessionNotFoundError';
58
- }
59
- }
60
-
61
- /**
62
- * Thrown when session validation fails
63
- */
64
- export class SessionValidationError extends McpError {
65
- constructor(message: string, cause?: Error) {
66
- super('SESSION_VALIDATION_ERROR', message, cause);
67
- this.name = 'SessionValidationError';
68
- }
69
- }
70
-
71
- /**
72
- * Thrown when authentication fails
73
- */
74
- export class AuthenticationError extends McpError {
75
- constructor(message: string, cause?: Error) {
76
- super('AUTH_ERROR', message, cause);
77
- this.name = 'AuthenticationError';
78
- }
79
- }
80
-
81
- /**
82
- * Thrown when OAuth state validation fails
83
- */
84
- export class InvalidStateError extends McpError {
85
- constructor(message: string = 'Invalid OAuth state', cause?: Error) {
86
- super('INVALID_STATE', message, cause);
87
- this.name = 'InvalidStateError';
88
- }
89
- }
90
-
91
- /**
92
- * Thrown when client is not connected
93
- */
94
- export class NotConnectedError extends McpError {
95
- constructor(message: string = 'Not connected to server', cause?: Error) {
96
- super('NOT_CONNECTED', message, cause);
97
- this.name = 'NotConnectedError';
98
- }
99
- }
100
-
101
- /**
102
- * Thrown when required configuration is missing
103
- */
104
- export class ConfigurationError extends McpError {
105
- constructor(message: string, cause?: Error) {
106
- super('CONFIGURATION_ERROR', message, cause);
107
- this.name = 'ConfigurationError';
108
- }
109
- }
110
-
111
- /**
112
- * Thrown when tool execution fails
113
- */
114
- export class ToolExecutionError extends McpError {
115
- constructor(toolName: string, message: string, cause?: Error) {
116
- super('TOOL_EXECUTION_ERROR', `Tool '${toolName}' failed: ${message}`, cause);
117
- this.name = 'ToolExecutionError';
118
- }
119
- }
120
-
121
- /**
122
- * RPC error codes for SSE communication
123
- */
124
- export const RpcErrorCodes = {
125
- EXECUTION_ERROR: 'EXECUTION_ERROR',
126
- MISSING_IDENTITY: 'MISSING_IDENTITY',
127
- UNAUTHORIZED: 'UNAUTHORIZED',
128
- NO_CONNECTION: 'NO_CONNECTION',
129
- UNKNOWN_METHOD: 'UNKNOWN_METHOD',
130
- INVALID_PARAMS: 'INVALID_PARAMS',
131
- } as const;
132
-
133
- export type RpcErrorCode = typeof RpcErrorCodes[keyof typeof RpcErrorCodes];
1
+ /**
2
+ * Standardized error classes for MCP Redis library
3
+ * Provides consistent error handling across the codebase
4
+ */
5
+
6
+ /**
7
+ * Base error class for all MCP-related errors
8
+ */
9
+ export class McpError extends Error {
10
+ constructor(
11
+ public readonly code: string,
12
+ message: string,
13
+ public readonly cause?: Error
14
+ ) {
15
+ super(message);
16
+ this.name = 'McpError';
17
+ // Maintain proper prototype chain for instanceof checks
18
+ Object.setPrototypeOf(this, new.target.prototype);
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ name: this.name,
24
+ code: this.code,
25
+ message: this.message,
26
+ ...(this.cause ? { cause: this.cause.message } : {}),
27
+ };
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Thrown when OAuth authorization is required
33
+ */
34
+ export class UnauthorizedError extends McpError {
35
+ constructor(message: string = 'OAuth authorization required', cause?: Error) {
36
+ super('UNAUTHORIZED', message, cause);
37
+ this.name = 'UnauthorizedError';
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Thrown when connection to MCP server fails
43
+ */
44
+ export class ConnectionError extends McpError {
45
+ constructor(message: string, cause?: Error) {
46
+ super('CONNECTION_ERROR', message, cause);
47
+ this.name = 'ConnectionError';
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Thrown when session is not found or expired
53
+ */
54
+ export class SessionNotFoundError extends McpError {
55
+ constructor(sessionId: string, cause?: Error) {
56
+ super('SESSION_NOT_FOUND', `Session not found: ${sessionId}`, cause);
57
+ this.name = 'SessionNotFoundError';
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Thrown when session validation fails
63
+ */
64
+ export class SessionValidationError extends McpError {
65
+ constructor(message: string, cause?: Error) {
66
+ super('SESSION_VALIDATION_ERROR', message, cause);
67
+ this.name = 'SessionValidationError';
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Thrown when authentication fails
73
+ */
74
+ export class AuthenticationError extends McpError {
75
+ constructor(message: string, cause?: Error) {
76
+ super('AUTH_ERROR', message, cause);
77
+ this.name = 'AuthenticationError';
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Thrown when OAuth state validation fails
83
+ */
84
+ export class InvalidStateError extends McpError {
85
+ constructor(message: string = 'Invalid OAuth state', cause?: Error) {
86
+ super('INVALID_STATE', message, cause);
87
+ this.name = 'InvalidStateError';
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Thrown when client is not connected
93
+ */
94
+ export class NotConnectedError extends McpError {
95
+ constructor(message: string = 'Not connected to server', cause?: Error) {
96
+ super('NOT_CONNECTED', message, cause);
97
+ this.name = 'NotConnectedError';
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Thrown when required configuration is missing
103
+ */
104
+ export class ConfigurationError extends McpError {
105
+ constructor(message: string, cause?: Error) {
106
+ super('CONFIGURATION_ERROR', message, cause);
107
+ this.name = 'ConfigurationError';
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Thrown when tool execution fails
113
+ */
114
+ export class ToolExecutionError extends McpError {
115
+ constructor(toolName: string, message: string, cause?: Error) {
116
+ super('TOOL_EXECUTION_ERROR', `Tool '${toolName}' failed: ${message}`, cause);
117
+ this.name = 'ToolExecutionError';
118
+ }
119
+ }
120
+
121
+ /**
122
+ * RPC error codes for SSE communication
123
+ */
124
+ export const RpcErrorCodes = {
125
+ EXECUTION_ERROR: 'EXECUTION_ERROR',
126
+ MISSING_IDENTITY: 'MISSING_IDENTITY',
127
+ UNAUTHORIZED: 'UNAUTHORIZED',
128
+ NO_CONNECTION: 'NO_CONNECTION',
129
+ UNKNOWN_METHOD: 'UNKNOWN_METHOD',
130
+ INVALID_PARAMS: 'INVALID_PARAMS',
131
+ } as const;
132
+
133
+ export type RpcErrorCode = typeof RpcErrorCodes[keyof typeof RpcErrorCodes];
@@ -1,28 +1,28 @@
1
- import type { McpConnectionEvent, McpObservabilityEvent } from './events.js';
2
- import type { McpRpcResponse } from './types.js';
3
-
4
- export function isRpcResponseEvent(
5
- event: McpConnectionEvent | McpObservabilityEvent | McpRpcResponse
6
- ): event is McpRpcResponse {
7
- return 'id' in event && ('result' in event || 'error' in event);
8
- }
9
-
10
- export function isConnectionEvent(
11
- event: McpConnectionEvent | McpObservabilityEvent | McpRpcResponse
12
- ): event is McpConnectionEvent {
13
- if (!('type' in event)) {
14
- return false;
15
- }
16
-
17
- switch (event.type) {
18
- case 'state_changed':
19
- case 'tools_discovered':
20
- case 'auth_required':
21
- case 'error':
22
- case 'disconnected':
23
- case 'progress':
24
- return true;
25
- default:
26
- return false;
27
- }
28
- }
1
+ import type { McpConnectionEvent, McpObservabilityEvent } from './events.js';
2
+ import type { McpRpcResponse } from './types.js';
3
+
4
+ export function isRpcResponseEvent(
5
+ event: McpConnectionEvent | McpObservabilityEvent | McpRpcResponse
6
+ ): event is McpRpcResponse {
7
+ return 'id' in event && ('result' in event || 'error' in event);
8
+ }
9
+
10
+ export function isConnectionEvent(
11
+ event: McpConnectionEvent | McpObservabilityEvent | McpRpcResponse
12
+ ): event is McpConnectionEvent {
13
+ if (!('type' in event)) {
14
+ return false;
15
+ }
16
+
17
+ switch (event.type) {
18
+ case 'state_changed':
19
+ case 'tools_discovered':
20
+ case 'auth_required':
21
+ case 'error':
22
+ case 'disconnected':
23
+ case 'progress':
24
+ return true;
25
+ default:
26
+ return false;
27
+ }
28
+ }