(options: McpClientOptions)
| 47 | private isConnected = false |
| 48 | |
| 49 | constructor(options: McpClientOptions) { |
| 50 | this.config = options.config |
| 51 | this.securityPolicy = options.securityPolicy ?? { |
| 52 | requireConsent: true, |
| 53 | auditLevel: 'basic', |
| 54 | maxToolExecutionsPerHour: 1000, |
| 55 | } |
| 56 | this.onToolsChanged = options.onToolsChanged |
| 57 | this.authProvider = options.authProvider |
| 58 | const resolvedIP = options.resolvedIP |
| 59 | |
| 60 | this.connectionStatus = { connected: false } |
| 61 | |
| 62 | if (!this.config.url) { |
| 63 | throw new McpError('URL required for Streamable HTTP transport') |
| 64 | } |
| 65 | |
| 66 | if (this.config.authType === 'oauth' && this.authProvider == null) { |
| 67 | throw new McpError('OAuth MCP server requires an authProvider') |
| 68 | } |
| 69 | const useOauth = this.config.authType === 'oauth' |
| 70 | this.transport = new StreamableHTTPClientTransport(new URL(this.config.url), { |
| 71 | authProvider: useOauth ? this.authProvider : undefined, |
| 72 | requestInit: { headers: this.config.headers }, |
| 73 | ...(resolvedIP ? { fetch: createPinnedFetch(resolvedIP) } : {}), |
| 74 | }) |
| 75 | |
| 76 | this.client = new Client( |
| 77 | { |
| 78 | name: 'sim-platform', |
| 79 | version: '1.0.0', |
| 80 | }, |
| 81 | { |
| 82 | capabilities: {}, |
| 83 | } |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Initialize connection to MCP server. |
nothing calls this directly
no test coverage detected