@mcp-b/transports 1.1.0 → 1.1.2-beta.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/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/browser-types.ts","../src/ExtensionClientTransport.ts","../src/ExtensionServerTransport.ts","../src/IframeChildTransport.ts","../src/IframeParentTransport.ts","../src/TabClientTransport.ts","../src/TabServerTransport.ts","../src/UserScriptClientTransport.ts","../src/UserScriptServerTransport.ts"],"sourcesContent":[],"mappings":";;;;;;;AAKY,KAAA,OAAA,GAAO,MAAA;AAKnB;AAKA;AAUA;AAkBiB,KAjCL,QAAA,GAiCkB,MAAA;;;;AAac,UAzC3B,iBAAA,CAyC2B;EAY3B;;;EA6BE,UAAA,CAAA,EA9EJ,OA8EI;;;AAWnB;AAOA;AAQiB,UAlGA,aAAA,CAkGe;EAMf;AASjB;;EAEY,UAAA,EAAA,MAAA;EACD;;AAKX;EA6Ba,QAAA,EAAA,OAGH;EAGG;AASb;AAQA;EAKa,aAAA,EAAA,OAAA;AAMb;AAKA;;;UA3KiB,aAAA;EClCA;AAkDjB;;;;;EAyIsB,SAAA,CAAA,QAAA,CAAA,EAAA,MAAA,EAAA,YAAA,CAAA,EDlJwB,OCkJxB,EAAA,KAAA,CAAA,EAAA,MAAA,CAAA,EDlJkD,WCkJlD,EAAA;EAA2B;;;;EAzIS,cAAA,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EDHrB,OCGqB,GAAA,IAAA;;;;AClD1D;EAuBa,WAAA,CAAA,QAAyB,CAAzB,EAAA,MAAyB,CAAA,EAAA,IAAA;;;;;AAiCrB,UFGA,mBAAA,CEHA;EA0DK;;;;;;sCFhDgB,oBAAoB;;;AGxE1D;AAyBA;EAUoB,UAAA,CAAA,QAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EACI;;;;EA6Fe,gBAAA,EAAA,QAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAyBtB;;;;;;AC1JjB;EA6Ba,aAAA,EAAA,EJiEM,aIjEgB;EAQG;;;EAQf,MAAA,CAAA,EJsDZ,aItDY;;;;;AAhBuB,UJ4E7B,SAAA,SAAkB,MI5EW,CAAA;EAAS,GAAA,CAAA,EJ6E/C,mBI7E+C;;;;AC7BvD;AAOa,ULyGI,oBAAA,CKzGe;EAKM,IAAA,EAAA,iBAAA;EAKlB,gBAAA,EAAA,MAAA;EACI,eAAA,CAAA,EAAA,MAAA;EAED,aAAA,EAAA,OAAA;EAkBN,QAAA,EL+EL,QK/EK;;AA+DsB,ULmBtB,eAAA,CKnBsB;EAmBtB,IAAA,EAAA,WAAA;EAjH0B,OAAA,ELmHhC,OKnHgC;EAAS,OAAA,ELoHzC,cKpHyC;;ULuHnC,qBAAA;;EM9HA,OAAA,ENgIN,OMhIM;EAOJ,OAAA,EN0HF,cM1HqB;;;;;AAiFV,UN+CL,WAAA,CM/CK;EAAiB,OAAA,ENgD5B,OMhD4B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/browser-types.ts","../src/ExtensionClientTransport.ts","../src/ExtensionServerTransport.ts","../src/IframeChildTransport.ts","../src/IframeParentTransport.ts","../src/TabClientTransport.ts","../src/TabServerTransport.ts","../src/UserScriptClientTransport.ts","../src/UserScriptServerTransport.ts"],"sourcesContent":[],"mappings":";;;;;;;AAKY,KAAA,OAAA,GAAO,MAAA;AAKnB;AAKA;AAUA;AAkBiB,KAjCL,QAAA,GAiCkB,MAAA;;;;AAac,UAzC3B,iBAAA,CAyC2B;EAY3B;;;EA6BE,UAAA,CAAA,EA9EJ,OA8EI;;;AAWnB;AAOA;AAQiB,UAlGA,aAAA,CAkGe;EAMf;AASjB;;EAEY,UAAA,EAAA,MAAA;EACD;;AAKX;EA6Ba,Q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CAAA;EAcN;;;EAmGuD,IAAA,CAAA,OAAA,EOtElD,cPsEkD,EAAA,QAAA,CAAA,EOtEvB,oBPsEuB,CAAA,EOtEA,OPsEA,CAAA,IAAA,CAAA;EAuBvD;;;WOpEA;;;AN9IjB;EAuBa,QAAA,QAAA;EAcO;;;EAG8B,QAAA,eAAA;EAgBjC;;;EA0DuD,QAAA,cAAA;EAyBvD;;;;;;ICjJA,WAAA,EAAA,MAAA;IAyBJ,aAAA,EAAA,MAAqB;IAUd,YAAA,EAAA,MAAA;EACI,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{JSONRPCMessageSchema as e}from"@modelcontextprotocol/sdk/types.js";let t=function(e){return e.START=`start`,e.STARTED=`started`,e.STOP=`stop`,e.STOPPED=`stopped`,e.PING=`ping`,e.PONG=`pong`,e.ERROR=`error`,e.LIST_TOOLS=`list_tools`,e.CALL_TOOL=`call_tool`,e.TOOL_LIST_UPDATED=`tool_list_updated`,e.TOOL_LIST_UPDATED_ACK=`tool_list_updated_ack`,e.PROCESS_DATA=`process_data`,e.SERVER_STARTED=`server_started`,e.SERVER_STOPPED=`server_stopped`,e.ERROR_FROM_NATIVE_HOST=`error_from_native_host`,e.CONNECT_NATIVE=`connectNative`,e.PING_NATIVE=`ping_native`,e.DISCONNECT_NATIVE=`disconnect_native`,e}({});const n={NAME:`com.chromemcp.nativehost`,DEFAULT_PORT:12306},r={NATIVE_CONNECTION_FAILED:`Failed to connect to native host`,NATIVE_DISCONNECTED:`Native connection disconnected`,SERVER_STATUS_LOAD_FAILED:`Failed to load server status`,TOOL_EXECUTION_FAILED:`Tool execution failed`,SERVER_STATUS_SAVE_FAILED:`Failed to save server status`},i={TOOL_EXECUTED:`Tool executed successfully`,CONNECTION_ESTABLISHED:`Connection established`,SERVER_STARTED:`Server started successfully`,SERVER_STOPPED:`Server stopped successfully`},a={SERVER_STATUS:`serverStatus`},o={GET_SERVER_STATUS:`get_server_status`,REFRESH_SERVER_STATUS:`refresh_server_status`,SERVER_STATUS_CHANGED:`server_status_changed`},s=n.NAME;var c=class{_port;_extensionId;_portName;_messageHandler;_disconnectHandler;_isReconnecting=!1;_reconnectAttempts=0;_reconnectTimer;_currentReconnectDelay;_isStarted=!1;_isClosed=!1;_autoReconnect;_maxReconnectAttempts;_reconnectDelay;_maxReconnectDelay;_reconnectBackoffMultiplier;onclose;onerror;onmessage;constructor(e={}){this._extensionId=e.extensionId,this._portName=e.portName||`mcp`,this._autoReconnect=e.autoReconnect??!0,this._maxReconnectAttempts=e.maxReconnectAttempts??10,this._reconnectDelay=e.reconnectDelay??1e3,this._maxReconnectDelay=e.maxReconnectDelay??3e4,this._reconnectBackoffMultiplier=e.reconnectBackoffMultiplier??1.5,this._currentReconnectDelay=this._reconnectDelay}async start(){if(this._isStarted&&this._port){console.warn(`ExtensionClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return}this._isStarted=!0,this._isClosed=!1,await this._connect()}async _connect(){return new Promise((t,n)=>{if(!chrome?.runtime?.connect){n(Error(`Chrome runtime API not available. This transport must be used in a Chrome extension context.`));return}try{this._extensionId?this._port=chrome.runtime.connect(this._extensionId,{name:this._portName}):this._port=chrome.runtime.connect({name:this._portName}),this._messageHandler=t=>{try{if(t.type===`keep-alive`)return;let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{this._cleanup(),this._isStarted&&!this._isClosed&&this._autoReconnect?this._scheduleReconnect():this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler);let r=chrome.runtime.lastError;if(r){if(this._cleanup(),this._isReconnecting&&this._isStarted&&!this._isClosed&&this._autoReconnect){n(Error(`Connection failed: ${r.message}`));return}n(Error(`Connection failed: ${r.message}`));return}this._reconnectAttempts=0,this._currentReconnectDelay=this._reconnectDelay,this._isReconnecting=!1,t()}catch(e){n(e)}})}async send(e,t){if(!this._isStarted)throw Error(`Transport not started`);if(this._isClosed)throw Error(`Transport is closed`);if(!this._port)throw Error(`Not connected`);try{this._port.postMessage(e)}catch(e){throw Error(`Failed to send message: ${e}`)}}async close(){if(this._isClosed=!0,this._isStarted=!1,this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler)),this._port=void 0}_scheduleReconnect(){if(!(this._isReconnecting||this._isClosed||!this._isStarted)){if(this._isReconnecting=!0,this._reconnectAttempts>=this._maxReconnectAttempts){console.error(`Maximum reconnection attempts reached`),this._isReconnecting=!1,this.onerror?.(Error(`Maximum reconnection attempts reached`)),this.onclose?.();return}this._reconnectAttempts++,console.log(`Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`),this._reconnectTimer=setTimeout(()=>{this._attemptReconnect()},this._currentReconnectDelay),this._currentReconnectDelay=Math.min(this._currentReconnectDelay*this._reconnectBackoffMultiplier,this._maxReconnectDelay)}}async _attemptReconnect(){if(!(this._isClosed||!this._isStarted))try{if(chrome?.runtime?.sendMessage)try{await chrome.runtime.sendMessage({type:`ping`})}catch{}await this._connect(),console.log(`Reconnection successful`),this._isReconnecting=!1}catch(e){console.error(`Reconnection failed:`,e),this._scheduleReconnect()}}},l=class{_port;_started=!1;_messageHandler;_disconnectHandler;_keepAliveTimer;_options;_connectionInfo;onclose;onerror;onmessage;constructor(e,t={}){this._port=e,this._options={keepAlive:t.keepAlive??!0,keepAliveInterval:t.keepAliveInterval??1e3},this._connectionInfo={connectedAt:Date.now(),lastMessageAt:Date.now(),messageCount:0}}async start(){if(this._started)throw Error(`ExtensionServerTransport already started! If using Server class, note that connect() calls start() automatically.`);if(!this._port)throw Error(`Port not available`);this._started=!0,this._messageHandler=t=>{try{if(this._connectionInfo.lastMessageAt=Date.now(),this._connectionInfo.messageCount++,t.type===`ping`){this._port.postMessage({type:`pong`});return}let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{console.log(`[ExtensionServerTransport] Client disconnected after ${Date.now()-this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`),this._cleanup(),this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler),this._options.keepAlive&&this._startKeepAlive(),console.log(`[ExtensionServerTransport] Started with client: ${this._port.sender?.id||`unknown`}`)}async send(e,t){if(!this._started)throw Error(`Transport not started`);if(!this._port)throw Error(`Not connected to client`);try{this._port.postMessage(e)}catch(e){throw chrome.runtime.lastError||!this._port?(this._cleanup(),this.onclose?.(),Error(`Client disconnected`)):Error(`Failed to send message: ${e}`)}}async close(){if(this._started=!1,this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0),this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler))}_startKeepAlive(){this._keepAliveTimer||=(console.log(`[ExtensionServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`),setInterval(()=>{if(!this._port){this._stopKeepAlive();return}try{this._port.postMessage({type:`keep-alive`,timestamp:Date.now()})}catch(e){console.error(`[ExtensionServerTransport] Keep-alive failed:`,e),this._stopKeepAlive()}},this._options.keepAliveInterval))}_stopKeepAlive(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0)}getConnectionInfo(){return{...this._connectionInfo,uptime:Date.now()-this._connectionInfo.connectedAt,isConnected:!!this._port&&this._started}}},u=class{_started=!1;_allowedOrigins;_channelId;_messageHandler;_clientOrigin;_serverReadyTimeout;_serverReadyRetryMs;onclose;onerror;onmessage;constructor(e){if(!e.allowedOrigins||e.allowedOrigins.length===0)throw Error(`At least one allowed origin must be specified`);this._allowedOrigins=e.allowedOrigins,this._channelId=e.channelId||`mcp-iframe`,this._serverReadyRetryMs=e.serverReadyRetryMs??250}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(!this._allowedOrigins.includes(t.origin)&&!this._allowedOrigins.includes(`*`)||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`client-to-server`)return;this._clientOrigin=t.origin;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-check-ready`){this.broadcastServerReady();return}try{let t=e.parse(n);this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.broadcastServerReady()}broadcastServerReady(){window.parent&&window.parent!==window?(window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},`*`),this.clearServerReadyRetry()):this.scheduleServerReadyRetry()}scheduleServerReadyRetry(){this._serverReadyTimeout||=setTimeout(()=>{this._serverReadyTimeout=void 0,this._started&&this.broadcastServerReady()},this._serverReadyRetryMs)}clearServerReadyRetry(){this._serverReadyTimeout&&=(clearTimeout(this._serverReadyTimeout),void 0)}async send(e){if(!this._started)throw Error(`Transport not started`);if(!this._clientOrigin){console.warn(`[IframeChildTransport] No client connected, message not sent`);return}window.parent&&window.parent!==window?window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:e},this._clientOrigin):console.warn(`[IframeChildTransport] Not running in an iframe, message not sent`)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._started=!1,this._clientOrigin&&window.parent&&window.parent!==window&&window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-stopped`},`*`),this.clearServerReadyRetry(),this.onclose?.()}},d=class{_started=!1;_iframe;_targetOrigin;_channelId;_messageHandler;_checkReadyTimeout;_checkReadyRetryMs;serverReadyPromise;_serverReadyResolve;_serverReadyReject;onclose;onerror;onmessage;constructor(e){if(!e.iframe)throw Error(`iframe element is required`);if(!e.targetOrigin)throw Error(`targetOrigin must be explicitly set for security`);this._iframe=e.iframe,this._targetOrigin=e.targetOrigin,this._channelId=e.channelId||`mcp-iframe`,this._checkReadyRetryMs=e.checkReadyRetryMs??250;let{promise:t,resolve:n,reject:r}=Promise.withResolvers();this.serverReadyPromise=t,this._serverReadyResolve=n,this._serverReadyReject=r}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(t.origin!==this._targetOrigin||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`server-to-client`)return;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-server-ready`){this._serverReadyResolve(),this.clearCheckReadyRetry();return}if(typeof n==`string`&&n===`mcp-server-stopped`){console.log(`[IframeParentTransport] Received mcp-server-stopped event, closing transport`),this.close();return}try{let t=e.parse(n);this._serverReadyResolve(),this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.sendCheckReady()}sendCheckReady(){let e=this._iframe.contentWindow;if(!e){console.warn(`[IframeParentTransport] iframe.contentWindow not available, will retry`),this.scheduleCheckReadyRetry();return}e.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:`mcp-check-ready`},this._targetOrigin)}scheduleCheckReadyRetry(){this._checkReadyTimeout||=setTimeout(()=>{this._checkReadyTimeout=void 0,this._started&&this.sendCheckReady()},this._checkReadyRetryMs)}clearCheckReadyRetry(){this._checkReadyTimeout&&=(clearTimeout(this._checkReadyTimeout),void 0)}async send(e){if(!this._started)throw Error(`Transport not started`);await this.serverReadyPromise;let t=this._iframe.contentWindow;if(!t)throw Error(`iframe.contentWindow not available`);t.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:e},this._targetOrigin)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._serverReadyReject(Error(`Transport closed before server ready`)),this.clearCheckReadyRetry(),this._started=!1,this.onclose?.()}},f=class{_started=!1;_targetOrigin;_channelId;_messageHandler;serverReadyPromise;_serverReadyResolve;_serverReadyReject;onclose;onerror;onmessage;constructor(e){if(!e.targetOrigin)throw Error(`targetOrigin must be explicitly set for security`);this._targetOrigin=e.targetOrigin,this._channelId=e.channelId||`mcp-default`;let{promise:t,resolve:n,reject:r}=Promise.withResolvers();this.serverReadyPromise=t,this._serverReadyResolve=()=>{n()},this._serverReadyReject=e=>{r(e)}}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(t.origin!==this._targetOrigin||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`server-to-client`)return;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-server-ready`){this._serverReadyResolve();return}if(typeof n==`string`&&n===`mcp-server-stopped`){console.log(`[TabClientTransport] Received mcp-server-stopped event, closing transport`),this.close();return}try{let t=e.parse(n);this._serverReadyResolve(),this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.sendCheckReady()}sendCheckReady(){window.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:`mcp-check-ready`},this._targetOrigin)}async send(e){if(!this._started)throw Error(`Transport not started`);await this.serverReadyPromise,window.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:e},this._targetOrigin)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._serverReadyReject(Error(`Transport closed before server ready`)),this._started=!1,this.onclose?.()}},p=class{_started=!1;_allowedOrigins;_channelId;_messageHandler;_clientOrigin;onclose;onerror;onmessage;constructor(e){if(!e.allowedOrigins||e.allowedOrigins.length===0)throw Error(`At least one allowed origin must be specified`);this._allowedOrigins=e.allowedOrigins,this._channelId=e.channelId||`mcp-default`}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(!this._allowedOrigins.includes(t.origin)&&!this._allowedOrigins.includes(`*`)||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`client-to-server`)return;this._clientOrigin=t.origin;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-check-ready`){window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},this._clientOrigin);return}try{let t=e.parse(n);this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},`*`)}async send(e){if(!this._started)throw Error(`Transport not started`);if(!this._clientOrigin){console.warn(`[TabServerTransport] No client connected, message not sent`);return}window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:e},this._clientOrigin)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._started=!1,window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-stopped`},`*`),this.onclose?.()}},m=class{_port;_extensionId;_portName;_messageHandler;_disconnectHandler;_isReconnecting=!1;_reconnectAttempts=0;_reconnectTimer;_currentReconnectDelay;_isStarted=!1;_isClosed=!1;_autoReconnect;_maxReconnectAttempts;_reconnectDelay;_maxReconnectDelay;_reconnectBackoffMultiplier;onclose;onerror;onmessage;constructor(e={}){this._extensionId=e.extensionId,this._portName=e.portName||`mcp`,this._autoReconnect=e.autoReconnect??!0,this._maxReconnectAttempts=e.maxReconnectAttempts??10,this._reconnectDelay=e.reconnectDelay??1e3,this._maxReconnectDelay=e.maxReconnectDelay??3e4,this._reconnectBackoffMultiplier=e.reconnectBackoffMultiplier??1.5,this._currentReconnectDelay=this._reconnectDelay}async start(){if(this._isStarted&&this._port){console.warn(`UserScriptClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return}this._isStarted=!0,this._isClosed=!1,await this._connect()}async _connect(){return new Promise((t,n)=>{if(!chrome?.runtime?.connect){n(Error(`Chrome runtime API not available. This transport must be used in a Chrome MV3 User Script context.`));return}try{this._extensionId?this._port=chrome.runtime.connect(this._extensionId,{name:this._portName}):this._port=chrome.runtime.connect({name:this._portName}),this._messageHandler=t=>{try{if(t.type===`keep-alive`)return;let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{this._cleanup(),this._isStarted&&!this._isClosed&&this._autoReconnect?this._scheduleReconnect():this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler);let r=chrome.runtime.lastError;if(r){if(this._cleanup(),this._isReconnecting&&this._isStarted&&!this._isClosed&&this._autoReconnect){n(Error(`Connection failed: ${r.message}`));return}n(Error(`Connection failed: ${r.message}`));return}this._reconnectAttempts=0,this._currentReconnectDelay=this._reconnectDelay,this._isReconnecting=!1,t()}catch(e){n(e)}})}async send(e,t){if(!this._isStarted)throw Error(`Transport not started`);if(this._isClosed)throw Error(`Transport is closed`);if(!this._port)throw Error(`Not connected`);try{this._port.postMessage(e)}catch(e){throw Error(`Failed to send message: ${e}`)}}async close(){if(this._isClosed=!0,this._isStarted=!1,this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler)),this._port=void 0}_scheduleReconnect(){if(!(this._isReconnecting||this._isClosed||!this._isStarted)){if(this._isReconnecting=!0,this._reconnectAttempts>=this._maxReconnectAttempts){console.error(`Maximum reconnection attempts reached`),this._isReconnecting=!1,this.onerror?.(Error(`Maximum reconnection attempts reached`)),this.onclose?.();return}this._reconnectAttempts++,console.log(`Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`),this._reconnectTimer=setTimeout(()=>{this._attemptReconnect()},this._currentReconnectDelay),this._currentReconnectDelay=Math.min(this._currentReconnectDelay*this._reconnectBackoffMultiplier,this._maxReconnectDelay)}}async _attemptReconnect(){if(!(this._isClosed||!this._isStarted))try{if(chrome?.runtime?.sendMessage)try{await chrome.runtime.sendMessage({type:`ping`})}catch{}await this._connect(),console.log(`Reconnection successful`),this._isReconnecting=!1}catch(e){console.error(`Reconnection failed:`,e),this._scheduleReconnect()}}},h=class{_port;_started=!1;_messageHandler;_disconnectHandler;_keepAliveTimer;_options;_connectionInfo;onclose;onerror;onmessage;constructor(e,t={}){this._port=e,this._options={keepAlive:t.keepAlive??!0,keepAliveInterval:t.keepAliveInterval??1e3},this._connectionInfo={connectedAt:Date.now(),lastMessageAt:Date.now(),messageCount:0}}async start(){if(this._started)throw Error(`UserScriptServerTransport already started! If using Server class, note that connect() calls start() automatically.`);if(!this._port)throw Error(`Port not available`);this._started=!0,this._messageHandler=t=>{try{if(this._connectionInfo.lastMessageAt=Date.now(),this._connectionInfo.messageCount++,t.type===`ping`){this._port.postMessage({type:`pong`});return}let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{console.log(`[UserScriptServerTransport] Client disconnected after ${Date.now()-this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`),this._cleanup(),this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler),this._options.keepAlive&&this._startKeepAlive(),console.log(`[UserScriptServerTransport] Started with client: ${this._port.sender?.id||`unknown`}`)}async send(e,t){if(!this._started)throw Error(`Transport not started`);if(!this._port)throw Error(`Not connected to client`);try{this._port.postMessage(e)}catch(e){throw chrome.runtime.lastError||!this._port?(this._cleanup(),this.onclose?.(),Error(`Client disconnected`)):Error(`Failed to send message: ${e}`)}}async close(){if(this._started=!1,this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0),this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler))}_startKeepAlive(){this._keepAliveTimer||=(console.log(`[UserScriptServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`),setInterval(()=>{if(!this._port){this._stopKeepAlive();return}try{this._port.postMessage({type:`keep-alive`,timestamp:Date.now()})}catch(e){console.error(`[UserScriptServerTransport] Keep-alive failed:`,e),this._stopKeepAlive()}},this._options.keepAliveInterval))}_stopKeepAlive(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0)}getConnectionInfo(){return{...this._connectionInfo,uptime:Date.now()-this._connectionInfo.connectedAt,isConnected:!!this._port&&this._started}}};export{o as BACKGROUND_MESSAGE_TYPES,r as ERROR_MESSAGES,c as ExtensionClientTransport,l as ExtensionServerTransport,s as HOST_NAME,u as IframeChildTransport,d as IframeParentTransport,n as NATIVE_HOST,t as NativeMessageType,a as STORAGE_KEYS,i as SUCCESS_MESSAGES,f as TabClientTransport,p as TabServerTransport,m as UserScriptClientTransport,h as UserScriptServerTransport};
|
|
1
|
+
import{JSONRPCMessageSchema as e}from"@modelcontextprotocol/sdk/types.js";let t=function(e){return e.START=`start`,e.STARTED=`started`,e.STOP=`stop`,e.STOPPED=`stopped`,e.PING=`ping`,e.PONG=`pong`,e.ERROR=`error`,e.LIST_TOOLS=`list_tools`,e.CALL_TOOL=`call_tool`,e.TOOL_LIST_UPDATED=`tool_list_updated`,e.TOOL_LIST_UPDATED_ACK=`tool_list_updated_ack`,e.PROCESS_DATA=`process_data`,e.SERVER_STARTED=`server_started`,e.SERVER_STOPPED=`server_stopped`,e.ERROR_FROM_NATIVE_HOST=`error_from_native_host`,e.CONNECT_NATIVE=`connectNative`,e.PING_NATIVE=`ping_native`,e.DISCONNECT_NATIVE=`disconnect_native`,e}({});const n={NAME:`com.chromemcp.nativehost`,DEFAULT_PORT:12306},r={NATIVE_CONNECTION_FAILED:`Failed to connect to native host`,NATIVE_DISCONNECTED:`Native connection disconnected`,SERVER_STATUS_LOAD_FAILED:`Failed to load server status`,TOOL_EXECUTION_FAILED:`Tool execution failed`,SERVER_STATUS_SAVE_FAILED:`Failed to save server status`},i={TOOL_EXECUTED:`Tool executed successfully`,CONNECTION_ESTABLISHED:`Connection established`,SERVER_STARTED:`Server started successfully`,SERVER_STOPPED:`Server stopped successfully`},a={SERVER_STATUS:`serverStatus`},o={GET_SERVER_STATUS:`get_server_status`,REFRESH_SERVER_STATUS:`refresh_server_status`,SERVER_STATUS_CHANGED:`server_status_changed`},s=n.NAME;var c=class{_port;_extensionId;_portName;_messageHandler;_disconnectHandler;_isReconnecting=!1;_reconnectAttempts=0;_reconnectTimer;_currentReconnectDelay;_isStarted=!1;_isClosed=!1;_autoReconnect;_maxReconnectAttempts;_reconnectDelay;_maxReconnectDelay;_reconnectBackoffMultiplier;onclose;onerror;onmessage;constructor(e={}){this._extensionId=e.extensionId,this._portName=e.portName||`mcp`,this._autoReconnect=e.autoReconnect??!0,this._maxReconnectAttempts=e.maxReconnectAttempts??10,this._reconnectDelay=e.reconnectDelay??1e3,this._maxReconnectDelay=e.maxReconnectDelay??3e4,this._reconnectBackoffMultiplier=e.reconnectBackoffMultiplier??1.5,this._currentReconnectDelay=this._reconnectDelay}async start(){if(this._isStarted&&this._port){console.warn(`ExtensionClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return}this._isStarted=!0,this._isClosed=!1,await this._connect()}async _connect(){return new Promise((t,n)=>{if(!chrome?.runtime?.connect){n(Error(`Chrome runtime API not available. This transport must be used in a Chrome extension context.`));return}try{this._extensionId?this._port=chrome.runtime.connect(this._extensionId,{name:this._portName}):this._port=chrome.runtime.connect({name:this._portName}),this._messageHandler=t=>{try{if(t.type===`keep-alive`)return;let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{this._cleanup(),this._isStarted&&!this._isClosed&&this._autoReconnect?this._scheduleReconnect():this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler);let r=chrome.runtime.lastError;if(r){if(this._cleanup(),this._isReconnecting&&this._isStarted&&!this._isClosed&&this._autoReconnect){n(Error(`Connection failed: ${r.message}`));return}n(Error(`Connection failed: ${r.message}`));return}this._reconnectAttempts=0,this._currentReconnectDelay=this._reconnectDelay,this._isReconnecting=!1,t()}catch(e){n(e)}})}async send(e,t){if(!this._isStarted)throw Error(`Transport not started`);if(this._isClosed)throw Error(`Transport is closed`);if(!this._port)throw Error(`Not connected`);try{this._port.postMessage(e)}catch(e){throw Error(`Failed to send message: ${e}`)}}async close(){if(this._isClosed=!0,this._isStarted=!1,this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler)),this._port=void 0}_scheduleReconnect(){if(!(this._isReconnecting||this._isClosed||!this._isStarted)){if(this._isReconnecting=!0,this._reconnectAttempts>=this._maxReconnectAttempts){console.error(`Maximum reconnection attempts reached`),this._isReconnecting=!1,this.onerror?.(Error(`Maximum reconnection attempts reached`)),this.onclose?.();return}this._reconnectAttempts++,console.log(`Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`),this._reconnectTimer=setTimeout(()=>{this._attemptReconnect()},this._currentReconnectDelay),this._currentReconnectDelay=Math.min(this._currentReconnectDelay*this._reconnectBackoffMultiplier,this._maxReconnectDelay)}}async _attemptReconnect(){if(!(this._isClosed||!this._isStarted))try{if(chrome?.runtime?.sendMessage)try{await chrome.runtime.sendMessage({type:`ping`})}catch{}await this._connect(),console.log(`Reconnection successful`),this._isReconnecting=!1}catch(e){console.error(`Reconnection failed:`,e),this._scheduleReconnect()}}},l=class{_port;_started=!1;_messageHandler;_disconnectHandler;_keepAliveTimer;_options;_connectionInfo;onclose;onerror;onmessage;constructor(e,t={}){this._port=e,this._options={keepAlive:t.keepAlive??!0,keepAliveInterval:t.keepAliveInterval??1e3},this._connectionInfo={connectedAt:Date.now(),lastMessageAt:Date.now(),messageCount:0}}async start(){if(this._started)throw Error(`ExtensionServerTransport already started! If using Server class, note that connect() calls start() automatically.`);if(!this._port)throw Error(`Port not available`);this._started=!0,this._messageHandler=t=>{try{if(this._connectionInfo.lastMessageAt=Date.now(),this._connectionInfo.messageCount++,t.type===`ping`){this._port.postMessage({type:`pong`});return}let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{console.log(`[ExtensionServerTransport] Client disconnected after ${Date.now()-this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`),this._cleanup(),this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler),this._options.keepAlive&&this._startKeepAlive(),console.log(`[ExtensionServerTransport] Started with client: ${this._port.sender?.id||`unknown`}`)}async send(e,t){if(!this._started)throw Error(`Transport not started`);if(!this._port)throw Error(`Not connected to client`);try{this._port.postMessage(e)}catch(e){throw chrome.runtime.lastError||!this._port?(this._cleanup(),this.onclose?.(),Error(`Client disconnected`)):Error(`Failed to send message: ${e}`)}}async close(){if(this._started=!1,this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0),this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler))}_startKeepAlive(){this._keepAliveTimer||=(console.log(`[ExtensionServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`),setInterval(()=>{if(!this._port){this._stopKeepAlive();return}try{this._port.postMessage({type:`keep-alive`,timestamp:Date.now()})}catch(e){console.error(`[ExtensionServerTransport] Keep-alive failed:`,e),this._stopKeepAlive()}},this._options.keepAliveInterval))}_stopKeepAlive(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0)}getConnectionInfo(){return{...this._connectionInfo,uptime:Date.now()-this._connectionInfo.connectedAt,isConnected:!!this._port&&this._started}}},u=class{_started=!1;_allowedOrigins;_channelId;_messageHandler;_clientOrigin;_serverReadyTimeout;_serverReadyRetryMs;onclose;onerror;onmessage;constructor(e){if(!e.allowedOrigins||e.allowedOrigins.length===0)throw Error(`At least one allowed origin must be specified`);this._allowedOrigins=e.allowedOrigins,this._channelId=e.channelId||`mcp-iframe`,this._serverReadyRetryMs=e.serverReadyRetryMs??250}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(!this._allowedOrigins.includes(t.origin)&&!this._allowedOrigins.includes(`*`)||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`client-to-server`)return;this._clientOrigin=t.origin;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-check-ready`){this.broadcastServerReady();return}try{let t=e.parse(n);this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.broadcastServerReady()}broadcastServerReady(){window.parent&&window.parent!==window?(window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},`*`),this.clearServerReadyRetry()):this.scheduleServerReadyRetry()}scheduleServerReadyRetry(){this._serverReadyTimeout||=setTimeout(()=>{this._serverReadyTimeout=void 0,this._started&&this.broadcastServerReady()},this._serverReadyRetryMs)}clearServerReadyRetry(){this._serverReadyTimeout&&=(clearTimeout(this._serverReadyTimeout),void 0)}async send(e){if(!this._started)throw Error(`Transport not started`);if(!this._clientOrigin){console.warn(`[IframeChildTransport] No client connected, message not sent`);return}window.parent&&window.parent!==window?window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:e},this._clientOrigin):console.warn(`[IframeChildTransport] Not running in an iframe, message not sent`)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._started=!1,this._clientOrigin&&window.parent&&window.parent!==window&&window.parent.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-stopped`},`*`),this.clearServerReadyRetry(),this.onclose?.()}},d=class{_started=!1;_iframe;_targetOrigin;_channelId;_messageHandler;_checkReadyTimeout;_checkReadyRetryMs;serverReadyPromise;_serverReadyResolve;_serverReadyReject;onclose;onerror;onmessage;constructor(e){if(!e.iframe)throw Error(`iframe element is required`);if(!e.targetOrigin)throw Error(`targetOrigin must be explicitly set for security`);this._iframe=e.iframe,this._targetOrigin=e.targetOrigin,this._channelId=e.channelId||`mcp-iframe`,this._checkReadyRetryMs=e.checkReadyRetryMs??250;let{promise:t,resolve:n,reject:r}=Promise.withResolvers();this.serverReadyPromise=t,this._serverReadyResolve=n,this._serverReadyReject=r}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(t.origin!==this._targetOrigin||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`server-to-client`)return;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-server-ready`){this._serverReadyResolve(),this.clearCheckReadyRetry();return}if(typeof n==`string`&&n===`mcp-server-stopped`){console.log(`[IframeParentTransport] Received mcp-server-stopped event, closing transport`),this.close();return}try{let t=e.parse(n);this._serverReadyResolve(),this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.sendCheckReady()}sendCheckReady(){let e=this._iframe.contentWindow;if(!e){console.warn(`[IframeParentTransport] iframe.contentWindow not available, will retry`),this.scheduleCheckReadyRetry();return}e.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:`mcp-check-ready`},this._targetOrigin)}scheduleCheckReadyRetry(){this._checkReadyTimeout||=setTimeout(()=>{this._checkReadyTimeout=void 0,this._started&&this.sendCheckReady()},this._checkReadyRetryMs)}clearCheckReadyRetry(){this._checkReadyTimeout&&=(clearTimeout(this._checkReadyTimeout),void 0)}async send(e){if(!this._started)throw Error(`Transport not started`);await this.serverReadyPromise;let t=this._iframe.contentWindow;if(!t)throw Error(`iframe.contentWindow not available`);t.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:e},this._targetOrigin)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._serverReadyReject(Error(`Transport closed before server ready`)),this.clearCheckReadyRetry(),this._started=!1,this.onclose?.()}},f=class{_started=!1;_targetOrigin;_channelId;_messageHandler;serverReadyPromise;_serverReadyResolve;_serverReadyReject;onclose;onerror;onmessage;constructor(e){if(!e.targetOrigin)throw Error(`targetOrigin must be explicitly set for security`);this._targetOrigin=e.targetOrigin,this._channelId=e.channelId||`mcp-default`;let{promise:t,resolve:n,reject:r}=Promise.withResolvers();this.serverReadyPromise=t,this._serverReadyResolve=()=>{n()},this._serverReadyReject=e=>{r(e)}}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(t.origin!==this._targetOrigin||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`server-to-client`)return;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-server-ready`){this._serverReadyResolve();return}if(typeof n==`string`&&n===`mcp-server-stopped`){console.log(`[TabClientTransport] Received mcp-server-stopped event, closing transport`),this.close();return}try{let t=e.parse(n);this._serverReadyResolve(),this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,this.sendCheckReady()}sendCheckReady(){window.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:`mcp-check-ready`},this._targetOrigin)}async send(e){if(!this._started)throw Error(`Transport not started`);await this.serverReadyPromise,window.postMessage({channel:this._channelId,type:`mcp`,direction:`client-to-server`,payload:e},this._targetOrigin)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._serverReadyReject(Error(`Transport closed before server ready`)),this._started=!1,this.onclose?.()}},p=class{_started=!1;_allowedOrigins;_channelId;_messageHandler;_clientOrigin;onclose;onerror;onmessage;constructor(e){if(!e.allowedOrigins||e.allowedOrigins.length===0)throw Error(`At least one allowed origin must be specified`);this._allowedOrigins=e.allowedOrigins,this._channelId=e.channelId||`mcp-default`}async start(){if(this._started)throw Error(`Transport already started`);this._messageHandler=t=>{if(!this._allowedOrigins.includes(t.origin)&&!this._allowedOrigins.includes(`*`)||t.data?.channel!==this._channelId||t.data?.type!==`mcp`||t.data?.direction!==`client-to-server`)return;this._clientOrigin=t.origin;let n=t.data.payload;if(typeof n==`string`&&n===`mcp-check-ready`){window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},this._clientOrigin);return}try{let t=e.parse(n);this.onmessage?.(t)}catch(e){this.onerror?.(Error(`Invalid message: ${e instanceof Error?e.message:String(e)}`))}},window.addEventListener(`message`,this._messageHandler),this._started=!0,window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-ready`},`*`)}async send(e){if(!this._started)throw Error(`Transport not started`);let t=this._clientOrigin||`*`;this._clientOrigin||console.debug(`[TabServerTransport] Sending to unknown client origin (backwards compatibility mode)`),window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:e},t)}async close(){this._messageHandler&&window.removeEventListener(`message`,this._messageHandler),this._started=!1,window.postMessage({channel:this._channelId,type:`mcp`,direction:`server-to-client`,payload:`mcp-server-stopped`},`*`),this.onclose?.()}},m=class{_port;_extensionId;_portName;_messageHandler;_disconnectHandler;_isReconnecting=!1;_reconnectAttempts=0;_reconnectTimer;_currentReconnectDelay;_isStarted=!1;_isClosed=!1;_autoReconnect;_maxReconnectAttempts;_reconnectDelay;_maxReconnectDelay;_reconnectBackoffMultiplier;onclose;onerror;onmessage;constructor(e={}){this._extensionId=e.extensionId,this._portName=e.portName||`mcp`,this._autoReconnect=e.autoReconnect??!0,this._maxReconnectAttempts=e.maxReconnectAttempts??10,this._reconnectDelay=e.reconnectDelay??1e3,this._maxReconnectDelay=e.maxReconnectDelay??3e4,this._reconnectBackoffMultiplier=e.reconnectBackoffMultiplier??1.5,this._currentReconnectDelay=this._reconnectDelay}async start(){if(this._isStarted&&this._port){console.warn(`UserScriptClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return}this._isStarted=!0,this._isClosed=!1,await this._connect()}async _connect(){return new Promise((t,n)=>{if(!chrome?.runtime?.connect){n(Error(`Chrome runtime API not available. This transport must be used in a Chrome MV3 User Script context.`));return}try{this._extensionId?this._port=chrome.runtime.connect(this._extensionId,{name:this._portName}):this._port=chrome.runtime.connect({name:this._portName}),this._messageHandler=t=>{try{if(t.type===`keep-alive`)return;let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{this._cleanup(),this._isStarted&&!this._isClosed&&this._autoReconnect?this._scheduleReconnect():this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler);let r=chrome.runtime.lastError;if(r){if(this._cleanup(),this._isReconnecting&&this._isStarted&&!this._isClosed&&this._autoReconnect){n(Error(`Connection failed: ${r.message}`));return}n(Error(`Connection failed: ${r.message}`));return}this._reconnectAttempts=0,this._currentReconnectDelay=this._reconnectDelay,this._isReconnecting=!1,t()}catch(e){n(e)}})}async send(e,t){if(!this._isStarted)throw Error(`Transport not started`);if(this._isClosed)throw Error(`Transport is closed`);if(!this._port)throw Error(`Not connected`);try{this._port.postMessage(e)}catch(e){throw Error(`Failed to send message: ${e}`)}}async close(){if(this._isClosed=!0,this._isStarted=!1,this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler)),this._port=void 0}_scheduleReconnect(){if(!(this._isReconnecting||this._isClosed||!this._isStarted)){if(this._isReconnecting=!0,this._reconnectAttempts>=this._maxReconnectAttempts){console.error(`Maximum reconnection attempts reached`),this._isReconnecting=!1,this.onerror?.(Error(`Maximum reconnection attempts reached`)),this.onclose?.();return}this._reconnectAttempts++,console.log(`Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`),this._reconnectTimer=setTimeout(()=>{this._attemptReconnect()},this._currentReconnectDelay),this._currentReconnectDelay=Math.min(this._currentReconnectDelay*this._reconnectBackoffMultiplier,this._maxReconnectDelay)}}async _attemptReconnect(){if(!(this._isClosed||!this._isStarted))try{if(chrome?.runtime?.sendMessage)try{await chrome.runtime.sendMessage({type:`ping`})}catch{}await this._connect(),console.log(`Reconnection successful`),this._isReconnecting=!1}catch(e){console.error(`Reconnection failed:`,e),this._scheduleReconnect()}}},h=class{_port;_started=!1;_messageHandler;_disconnectHandler;_keepAliveTimer;_options;_connectionInfo;onclose;onerror;onmessage;constructor(e,t={}){this._port=e,this._options={keepAlive:t.keepAlive??!0,keepAliveInterval:t.keepAliveInterval??1e3},this._connectionInfo={connectedAt:Date.now(),lastMessageAt:Date.now(),messageCount:0}}async start(){if(this._started)throw Error(`UserScriptServerTransport already started! If using Server class, note that connect() calls start() automatically.`);if(!this._port)throw Error(`Port not available`);this._started=!0,this._messageHandler=t=>{try{if(this._connectionInfo.lastMessageAt=Date.now(),this._connectionInfo.messageCount++,t.type===`ping`){this._port.postMessage({type:`pong`});return}let n=e.parse(t);this.onmessage?.(n)}catch(e){this.onerror?.(Error(`Failed to parse message: ${e}`))}},this._disconnectHandler=()=>{console.log(`[UserScriptServerTransport] Client disconnected after ${Date.now()-this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`),this._cleanup(),this.onclose?.()},this._port.onMessage.addListener(this._messageHandler),this._port.onDisconnect.addListener(this._disconnectHandler),this._options.keepAlive&&this._startKeepAlive(),console.log(`[UserScriptServerTransport] Started with client: ${this._port.sender?.id||`unknown`}`)}async send(e,t){if(!this._started)throw Error(`Transport not started`);if(!this._port)throw Error(`Not connected to client`);try{this._port.postMessage(e)}catch(e){throw chrome.runtime.lastError||!this._port?(this._cleanup(),this.onclose?.(),Error(`Client disconnected`)):Error(`Failed to send message: ${e}`)}}async close(){if(this._started=!1,this._port)try{this._port.disconnect()}catch{}this._cleanup(),this.onclose?.()}_cleanup(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0),this._port&&(this._messageHandler&&this._port.onMessage.removeListener(this._messageHandler),this._disconnectHandler&&this._port.onDisconnect.removeListener(this._disconnectHandler))}_startKeepAlive(){this._keepAliveTimer||=(console.log(`[UserScriptServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`),setInterval(()=>{if(!this._port){this._stopKeepAlive();return}try{this._port.postMessage({type:`keep-alive`,timestamp:Date.now()})}catch(e){console.error(`[UserScriptServerTransport] Keep-alive failed:`,e),this._stopKeepAlive()}},this._options.keepAliveInterval))}_stopKeepAlive(){this._keepAliveTimer!==void 0&&(clearInterval(this._keepAliveTimer),this._keepAliveTimer=void 0)}getConnectionInfo(){return{...this._connectionInfo,uptime:Date.now()-this._connectionInfo.connectedAt,isConnected:!!this._port&&this._started}}};export{o as BACKGROUND_MESSAGE_TYPES,r as ERROR_MESSAGES,c as ExtensionClientTransport,l as ExtensionServerTransport,s as HOST_NAME,u as IframeChildTransport,d as IframeParentTransport,n as NATIVE_HOST,t as NativeMessageType,a as STORAGE_KEYS,i as SUCCESS_MESSAGES,f as TabClientTransport,p as TabServerTransport,m as UserScriptClientTransport,h as UserScriptServerTransport};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["error","error"],"sources":["../src/browser-types.ts","../src/ExtensionClientTransport.ts","../src/ExtensionServerTransport.ts","../src/IframeChildTransport.ts","../src/IframeParentTransport.ts","../src/TabClientTransport.ts","../src/TabServerTransport.ts","../src/UserScriptClientTransport.ts","../src/UserScriptServerTransport.ts"],"sourcesContent":["import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Unique identifier for an event in the event store\n */\nexport type EventId = string;\n\n/**\n * Unique identifier for a stream of events\n */\nexport type StreamId = string;\n\n/**\n * Options for connecting to an MCP server\n */\nexport interface MCPConnectOptions {\n /**\n * The event ID to resume from if reconnecting\n */\n resumeFrom?: EventId;\n}\n\n/**\n * Information about the MCP server\n */\nexport interface MCPServerInfo {\n /**\n * Unique identifier for this server instance\n */\n instanceId: string;\n /**\n * Whether the server maintains session state\n */\n stateful: boolean;\n /**\n * Whether the server has event storage enabled\n */\n hasEventStore: boolean;\n}\n\n/**\n * Event storage interface for accessing stored events\n */\nexport interface MCPEventStore {\n /**\n * Get stored events, optionally filtered by client and/or after a specific event\n * @param clientId - Optional client ID to filter events\n * @param afterEventId - Optional event ID to get events after\n * @param limit - Maximum number of events to return (default: 100)\n */\n getEvents(clientId?: string, afterEventId?: EventId, limit?: number): StoredEvent[];\n\n /**\n * Get the ID of the last event, optionally for a specific client\n * @param clientId - Optional client ID to filter by\n */\n getLastEventId(clientId?: string): EventId | null;\n\n /**\n * Clear stored events, optionally for a specific client\n * @param clientId - Optional client ID to clear events for\n */\n clearEvents(clientId?: string): void;\n}\n\n/**\n * The MCP interface exposed on window for browser environments\n */\nexport interface MCPBrowserInterface {\n /**\n * Connect a client to the MCP server\n * @param clientId - Unique identifier for the client\n * @param options - Optional connection options\n * @returns MessagePort for communication or null if connection fails\n */\n connect(clientId: string, options?: MCPConnectOptions): MessagePort | null;\n\n /**\n * Disconnect a client from the MCP server\n * @param clientId - The client ID to disconnect\n */\n disconnect(clientId: string): void;\n\n /**\n * Terminate a client's session and clean up all associated resources\n * @param clientId - The client ID to terminate\n */\n terminateSession?(clientId: string): void;\n\n /**\n * Check if the MCP server is available and running\n */\n isServerAvailable(): boolean;\n\n /**\n * Get information about the MCP server\n */\n getServerInfo(): MCPServerInfo;\n\n /**\n * Event storage access (only available in stateful mode with event store)\n */\n events?: MCPEventStore;\n}\n\n/**\n * Extended Window interface with MCP support\n */\nexport interface MCPWindow extends Window {\n mcp?: MCPBrowserInterface;\n}\n\n/**\n * Message types for internal MCP communication\n */\nexport interface MCPServerInfoMessage {\n type: 'mcp-server-info';\n serverInstanceId: string;\n serverSessionId?: string;\n hasEventStore: boolean;\n streamId: StreamId;\n}\n\nexport interface MCPEventMessage {\n type: 'mcp-event';\n eventId: EventId;\n message: JSONRPCMessage;\n}\n\nexport interface MCPReplayEventMessage {\n type: 'mcp-replay-event';\n eventId: EventId;\n message: JSONRPCMessage;\n}\n\n/**\n * Stored event with metadata for event sourcing\n */\nexport interface StoredEvent {\n eventId: EventId;\n streamId: StreamId;\n message: JSONRPCMessage;\n timestamp: number;\n clientId: string;\n}\n\nexport enum NativeMessageType {\n START = 'start',\n STARTED = 'started',\n STOP = 'stop',\n STOPPED = 'stopped',\n PING = 'ping',\n PONG = 'pong',\n ERROR = 'error',\n LIST_TOOLS = 'list_tools',\n CALL_TOOL = 'call_tool',\n TOOL_LIST_UPDATED = 'tool_list_updated',\n TOOL_LIST_UPDATED_ACK = 'tool_list_updated_ack',\n PROCESS_DATA = 'process_data',\n\n // Additional message types used in Chrome extension\n SERVER_STARTED = 'server_started',\n SERVER_STOPPED = 'server_stopped',\n ERROR_FROM_NATIVE_HOST = 'error_from_native_host',\n CONNECT_NATIVE = 'connectNative',\n PING_NATIVE = 'ping_native',\n DISCONNECT_NATIVE = 'disconnect_native',\n}\n\n/**\n * Chrome Extension Constants\n * Centralized configuration values and magic constants\n */\n\n// Native Host Configuration\nexport const NATIVE_HOST = {\n NAME: 'com.chromemcp.nativehost',\n DEFAULT_PORT: 12306,\n} as const;\n\n// Error Messages\nexport const ERROR_MESSAGES = {\n NATIVE_CONNECTION_FAILED: 'Failed to connect to native host',\n NATIVE_DISCONNECTED: 'Native connection disconnected',\n SERVER_STATUS_LOAD_FAILED: 'Failed to load server status',\n TOOL_EXECUTION_FAILED: 'Tool execution failed',\n SERVER_STATUS_SAVE_FAILED: 'Failed to save server status',\n} as const;\n\n// Success Messages\nexport const SUCCESS_MESSAGES = {\n TOOL_EXECUTED: 'Tool executed successfully',\n CONNECTION_ESTABLISHED: 'Connection established',\n SERVER_STARTED: 'Server started successfully',\n SERVER_STOPPED: 'Server stopped successfully',\n} as const;\n\n// Storage Keys\nexport const STORAGE_KEYS = {\n SERVER_STATUS: 'serverStatus',\n} as const;\n\n// Background script message types\nexport const BACKGROUND_MESSAGE_TYPES = {\n GET_SERVER_STATUS: 'get_server_status',\n REFRESH_SERVER_STATUS: 'refresh_server_status',\n SERVER_STATUS_CHANGED: 'server_status_changed',\n} as const;\n\nexport const HOST_NAME = NATIVE_HOST.NAME;\n\n/**\n * Server status management interface\n */\nexport interface ServerStatus {\n isRunning: boolean;\n port?: number;\n lastUpdated: number;\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for ExtensionClientTransport\n */\nexport interface ExtensionClientTransportOptions {\n /**\n * The extension ID to connect to (optional for same-extension connections)\n */\n extensionId?: string;\n\n /**\n * Port name for the connection\n * Default: 'mcp'\n */\n portName?: string;\n\n /**\n * Enable automatic reconnection on disconnect\n * Default: true\n */\n autoReconnect?: boolean;\n\n /**\n * Maximum number of reconnection attempts\n * Default: 10\n */\n maxReconnectAttempts?: number;\n\n /**\n * Initial reconnection delay in milliseconds\n * Default: 1000\n */\n reconnectDelay?: number;\n\n /**\n * Maximum reconnection delay in milliseconds\n * Default: 30000\n */\n maxReconnectDelay?: number;\n\n /**\n * Reconnection backoff multiplier\n * Default: 1.5\n */\n reconnectBackoffMultiplier?: number;\n}\n\n/**\n * Client transport for Chrome extensions using Port-based messaging.\n * This transport can be used in content scripts, popup scripts, or sidepanel scripts\n * to connect to a server running in the background service worker.\n *\n * Features automatic reconnection to handle background service worker lifecycle.\n */\nexport class ExtensionClientTransport implements Transport {\n private _port: chrome.runtime.Port | undefined;\n private _extensionId: string | undefined;\n private _portName: string;\n private _messageHandler: ((message: any) => void) | undefined;\n private _disconnectHandler: (() => void) | undefined;\n private _isReconnecting = false;\n private _reconnectAttempts = 0;\n private _reconnectTimer: number | undefined;\n private _currentReconnectDelay: number;\n private _isStarted = false;\n private _isClosed = false;\n\n // Configuration\n private _autoReconnect: boolean;\n private _maxReconnectAttempts: number;\n private _reconnectDelay: number;\n private _maxReconnectDelay: number;\n private _reconnectBackoffMultiplier: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: ExtensionClientTransportOptions = {}) {\n this._extensionId = options.extensionId;\n this._portName = options.portName || 'mcp';\n this._autoReconnect = options.autoReconnect ?? true;\n this._maxReconnectAttempts = options.maxReconnectAttempts ?? 10;\n this._reconnectDelay = options.reconnectDelay ?? 1000;\n this._maxReconnectDelay = options.maxReconnectDelay ?? 30000;\n this._reconnectBackoffMultiplier = options.reconnectBackoffMultiplier ?? 1.5;\n this._currentReconnectDelay = this._reconnectDelay;\n }\n\n /**\n * Starts the transport by connecting to the extension port\n */\n async start(): Promise<void> {\n if (this._isStarted && this._port) {\n console.warn(\n 'ExtensionClientTransport already started! If using Client class, note that connect() calls start() automatically.'\n );\n return;\n }\n\n this._isStarted = true;\n this._isClosed = false;\n\n await this._connect();\n }\n\n /**\n * Connects to the extension port\n */\n private async _connect(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!chrome?.runtime?.connect) {\n reject(\n new Error(\n 'Chrome runtime API not available. This transport must be used in a Chrome extension context.'\n )\n );\n return;\n }\n\n try {\n // Connect to the extension\n if (this._extensionId) {\n this._port = chrome.runtime.connect(this._extensionId, {\n name: this._portName,\n });\n } else {\n this._port = chrome.runtime.connect({ name: this._portName });\n }\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Handle keep-alive messages\n if (message.type === 'keep-alive') {\n // Just acknowledge receipt, no need to propagate\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n this._cleanup();\n\n // Only attempt reconnection if we're started and not manually closed\n if (this._isStarted && !this._isClosed && this._autoReconnect) {\n this._scheduleReconnect();\n } else {\n this.onclose?.();\n }\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Check for immediate connection errors\n const error = chrome.runtime.lastError;\n if (error) {\n this._cleanup();\n\n // If we're reconnecting and hit an error, schedule another attempt\n if (this._isReconnecting && this._isStarted && !this._isClosed && this._autoReconnect) {\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n // Connection successful\n this._reconnectAttempts = 0;\n this._currentReconnectDelay = this._reconnectDelay;\n this._isReconnecting = false;\n\n resolve();\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /**\n * Sends a message to the server\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._isStarted) {\n throw new Error('Transport not started');\n }\n\n if (this._isClosed) {\n throw new Error('Transport is closed');\n }\n\n if (!this._port) {\n throw new Error('Not connected');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._isClosed = true;\n this._isStarted = false;\n\n // Cancel any pending reconnection\n if (this._reconnectTimer !== undefined) {\n clearTimeout(this._reconnectTimer);\n this._reconnectTimer = undefined;\n }\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n this._port = undefined;\n }\n\n /**\n * Schedules a reconnection attempt\n */\n private _scheduleReconnect(): void {\n if (this._isReconnecting || this._isClosed || !this._isStarted) {\n return;\n }\n\n this._isReconnecting = true;\n\n // Check if we've exceeded max attempts\n if (this._reconnectAttempts >= this._maxReconnectAttempts) {\n console.error('Maximum reconnection attempts reached');\n this._isReconnecting = false;\n this.onerror?.(new Error('Maximum reconnection attempts reached'));\n this.onclose?.();\n return;\n }\n\n this._reconnectAttempts++;\n\n console.log(\n `Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`\n );\n\n this._reconnectTimer = setTimeout(() => {\n this._attemptReconnect();\n }, this._currentReconnectDelay) as unknown as number;\n\n // Apply exponential backoff\n this._currentReconnectDelay = Math.min(\n this._currentReconnectDelay * this._reconnectBackoffMultiplier,\n this._maxReconnectDelay\n );\n }\n\n /**\n * Attempts to reconnect to the extension\n */\n private async _attemptReconnect(): Promise<void> {\n if (this._isClosed || !this._isStarted) {\n return;\n }\n\n try {\n // First, try to wake up the service worker by sending a message\n if (chrome?.runtime?.sendMessage) {\n try {\n await chrome.runtime.sendMessage({ type: 'ping' });\n } catch (_error) {\n // Service worker might not be ready yet\n }\n }\n\n // Attempt to connect\n await this._connect();\n\n console.log('Reconnection successful');\n this._isReconnecting = false;\n } catch (error) {\n console.error('Reconnection failed:', error);\n\n // Schedule another attempt\n this._scheduleReconnect();\n }\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for ExtensionServerTransport\n */\nexport type ExtensionServerTransportOptions = {\n /**\n * Enable keep-alive mechanism to prevent service worker shutdown\n * Default: true\n */\n keepAlive?: boolean;\n\n /**\n * Keep-alive interval in milliseconds\n * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)\n */\n keepAliveInterval?: number;\n};\n\n/**\n * Server transport for Chrome extensions using Port-based messaging.\n * This transport handles a single client connection through Chrome's port messaging API.\n * It should be used in the extension's background service worker.\n *\n * Features:\n * - Keep-alive mechanism to prevent service worker shutdown\n * - Graceful connection state management\n */\nexport class ExtensionServerTransport implements Transport {\n private _port: chrome.runtime.Port;\n private _started = false;\n private _messageHandler: ((message: any, port: chrome.runtime.Port) => void) | undefined;\n private _disconnectHandler: ((port: chrome.runtime.Port) => void) | undefined;\n private _keepAliveTimer: number | undefined;\n private _options: ExtensionServerTransportOptions;\n private _connectionInfo: {\n connectedAt: number;\n lastMessageAt: number;\n messageCount: number;\n };\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(port: chrome.runtime.Port, options: ExtensionServerTransportOptions = {}) {\n this._port = port;\n this._options = {\n keepAlive: options.keepAlive ?? true,\n keepAliveInterval: options.keepAliveInterval ?? 1000,\n };\n this._connectionInfo = {\n connectedAt: Date.now(),\n lastMessageAt: Date.now(),\n messageCount: 0,\n };\n }\n\n /**\n * Starts the transport and begins handling messages\n */\n async start(): Promise<void> {\n if (this._started) {\n throw new Error(\n 'ExtensionServerTransport already started! If using Server class, note that connect() calls start() automatically.'\n );\n }\n\n if (!this._port) {\n throw new Error('Port not available');\n }\n\n this._started = true;\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Update connection info\n this._connectionInfo.lastMessageAt = Date.now();\n this._connectionInfo.messageCount++;\n\n // Handle ping messages for keep-alive\n if (message.type === 'ping') {\n this._port.postMessage({ type: 'pong' });\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n console.log(\n `[ExtensionServerTransport] Client disconnected after ${Date.now() - this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`\n );\n this._cleanup();\n this.onclose?.();\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Start keep-alive mechanism if enabled\n if (this._options.keepAlive) {\n this._startKeepAlive();\n }\n\n console.log(\n `[ExtensionServerTransport] Started with client: ${this._port.sender?.id || 'unknown'}`\n );\n }\n\n /**\n * Sends a message to the client\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._port) {\n throw new Error('Not connected to client');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n // Check if the error is due to disconnection\n if (chrome.runtime.lastError || !this._port) {\n this._cleanup();\n this.onclose?.();\n throw new Error('Client disconnected');\n }\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._started = false;\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n // Stop keep-alive timer\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n }\n\n /**\n * Starts the keep-alive mechanism\n */\n private _startKeepAlive(): void {\n if (this._keepAliveTimer) {\n return;\n }\n\n console.log(\n `[ExtensionServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`\n );\n\n this._keepAliveTimer = setInterval(() => {\n if (!this._port) {\n this._stopKeepAlive();\n return;\n }\n\n try {\n // Send a keep-alive ping\n this._port.postMessage({ type: 'keep-alive', timestamp: Date.now() });\n } catch (error) {\n console.error('[ExtensionServerTransport] Keep-alive failed:', error);\n this._stopKeepAlive();\n }\n }, this._options.keepAliveInterval!) as unknown as number;\n }\n\n /**\n * Stops the keep-alive mechanism\n */\n private _stopKeepAlive(): void {\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n }\n\n /**\n * Gets connection information\n */\n getConnectionInfo() {\n return {\n ...this._connectionInfo,\n uptime: Date.now() - this._connectionInfo.connectedAt,\n isConnected: !!this._port && this._started,\n };\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface IframeChildTransportOptions {\n /** Whitelist of parent origins allowed to connect (for security) */\n allowedOrigins: string[];\n /** Optional channel name (default: 'mcp-iframe') */\n channelId?: string;\n /** Retry interval for broadcasting ready signal in milliseconds (default: 250) */\n serverReadyRetryMs?: number;\n}\n\n/**\n * IframeChildTransport - Server transport for iframe\n *\n * Use this transport when an iframe wants to expose an MCP server to its parent page.\n * Supports cross-origin communication.\n *\n * @example\n * ```typescript\n * const transport = new IframeChildTransport({\n * allowedOrigins: ['https://parent-app.com'],\n * });\n *\n * const server = new Server({ name: 'IframeApp', version: '1.0.0' });\n * await server.connect(transport);\n * ```\n */\nexport class IframeChildTransport implements Transport {\n private _started = false;\n private _allowedOrigins: string[];\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _clientOrigin?: string;\n private _serverReadyTimeout: ReturnType<typeof setTimeout> | undefined;\n private readonly _serverReadyRetryMs: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: IframeChildTransportOptions) {\n if (!options.allowedOrigins || options.allowedOrigins.length === 0) {\n throw new Error('At least one allowed origin must be specified');\n }\n\n this._allowedOrigins = options.allowedOrigins;\n this._channelId = options.channelId || 'mcp-iframe';\n this._serverReadyRetryMs = options.serverReadyRetryMs ?? 250;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (!this._allowedOrigins.includes(event.origin) && !this._allowedOrigins.includes('*')) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'client-to-server') {\n return;\n }\n\n this._clientOrigin = event.origin;\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-check-ready') {\n this.broadcastServerReady();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n this.broadcastServerReady();\n }\n\n private broadcastServerReady() {\n if (window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n '*'\n );\n\n this.clearServerReadyRetry();\n } else {\n this.scheduleServerReadyRetry();\n }\n }\n\n private scheduleServerReadyRetry() {\n if (this._serverReadyTimeout) {\n return;\n }\n\n this._serverReadyTimeout = setTimeout(() => {\n this._serverReadyTimeout = undefined;\n if (this._started) {\n this.broadcastServerReady();\n }\n }, this._serverReadyRetryMs);\n }\n\n private clearServerReadyRetry() {\n if (this._serverReadyTimeout) {\n clearTimeout(this._serverReadyTimeout);\n this._serverReadyTimeout = undefined;\n }\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._clientOrigin) {\n console.warn('[IframeChildTransport] No client connected, message not sent');\n return;\n }\n\n if (window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: message,\n },\n this._clientOrigin\n );\n } else {\n console.warn('[IframeChildTransport] Not running in an iframe, message not sent');\n }\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n this._started = false;\n\n if (this._clientOrigin && window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-stopped',\n },\n '*'\n );\n }\n\n this.clearServerReadyRetry();\n\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface IframeParentTransportOptions {\n /** Reference to the iframe element */\n iframe: HTMLIFrameElement;\n /** Expected origin of the iframe (for security) */\n targetOrigin: string;\n /** Optional channel name (default: 'mcp-iframe') */\n channelId?: string;\n /** Retry interval for ready handshake in milliseconds (default: 250) */\n checkReadyRetryMs?: number;\n}\n\n/**\n * IframeParentTransport - Client transport for parent page\n *\n * Use this transport when the parent page wants to connect to an MCP server\n * running inside an iframe. Supports cross-origin communication.\n *\n * @example\n * ```typescript\n * const iframe = document.querySelector('iframe');\n * const transport = new IframeParentTransport({\n * iframe,\n * targetOrigin: 'https://iframe-app.com',\n * });\n *\n * const client = new Client({ name: 'Parent', version: '1.0.0' });\n * await client.connect(transport);\n * ```\n */\nexport class IframeParentTransport implements Transport {\n private _started = false;\n private _iframe: HTMLIFrameElement;\n private _targetOrigin: string;\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _checkReadyTimeout: ReturnType<typeof setTimeout> | undefined;\n private readonly _checkReadyRetryMs: number;\n public readonly serverReadyPromise: Promise<void>;\n private _serverReadyResolve: () => void;\n private _serverReadyReject: (reason: any) => void;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: IframeParentTransportOptions) {\n if (!options.iframe) {\n throw new Error('iframe element is required');\n }\n if (!options.targetOrigin) {\n throw new Error('targetOrigin must be explicitly set for security');\n }\n\n this._iframe = options.iframe;\n this._targetOrigin = options.targetOrigin;\n this._channelId = options.channelId || 'mcp-iframe';\n this._checkReadyRetryMs = options.checkReadyRetryMs ?? 250;\n\n const { promise, resolve, reject } = Promise.withResolvers<void>();\n this.serverReadyPromise = promise;\n this._serverReadyResolve = resolve;\n this._serverReadyReject = reject;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (event.origin !== this._targetOrigin) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'server-to-client') {\n return;\n }\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-server-ready') {\n this._serverReadyResolve();\n this.clearCheckReadyRetry();\n return;\n }\n\n if (typeof payload === 'string' && payload === 'mcp-server-stopped') {\n console.log('[IframeParentTransport] Received mcp-server-stopped event, closing transport');\n this.close();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this._serverReadyResolve();\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n this.sendCheckReady();\n }\n\n private sendCheckReady() {\n const contentWindow = this._iframe.contentWindow;\n\n if (!contentWindow) {\n console.warn('[IframeParentTransport] iframe.contentWindow not available, will retry');\n this.scheduleCheckReadyRetry();\n return;\n }\n\n contentWindow.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: 'mcp-check-ready',\n },\n this._targetOrigin\n );\n }\n\n private scheduleCheckReadyRetry() {\n if (this._checkReadyTimeout) {\n return;\n }\n\n this._checkReadyTimeout = setTimeout(() => {\n this._checkReadyTimeout = undefined;\n if (this._started) {\n this.sendCheckReady();\n }\n }, this._checkReadyRetryMs);\n }\n\n private clearCheckReadyRetry() {\n if (this._checkReadyTimeout) {\n clearTimeout(this._checkReadyTimeout);\n this._checkReadyTimeout = undefined;\n }\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n await this.serverReadyPromise;\n\n const contentWindow = this._iframe.contentWindow;\n\n if (!contentWindow) {\n throw new Error('iframe.contentWindow not available');\n }\n\n contentWindow.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: message,\n },\n this._targetOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n\n this._serverReadyReject(new Error('Transport closed before server ready'));\n\n this.clearCheckReadyRetry();\n\n this._started = false;\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface TabClientTransportOptions {\n /** Origin expected from the server window (for security) */\n targetOrigin: string;\n /** Optional channel name (default: 'mcp-default') */\n channelId?: string;\n}\n\nexport class TabClientTransport implements Transport {\n private _started = false;\n private _targetOrigin: string;\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n public readonly serverReadyPromise: Promise<void>;\n private _serverReadyResolve: () => void;\n private _serverReadyReject: (reason: any) => void;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: TabClientTransportOptions) {\n if (!options.targetOrigin) {\n throw new Error('targetOrigin must be explicitly set for security');\n }\n this._targetOrigin = options.targetOrigin;\n this._channelId = options.channelId || 'mcp-default';\n\n // Create the server ready promise in constructor so it's available immediately\n const { promise, resolve, reject } = Promise.withResolvers<void>();\n this.serverReadyPromise = promise;\n this._serverReadyResolve = () => {\n resolve();\n };\n this._serverReadyReject = (reason) => {\n reject(reason);\n };\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (event.origin !== this._targetOrigin) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'server-to-client') {\n return;\n }\n\n const payload = event.data.payload;\n\n // Handle server ready signal\n if (typeof payload === 'string' && payload === 'mcp-server-ready') {\n this._serverReadyResolve();\n return;\n }\n\n // Handle server stopped signal\n if (typeof payload === 'string' && payload === 'mcp-server-stopped') {\n console.log('[TabClientTransport] Received mcp-server-stopped event, closing transport');\n this.close();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this._serverReadyResolve();\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n // Send check-ready to prompt server if already started\n this.sendCheckReady();\n }\n\n private sendCheckReady() {\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: 'mcp-check-ready',\n },\n this._targetOrigin\n );\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n // Await server ready before sending any JSON-RPC message\n await this.serverReadyPromise;\n\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: message,\n },\n this._targetOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n\n // Reject the server ready promise if it hasn't been resolved yet\n this._serverReadyReject(new Error('Transport closed before server ready'));\n\n this._started = false;\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface TabServerTransportOptions {\n /** Whitelist of origins allowed to connect (for security) */\n allowedOrigins: string[];\n /** Optional channel name (default: 'mcp-default') */\n channelId?: string;\n}\n\nexport class TabServerTransport implements Transport {\n private _started = false;\n private _allowedOrigins: string[];\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _clientOrigin?: string;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: TabServerTransportOptions) {\n if (!options.allowedOrigins || options.allowedOrigins.length === 0) {\n throw new Error('At least one allowed origin must be specified');\n }\n\n this._allowedOrigins = options.allowedOrigins;\n this._channelId = options.channelId || 'mcp-default';\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (!this._allowedOrigins.includes(event.origin) && !this._allowedOrigins.includes('*')) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'client-to-server') {\n return;\n }\n\n this._clientOrigin = event.origin;\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-check-ready') {\n // Respond with server ready\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n this._clientOrigin\n );\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n // Broadcast server ready to all allowed origins\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n '*'\n );\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._clientOrigin) {\n console.warn('[TabServerTransport] No client connected, message not sent');\n return;\n }\n\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: message,\n },\n this._clientOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n this._started = false;\n\n // Post message to notify content scripts that the MCP server has stopped\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-stopped',\n },\n '*'\n );\n\n this.onclose?.();\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for UserScriptClientTransport\n */\nexport interface UserScriptClientTransportOptions {\n /**\n * The extension ID to connect to (optional for same-extension connections)\n */\n extensionId?: string;\n\n /**\n * Port name for the connection\n * Default: 'mcp'\n */\n portName?: string;\n\n /**\n * Enable automatic reconnection on disconnect\n * Default: true\n */\n autoReconnect?: boolean;\n\n /**\n * Maximum number of reconnection attempts\n * Default: 10\n */\n maxReconnectAttempts?: number;\n\n /**\n * Initial reconnection delay in milliseconds\n * Default: 1000\n */\n reconnectDelay?: number;\n\n /**\n * Maximum reconnection delay in milliseconds\n * Default: 30000\n */\n maxReconnectDelay?: number;\n\n /**\n * Reconnection backoff multiplier\n * Default: 1.5\n */\n reconnectBackoffMultiplier?: number;\n}\n\n/**\n * Client transport for Chrome MV3 User Scripts using Port-based messaging.\n * This transport can be used inside a User Script context to connect to the\n * extension's background service worker. On the extension side, connections\n * are received via chrome.runtime.onUserScriptConnect.\n *\n * Features automatic reconnection to handle background service worker lifecycle.\n */\nexport class UserScriptClientTransport implements Transport {\n private _port: chrome.runtime.Port | undefined;\n private _extensionId: string | undefined;\n private _portName: string;\n private _messageHandler: ((message: any) => void) | undefined;\n private _disconnectHandler: (() => void) | undefined;\n private _isReconnecting = false;\n private _reconnectAttempts = 0;\n private _reconnectTimer: number | undefined;\n private _currentReconnectDelay: number;\n private _isStarted = false;\n private _isClosed = false;\n\n // Configuration\n private _autoReconnect: boolean;\n private _maxReconnectAttempts: number;\n private _reconnectDelay: number;\n private _maxReconnectDelay: number;\n private _reconnectBackoffMultiplier: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: UserScriptClientTransportOptions = {}) {\n this._extensionId = options.extensionId;\n this._portName = options.portName || 'mcp';\n this._autoReconnect = options.autoReconnect ?? true;\n this._maxReconnectAttempts = options.maxReconnectAttempts ?? 10;\n this._reconnectDelay = options.reconnectDelay ?? 1000;\n this._maxReconnectDelay = options.maxReconnectDelay ?? 30000;\n this._reconnectBackoffMultiplier = options.reconnectBackoffMultiplier ?? 1.5;\n this._currentReconnectDelay = this._reconnectDelay;\n }\n\n /**\n * Starts the transport by connecting to the extension port\n */\n async start(): Promise<void> {\n if (this._isStarted && this._port) {\n console.warn(\n 'UserScriptClientTransport already started! If using Client class, note that connect() calls start() automatically.'\n );\n return;\n }\n\n this._isStarted = true;\n this._isClosed = false;\n\n await this._connect();\n }\n\n /**\n * Connects to the extension port\n */\n private async _connect(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!chrome?.runtime?.connect) {\n reject(\n new Error(\n 'Chrome runtime API not available. This transport must be used in a Chrome MV3 User Script context.'\n )\n );\n return;\n }\n\n try {\n // Connect to the extension. From a user script, this triggers onUserScriptConnect on the extension side.\n if (this._extensionId) {\n this._port = chrome.runtime.connect(this._extensionId, {\n name: this._portName,\n });\n } else {\n this._port = chrome.runtime.connect({ name: this._portName });\n }\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Handle keep-alive messages\n if ((message as any).type === 'keep-alive') {\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n this._cleanup();\n\n // Only attempt reconnection if we're started and not manually closed\n if (this._isStarted && !this._isClosed && this._autoReconnect) {\n this._scheduleReconnect();\n } else {\n this.onclose?.();\n }\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Check for immediate connection errors\n const error = chrome.runtime.lastError;\n if (error) {\n this._cleanup();\n\n // If we're reconnecting and hit an error, schedule another attempt\n if (this._isReconnecting && this._isStarted && !this._isClosed && this._autoReconnect) {\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n // Connection successful\n this._reconnectAttempts = 0;\n this._currentReconnectDelay = this._reconnectDelay;\n this._isReconnecting = false;\n\n resolve();\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /**\n * Sends a message to the server\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._isStarted) {\n throw new Error('Transport not started');\n }\n\n if (this._isClosed) {\n throw new Error('Transport is closed');\n }\n\n if (!this._port) {\n throw new Error('Not connected');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._isClosed = true;\n this._isStarted = false;\n\n // Cancel any pending reconnection\n if (this._reconnectTimer !== undefined) {\n clearTimeout(this._reconnectTimer);\n this._reconnectTimer = undefined;\n }\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n this._port = undefined;\n }\n\n /**\n * Schedules a reconnection attempt\n */\n private _scheduleReconnect(): void {\n if (this._isReconnecting || this._isClosed || !this._isStarted) {\n return;\n }\n\n this._isReconnecting = true;\n\n // Check if we've exceeded max attempts\n if (this._reconnectAttempts >= this._maxReconnectAttempts) {\n console.error('Maximum reconnection attempts reached');\n this._isReconnecting = false;\n this.onerror?.(new Error('Maximum reconnection attempts reached'));\n this.onclose?.();\n return;\n }\n\n this._reconnectAttempts++;\n\n console.log(\n `Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`\n );\n\n this._reconnectTimer = setTimeout(() => {\n this._attemptReconnect();\n }, this._currentReconnectDelay) as unknown as number;\n\n // Apply exponential backoff\n this._currentReconnectDelay = Math.min(\n this._currentReconnectDelay * this._reconnectBackoffMultiplier,\n this._maxReconnectDelay\n );\n }\n\n /**\n * Attempts to reconnect to the extension\n */\n private async _attemptReconnect(): Promise<void> {\n if (this._isClosed || !this._isStarted) {\n return;\n }\n\n try {\n // First, try to wake up the service worker by sending a message\n if (chrome?.runtime?.sendMessage) {\n try {\n await chrome.runtime.sendMessage({ type: 'ping' });\n } catch (_error) {\n // Service worker might not be ready yet\n }\n }\n\n // Attempt to connect\n await this._connect();\n\n console.log('Reconnection successful');\n this._isReconnecting = false;\n } catch (error) {\n console.error('Reconnection failed:', error);\n\n // Schedule another attempt\n this._scheduleReconnect();\n }\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for UserScriptServerTransport\n */\nexport type UserScriptServerTransportOptions = {\n /**\n * Enable keep-alive mechanism to prevent service worker shutdown\n * Default: true\n */\n keepAlive?: boolean;\n\n /**\n * Keep-alive interval in milliseconds\n * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)\n */\n keepAliveInterval?: number;\n};\n\n/**\n * Server transport for Chrome MV3 User Scripts using Port-based messaging.\n * This transport handles a single client connection through Chrome's port\n * messaging API. It should be used in the extension's background service\n * worker. Connections are initiated from User Scripts via chrome.runtime.connect\n * and received here via chrome.runtime.onUserScriptConnect.\n *\n * Features:\n * - Keep-alive mechanism to prevent service worker shutdown\n * - Graceful connection state management\n */\nexport class UserScriptServerTransport implements Transport {\n private _port: chrome.runtime.Port;\n private _started = false;\n private _messageHandler: ((message: unknown, port: chrome.runtime.Port) => void) | undefined;\n private _disconnectHandler: ((port: chrome.runtime.Port) => void) | undefined;\n private _keepAliveTimer: number | undefined;\n private _options: UserScriptServerTransportOptions;\n private _connectionInfo: {\n connectedAt: number;\n lastMessageAt: number;\n messageCount: number;\n };\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(port: chrome.runtime.Port, options: UserScriptServerTransportOptions = {}) {\n this._port = port;\n this._options = {\n keepAlive: options.keepAlive ?? true,\n keepAliveInterval: options.keepAliveInterval ?? 1000,\n };\n this._connectionInfo = {\n connectedAt: Date.now(),\n lastMessageAt: Date.now(),\n messageCount: 0,\n };\n }\n\n /**\n * Starts the transport and begins handling messages\n */\n async start(): Promise<void> {\n if (this._started) {\n throw new Error(\n 'UserScriptServerTransport already started! If using Server class, note that connect() calls start() automatically.'\n );\n }\n\n if (!this._port) {\n throw new Error('Port not available');\n }\n\n this._started = true;\n\n // Set up message handler\n this._messageHandler = (message: unknown) => {\n try {\n // Update connection info\n this._connectionInfo.lastMessageAt = Date.now();\n this._connectionInfo.messageCount++;\n\n // Handle ping messages for keep-alive\n const msg = message as { type?: string };\n if (msg.type === 'ping') {\n this._port.postMessage({ type: 'pong' });\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n console.log(\n `[UserScriptServerTransport] Client disconnected after ${Date.now() - this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`\n );\n this._cleanup();\n this.onclose?.();\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Start keep-alive mechanism if enabled\n if (this._options.keepAlive) {\n this._startKeepAlive();\n }\n\n console.log(\n `[UserScriptServerTransport] Started with client: ${this._port.sender?.id || 'unknown'}`\n );\n }\n\n /**\n * Sends a message to the client\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._port) {\n throw new Error('Not connected to client');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n // Check if the error is due to disconnection\n if (chrome.runtime.lastError || !this._port) {\n this._cleanup();\n this.onclose?.();\n throw new Error('Client disconnected');\n }\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._started = false;\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n // Stop keep-alive timer\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n }\n\n /**\n * Starts the keep-alive mechanism\n */\n private _startKeepAlive(): void {\n if (this._keepAliveTimer) {\n return;\n }\n\n console.log(\n `[UserScriptServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`\n );\n\n this._keepAliveTimer = setInterval(() => {\n if (!this._port) {\n this._stopKeepAlive();\n return;\n }\n\n try {\n // Send a keep-alive ping\n this._port.postMessage({ type: 'keep-alive', timestamp: Date.now() });\n } catch (error) {\n console.error('[UserScriptServerTransport] Keep-alive failed:', error);\n this._stopKeepAlive();\n }\n }, this._options.keepAliveInterval!) as unknown as number;\n }\n\n /**\n * Stops the keep-alive mechanism\n */\n private _stopKeepAlive(): void {\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n }\n\n /**\n * Gets connection information\n */\n getConnectionInfo() {\n return {\n ...this._connectionInfo,\n uptime: Date.now() - this._connectionInfo.connectedAt,\n isConnected: !!this._port && this._started,\n };\n }\n}\n"],"mappings":"0EAkJA,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,MAAA,QACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,WAAA,aACA,EAAA,UAAA,YACA,EAAA,kBAAA,oBACA,EAAA,sBAAA,wBACA,EAAA,aAAA,eAGA,EAAA,eAAA,iBACA,EAAA,eAAA,iBACA,EAAA,uBAAA,yBACA,EAAA,eAAA,gBACA,EAAA,YAAA,cACA,EAAA,kBAAA,2BASF,MAAa,EAAc,CACzB,KAAM,2BACN,aAAc,MACf,CAGY,EAAiB,CAC5B,yBAA0B,mCAC1B,oBAAqB,iCACrB,0BAA2B,+BAC3B,sBAAuB,wBACvB,0BAA2B,+BAC5B,CAGY,EA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,KAAK,MAAM,UAAU,eAAe,KAAK,gBAAgB,CAEvD,KAAK,oBACP,KAAK,MAAM,aAAa,eAAe,KAAK,mBAAmB,EAQrE,iBAAgC,CAC1B,AAQJ,KAAK,mBAJL,QAAQ,IACN,wDAAwD,KAAK,SAAS,kBAAkB,aACzF,CAEsB,gBAAkB,CACvC,GAAI,CAAC,KAAK,MAAO,CACf,KAAK,gBAAgB,CACrB,OAGF,GAAI,CAEF,KAAK,MAAM,YAAY,CAAE,KAAM,aAAc,UAAW,KAAK,KAAK,CAAE,CAAC,OAC9D,EAAO,CACd,QAAQ,MAAM,iDAAkD,EAAM,CACtE,KAAK,gBAAgB,GAEtB,KAAK,SAAS,kBAAmB,EAMtC,gBAA+B,CACzB,KAAK,kBAAoB,IAAA,KAC3B,cAAc,KAAK,gBAAgB,CACnC,KAAK,gBAAkB,IAAA,IAO3B,mBAAoB,CAClB,MAAO,CACL,GAAG,KAAK,gBACR,OAAQ,KAAK,KAAK,CAAG,KAAK,gBAAgB,YAC1C,YAAa,CAAC,CAAC,KAAK,OAAS,KAAK,SACnC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["error","error"],"sources":["../src/browser-types.ts","../src/ExtensionClientTransport.ts","../src/ExtensionServerTransport.ts","../src/IframeChildTransport.ts","../src/IframeParentTransport.ts","../src/TabClientTransport.ts","../src/TabServerTransport.ts","../src/UserScriptClientTransport.ts","../src/UserScriptServerTransport.ts"],"sourcesContent":["import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Unique identifier for an event in the event store\n */\nexport type EventId = string;\n\n/**\n * Unique identifier for a stream of events\n */\nexport type StreamId = string;\n\n/**\n * Options for connecting to an MCP server\n */\nexport interface MCPConnectOptions {\n /**\n * The event ID to resume from if reconnecting\n */\n resumeFrom?: EventId;\n}\n\n/**\n * Information about the MCP server\n */\nexport interface MCPServerInfo {\n /**\n * Unique identifier for this server instance\n */\n instanceId: string;\n /**\n * Whether the server maintains session state\n */\n stateful: boolean;\n /**\n * Whether the server has event storage enabled\n */\n hasEventStore: boolean;\n}\n\n/**\n * Event storage interface for accessing stored events\n */\nexport interface MCPEventStore {\n /**\n * Get stored events, optionally filtered by client and/or after a specific event\n * @param clientId - Optional client ID to filter events\n * @param afterEventId - Optional event ID to get events after\n * @param limit - Maximum number of events to return (default: 100)\n */\n getEvents(clientId?: string, afterEventId?: EventId, limit?: number): StoredEvent[];\n\n /**\n * Get the ID of the last event, optionally for a specific client\n * @param clientId - Optional client ID to filter by\n */\n getLastEventId(clientId?: string): EventId | null;\n\n /**\n * Clear stored events, optionally for a specific client\n * @param clientId - Optional client ID to clear events for\n */\n clearEvents(clientId?: string): void;\n}\n\n/**\n * The MCP interface exposed on window for browser environments\n */\nexport interface MCPBrowserInterface {\n /**\n * Connect a client to the MCP server\n * @param clientId - Unique identifier for the client\n * @param options - Optional connection options\n * @returns MessagePort for communication or null if connection fails\n */\n connect(clientId: string, options?: MCPConnectOptions): MessagePort | null;\n\n /**\n * Disconnect a client from the MCP server\n * @param clientId - The client ID to disconnect\n */\n disconnect(clientId: string): void;\n\n /**\n * Terminate a client's session and clean up all associated resources\n * @param clientId - The client ID to terminate\n */\n terminateSession?(clientId: string): void;\n\n /**\n * Check if the MCP server is available and running\n */\n isServerAvailable(): boolean;\n\n /**\n * Get information about the MCP server\n */\n getServerInfo(): MCPServerInfo;\n\n /**\n * Event storage access (only available in stateful mode with event store)\n */\n events?: MCPEventStore;\n}\n\n/**\n * Extended Window interface with MCP support\n */\nexport interface MCPWindow extends Window {\n mcp?: MCPBrowserInterface;\n}\n\n/**\n * Message types for internal MCP communication\n */\nexport interface MCPServerInfoMessage {\n type: 'mcp-server-info';\n serverInstanceId: string;\n serverSessionId?: string;\n hasEventStore: boolean;\n streamId: StreamId;\n}\n\nexport interface MCPEventMessage {\n type: 'mcp-event';\n eventId: EventId;\n message: JSONRPCMessage;\n}\n\nexport interface MCPReplayEventMessage {\n type: 'mcp-replay-event';\n eventId: EventId;\n message: JSONRPCMessage;\n}\n\n/**\n * Stored event with metadata for event sourcing\n */\nexport interface StoredEvent {\n eventId: EventId;\n streamId: StreamId;\n message: JSONRPCMessage;\n timestamp: number;\n clientId: string;\n}\n\nexport enum NativeMessageType {\n START = 'start',\n STARTED = 'started',\n STOP = 'stop',\n STOPPED = 'stopped',\n PING = 'ping',\n PONG = 'pong',\n ERROR = 'error',\n LIST_TOOLS = 'list_tools',\n CALL_TOOL = 'call_tool',\n TOOL_LIST_UPDATED = 'tool_list_updated',\n TOOL_LIST_UPDATED_ACK = 'tool_list_updated_ack',\n PROCESS_DATA = 'process_data',\n\n // Additional message types used in Chrome extension\n SERVER_STARTED = 'server_started',\n SERVER_STOPPED = 'server_stopped',\n ERROR_FROM_NATIVE_HOST = 'error_from_native_host',\n CONNECT_NATIVE = 'connectNative',\n PING_NATIVE = 'ping_native',\n DISCONNECT_NATIVE = 'disconnect_native',\n}\n\n/**\n * Chrome Extension Constants\n * Centralized configuration values and magic constants\n */\n\n// Native Host Configuration\nexport const NATIVE_HOST = {\n NAME: 'com.chromemcp.nativehost',\n DEFAULT_PORT: 12306,\n} as const;\n\n// Error Messages\nexport const ERROR_MESSAGES = {\n NATIVE_CONNECTION_FAILED: 'Failed to connect to native host',\n NATIVE_DISCONNECTED: 'Native connection disconnected',\n SERVER_STATUS_LOAD_FAILED: 'Failed to load server status',\n TOOL_EXECUTION_FAILED: 'Tool execution failed',\n SERVER_STATUS_SAVE_FAILED: 'Failed to save server status',\n} as const;\n\n// Success Messages\nexport const SUCCESS_MESSAGES = {\n TOOL_EXECUTED: 'Tool executed successfully',\n CONNECTION_ESTABLISHED: 'Connection established',\n SERVER_STARTED: 'Server started successfully',\n SERVER_STOPPED: 'Server stopped successfully',\n} as const;\n\n// Storage Keys\nexport const STORAGE_KEYS = {\n SERVER_STATUS: 'serverStatus',\n} as const;\n\n// Background script message types\nexport const BACKGROUND_MESSAGE_TYPES = {\n GET_SERVER_STATUS: 'get_server_status',\n REFRESH_SERVER_STATUS: 'refresh_server_status',\n SERVER_STATUS_CHANGED: 'server_status_changed',\n} as const;\n\nexport const HOST_NAME = NATIVE_HOST.NAME;\n\n/**\n * Server status management interface\n */\nexport interface ServerStatus {\n isRunning: boolean;\n port?: number;\n lastUpdated: number;\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for ExtensionClientTransport\n */\nexport interface ExtensionClientTransportOptions {\n /**\n * The extension ID to connect to (optional for same-extension connections)\n */\n extensionId?: string;\n\n /**\n * Port name for the connection\n * Default: 'mcp'\n */\n portName?: string;\n\n /**\n * Enable automatic reconnection on disconnect\n * Default: true\n */\n autoReconnect?: boolean;\n\n /**\n * Maximum number of reconnection attempts\n * Default: 10\n */\n maxReconnectAttempts?: number;\n\n /**\n * Initial reconnection delay in milliseconds\n * Default: 1000\n */\n reconnectDelay?: number;\n\n /**\n * Maximum reconnection delay in milliseconds\n * Default: 30000\n */\n maxReconnectDelay?: number;\n\n /**\n * Reconnection backoff multiplier\n * Default: 1.5\n */\n reconnectBackoffMultiplier?: number;\n}\n\n/**\n * Client transport for Chrome extensions using Port-based messaging.\n * This transport can be used in content scripts, popup scripts, or sidepanel scripts\n * to connect to a server running in the background service worker.\n *\n * Features automatic reconnection to handle background service worker lifecycle.\n */\nexport class ExtensionClientTransport implements Transport {\n private _port: chrome.runtime.Port | undefined;\n private _extensionId: string | undefined;\n private _portName: string;\n private _messageHandler: ((message: any) => void) | undefined;\n private _disconnectHandler: (() => void) | undefined;\n private _isReconnecting = false;\n private _reconnectAttempts = 0;\n private _reconnectTimer: number | undefined;\n private _currentReconnectDelay: number;\n private _isStarted = false;\n private _isClosed = false;\n\n // Configuration\n private _autoReconnect: boolean;\n private _maxReconnectAttempts: number;\n private _reconnectDelay: number;\n private _maxReconnectDelay: number;\n private _reconnectBackoffMultiplier: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: ExtensionClientTransportOptions = {}) {\n this._extensionId = options.extensionId;\n this._portName = options.portName || 'mcp';\n this._autoReconnect = options.autoReconnect ?? true;\n this._maxReconnectAttempts = options.maxReconnectAttempts ?? 10;\n this._reconnectDelay = options.reconnectDelay ?? 1000;\n this._maxReconnectDelay = options.maxReconnectDelay ?? 30000;\n this._reconnectBackoffMultiplier = options.reconnectBackoffMultiplier ?? 1.5;\n this._currentReconnectDelay = this._reconnectDelay;\n }\n\n /**\n * Starts the transport by connecting to the extension port\n */\n async start(): Promise<void> {\n if (this._isStarted && this._port) {\n console.warn(\n 'ExtensionClientTransport already started! If using Client class, note that connect() calls start() automatically.'\n );\n return;\n }\n\n this._isStarted = true;\n this._isClosed = false;\n\n await this._connect();\n }\n\n /**\n * Connects to the extension port\n */\n private async _connect(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!chrome?.runtime?.connect) {\n reject(\n new Error(\n 'Chrome runtime API not available. This transport must be used in a Chrome extension context.'\n )\n );\n return;\n }\n\n try {\n // Connect to the extension\n if (this._extensionId) {\n this._port = chrome.runtime.connect(this._extensionId, {\n name: this._portName,\n });\n } else {\n this._port = chrome.runtime.connect({ name: this._portName });\n }\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Handle keep-alive messages\n if (message.type === 'keep-alive') {\n // Just acknowledge receipt, no need to propagate\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n this._cleanup();\n\n // Only attempt reconnection if we're started and not manually closed\n if (this._isStarted && !this._isClosed && this._autoReconnect) {\n this._scheduleReconnect();\n } else {\n this.onclose?.();\n }\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Check for immediate connection errors\n const error = chrome.runtime.lastError;\n if (error) {\n this._cleanup();\n\n // If we're reconnecting and hit an error, schedule another attempt\n if (this._isReconnecting && this._isStarted && !this._isClosed && this._autoReconnect) {\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n // Connection successful\n this._reconnectAttempts = 0;\n this._currentReconnectDelay = this._reconnectDelay;\n this._isReconnecting = false;\n\n resolve();\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /**\n * Sends a message to the server\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._isStarted) {\n throw new Error('Transport not started');\n }\n\n if (this._isClosed) {\n throw new Error('Transport is closed');\n }\n\n if (!this._port) {\n throw new Error('Not connected');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._isClosed = true;\n this._isStarted = false;\n\n // Cancel any pending reconnection\n if (this._reconnectTimer !== undefined) {\n clearTimeout(this._reconnectTimer);\n this._reconnectTimer = undefined;\n }\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n this._port = undefined;\n }\n\n /**\n * Schedules a reconnection attempt\n */\n private _scheduleReconnect(): void {\n if (this._isReconnecting || this._isClosed || !this._isStarted) {\n return;\n }\n\n this._isReconnecting = true;\n\n // Check if we've exceeded max attempts\n if (this._reconnectAttempts >= this._maxReconnectAttempts) {\n console.error('Maximum reconnection attempts reached');\n this._isReconnecting = false;\n this.onerror?.(new Error('Maximum reconnection attempts reached'));\n this.onclose?.();\n return;\n }\n\n this._reconnectAttempts++;\n\n console.log(\n `Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`\n );\n\n this._reconnectTimer = setTimeout(() => {\n this._attemptReconnect();\n }, this._currentReconnectDelay) as unknown as number;\n\n // Apply exponential backoff\n this._currentReconnectDelay = Math.min(\n this._currentReconnectDelay * this._reconnectBackoffMultiplier,\n this._maxReconnectDelay\n );\n }\n\n /**\n * Attempts to reconnect to the extension\n */\n private async _attemptReconnect(): Promise<void> {\n if (this._isClosed || !this._isStarted) {\n return;\n }\n\n try {\n // First, try to wake up the service worker by sending a message\n if (chrome?.runtime?.sendMessage) {\n try {\n await chrome.runtime.sendMessage({ type: 'ping' });\n } catch (_error) {\n // Service worker might not be ready yet\n }\n }\n\n // Attempt to connect\n await this._connect();\n\n console.log('Reconnection successful');\n this._isReconnecting = false;\n } catch (error) {\n console.error('Reconnection failed:', error);\n\n // Schedule another attempt\n this._scheduleReconnect();\n }\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for ExtensionServerTransport\n */\nexport type ExtensionServerTransportOptions = {\n /**\n * Enable keep-alive mechanism to prevent service worker shutdown\n * Default: true\n */\n keepAlive?: boolean;\n\n /**\n * Keep-alive interval in milliseconds\n * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)\n */\n keepAliveInterval?: number;\n};\n\n/**\n * Server transport for Chrome extensions using Port-based messaging.\n * This transport handles a single client connection through Chrome's port messaging API.\n * It should be used in the extension's background service worker.\n *\n * Features:\n * - Keep-alive mechanism to prevent service worker shutdown\n * - Graceful connection state management\n */\nexport class ExtensionServerTransport implements Transport {\n private _port: chrome.runtime.Port;\n private _started = false;\n private _messageHandler: ((message: any, port: chrome.runtime.Port) => void) | undefined;\n private _disconnectHandler: ((port: chrome.runtime.Port) => void) | undefined;\n private _keepAliveTimer: number | undefined;\n private _options: ExtensionServerTransportOptions;\n private _connectionInfo: {\n connectedAt: number;\n lastMessageAt: number;\n messageCount: number;\n };\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(port: chrome.runtime.Port, options: ExtensionServerTransportOptions = {}) {\n this._port = port;\n this._options = {\n keepAlive: options.keepAlive ?? true,\n keepAliveInterval: options.keepAliveInterval ?? 1000,\n };\n this._connectionInfo = {\n connectedAt: Date.now(),\n lastMessageAt: Date.now(),\n messageCount: 0,\n };\n }\n\n /**\n * Starts the transport and begins handling messages\n */\n async start(): Promise<void> {\n if (this._started) {\n throw new Error(\n 'ExtensionServerTransport already started! If using Server class, note that connect() calls start() automatically.'\n );\n }\n\n if (!this._port) {\n throw new Error('Port not available');\n }\n\n this._started = true;\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Update connection info\n this._connectionInfo.lastMessageAt = Date.now();\n this._connectionInfo.messageCount++;\n\n // Handle ping messages for keep-alive\n if (message.type === 'ping') {\n this._port.postMessage({ type: 'pong' });\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n console.log(\n `[ExtensionServerTransport] Client disconnected after ${Date.now() - this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`\n );\n this._cleanup();\n this.onclose?.();\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Start keep-alive mechanism if enabled\n if (this._options.keepAlive) {\n this._startKeepAlive();\n }\n\n console.log(\n `[ExtensionServerTransport] Started with client: ${this._port.sender?.id || 'unknown'}`\n );\n }\n\n /**\n * Sends a message to the client\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._port) {\n throw new Error('Not connected to client');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n // Check if the error is due to disconnection\n if (chrome.runtime.lastError || !this._port) {\n this._cleanup();\n this.onclose?.();\n throw new Error('Client disconnected');\n }\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._started = false;\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n // Stop keep-alive timer\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n }\n\n /**\n * Starts the keep-alive mechanism\n */\n private _startKeepAlive(): void {\n if (this._keepAliveTimer) {\n return;\n }\n\n console.log(\n `[ExtensionServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`\n );\n\n this._keepAliveTimer = setInterval(() => {\n if (!this._port) {\n this._stopKeepAlive();\n return;\n }\n\n try {\n // Send a keep-alive ping\n this._port.postMessage({ type: 'keep-alive', timestamp: Date.now() });\n } catch (error) {\n console.error('[ExtensionServerTransport] Keep-alive failed:', error);\n this._stopKeepAlive();\n }\n }, this._options.keepAliveInterval!) as unknown as number;\n }\n\n /**\n * Stops the keep-alive mechanism\n */\n private _stopKeepAlive(): void {\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n }\n\n /**\n * Gets connection information\n */\n getConnectionInfo() {\n return {\n ...this._connectionInfo,\n uptime: Date.now() - this._connectionInfo.connectedAt,\n isConnected: !!this._port && this._started,\n };\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface IframeChildTransportOptions {\n /** Whitelist of parent origins allowed to connect (for security) */\n allowedOrigins: string[];\n /** Optional channel name (default: 'mcp-iframe') */\n channelId?: string;\n /** Retry interval for broadcasting ready signal in milliseconds (default: 250) */\n serverReadyRetryMs?: number;\n}\n\n/**\n * IframeChildTransport - Server transport for iframe\n *\n * Use this transport when an iframe wants to expose an MCP server to its parent page.\n * Supports cross-origin communication.\n *\n * @example\n * ```typescript\n * const transport = new IframeChildTransport({\n * allowedOrigins: ['https://parent-app.com'],\n * });\n *\n * const server = new Server({ name: 'IframeApp', version: '1.0.0' });\n * await server.connect(transport);\n * ```\n */\nexport class IframeChildTransport implements Transport {\n private _started = false;\n private _allowedOrigins: string[];\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _clientOrigin?: string;\n private _serverReadyTimeout: ReturnType<typeof setTimeout> | undefined;\n private readonly _serverReadyRetryMs: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: IframeChildTransportOptions) {\n if (!options.allowedOrigins || options.allowedOrigins.length === 0) {\n throw new Error('At least one allowed origin must be specified');\n }\n\n this._allowedOrigins = options.allowedOrigins;\n this._channelId = options.channelId || 'mcp-iframe';\n this._serverReadyRetryMs = options.serverReadyRetryMs ?? 250;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (!this._allowedOrigins.includes(event.origin) && !this._allowedOrigins.includes('*')) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'client-to-server') {\n return;\n }\n\n this._clientOrigin = event.origin;\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-check-ready') {\n this.broadcastServerReady();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n this.broadcastServerReady();\n }\n\n private broadcastServerReady() {\n if (window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n '*'\n );\n\n this.clearServerReadyRetry();\n } else {\n this.scheduleServerReadyRetry();\n }\n }\n\n private scheduleServerReadyRetry() {\n if (this._serverReadyTimeout) {\n return;\n }\n\n this._serverReadyTimeout = setTimeout(() => {\n this._serverReadyTimeout = undefined;\n if (this._started) {\n this.broadcastServerReady();\n }\n }, this._serverReadyRetryMs);\n }\n\n private clearServerReadyRetry() {\n if (this._serverReadyTimeout) {\n clearTimeout(this._serverReadyTimeout);\n this._serverReadyTimeout = undefined;\n }\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._clientOrigin) {\n console.warn('[IframeChildTransport] No client connected, message not sent');\n return;\n }\n\n if (window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: message,\n },\n this._clientOrigin\n );\n } else {\n console.warn('[IframeChildTransport] Not running in an iframe, message not sent');\n }\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n this._started = false;\n\n if (this._clientOrigin && window.parent && window.parent !== window) {\n window.parent.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-stopped',\n },\n '*'\n );\n }\n\n this.clearServerReadyRetry();\n\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface IframeParentTransportOptions {\n /** Reference to the iframe element */\n iframe: HTMLIFrameElement;\n /** Expected origin of the iframe (for security) */\n targetOrigin: string;\n /** Optional channel name (default: 'mcp-iframe') */\n channelId?: string;\n /** Retry interval for ready handshake in milliseconds (default: 250) */\n checkReadyRetryMs?: number;\n}\n\n/**\n * IframeParentTransport - Client transport for parent page\n *\n * Use this transport when the parent page wants to connect to an MCP server\n * running inside an iframe. Supports cross-origin communication.\n *\n * @example\n * ```typescript\n * const iframe = document.querySelector('iframe');\n * const transport = new IframeParentTransport({\n * iframe,\n * targetOrigin: 'https://iframe-app.com',\n * });\n *\n * const client = new Client({ name: 'Parent', version: '1.0.0' });\n * await client.connect(transport);\n * ```\n */\nexport class IframeParentTransport implements Transport {\n private _started = false;\n private _iframe: HTMLIFrameElement;\n private _targetOrigin: string;\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _checkReadyTimeout: ReturnType<typeof setTimeout> | undefined;\n private readonly _checkReadyRetryMs: number;\n public readonly serverReadyPromise: Promise<void>;\n private _serverReadyResolve: () => void;\n private _serverReadyReject: (reason: any) => void;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: IframeParentTransportOptions) {\n if (!options.iframe) {\n throw new Error('iframe element is required');\n }\n if (!options.targetOrigin) {\n throw new Error('targetOrigin must be explicitly set for security');\n }\n\n this._iframe = options.iframe;\n this._targetOrigin = options.targetOrigin;\n this._channelId = options.channelId || 'mcp-iframe';\n this._checkReadyRetryMs = options.checkReadyRetryMs ?? 250;\n\n const { promise, resolve, reject } = Promise.withResolvers<void>();\n this.serverReadyPromise = promise;\n this._serverReadyResolve = resolve;\n this._serverReadyReject = reject;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (event.origin !== this._targetOrigin) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'server-to-client') {\n return;\n }\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-server-ready') {\n this._serverReadyResolve();\n this.clearCheckReadyRetry();\n return;\n }\n\n if (typeof payload === 'string' && payload === 'mcp-server-stopped') {\n console.log('[IframeParentTransport] Received mcp-server-stopped event, closing transport');\n this.close();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this._serverReadyResolve();\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n this.sendCheckReady();\n }\n\n private sendCheckReady() {\n const contentWindow = this._iframe.contentWindow;\n\n if (!contentWindow) {\n console.warn('[IframeParentTransport] iframe.contentWindow not available, will retry');\n this.scheduleCheckReadyRetry();\n return;\n }\n\n contentWindow.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: 'mcp-check-ready',\n },\n this._targetOrigin\n );\n }\n\n private scheduleCheckReadyRetry() {\n if (this._checkReadyTimeout) {\n return;\n }\n\n this._checkReadyTimeout = setTimeout(() => {\n this._checkReadyTimeout = undefined;\n if (this._started) {\n this.sendCheckReady();\n }\n }, this._checkReadyRetryMs);\n }\n\n private clearCheckReadyRetry() {\n if (this._checkReadyTimeout) {\n clearTimeout(this._checkReadyTimeout);\n this._checkReadyTimeout = undefined;\n }\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n await this.serverReadyPromise;\n\n const contentWindow = this._iframe.contentWindow;\n\n if (!contentWindow) {\n throw new Error('iframe.contentWindow not available');\n }\n\n contentWindow.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: message,\n },\n this._targetOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n\n this._serverReadyReject(new Error('Transport closed before server ready'));\n\n this.clearCheckReadyRetry();\n\n this._started = false;\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface TabClientTransportOptions {\n /** Origin expected from the server window (for security) */\n targetOrigin: string;\n /** Optional channel name (default: 'mcp-default') */\n channelId?: string;\n}\n\nexport class TabClientTransport implements Transport {\n private _started = false;\n private _targetOrigin: string;\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n public readonly serverReadyPromise: Promise<void>;\n private _serverReadyResolve: () => void;\n private _serverReadyReject: (reason: any) => void;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: TabClientTransportOptions) {\n if (!options.targetOrigin) {\n throw new Error('targetOrigin must be explicitly set for security');\n }\n this._targetOrigin = options.targetOrigin;\n this._channelId = options.channelId || 'mcp-default';\n\n // Create the server ready promise in constructor so it's available immediately\n const { promise, resolve, reject } = Promise.withResolvers<void>();\n this.serverReadyPromise = promise;\n this._serverReadyResolve = () => {\n resolve();\n };\n this._serverReadyReject = (reason) => {\n reject(reason);\n };\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (event.origin !== this._targetOrigin) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'server-to-client') {\n return;\n }\n\n const payload = event.data.payload;\n\n // Handle server ready signal\n if (typeof payload === 'string' && payload === 'mcp-server-ready') {\n this._serverReadyResolve();\n return;\n }\n\n // Handle server stopped signal\n if (typeof payload === 'string' && payload === 'mcp-server-stopped') {\n console.log('[TabClientTransport] Received mcp-server-stopped event, closing transport');\n this.close();\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this._serverReadyResolve();\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n // Send check-ready to prompt server if already started\n this.sendCheckReady();\n }\n\n private sendCheckReady() {\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: 'mcp-check-ready',\n },\n this._targetOrigin\n );\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n // Await server ready before sending any JSON-RPC message\n await this.serverReadyPromise;\n\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'client-to-server',\n payload: message,\n },\n this._targetOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n\n // Reject the server ready promise if it hasn't been resolved yet\n this._serverReadyReject(new Error('Transport closed before server ready'));\n\n this._started = false;\n this.onclose?.();\n }\n}\n","import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport interface TabServerTransportOptions {\n /** Whitelist of origins allowed to connect (for security) */\n allowedOrigins: string[];\n /** Optional channel name (default: 'mcp-default') */\n channelId?: string;\n}\n\nexport class TabServerTransport implements Transport {\n private _started = false;\n private _allowedOrigins: string[];\n private _channelId: string;\n private _messageHandler?: (event: MessageEvent) => void;\n private _clientOrigin?: string;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: TabServerTransportOptions) {\n if (!options.allowedOrigins || options.allowedOrigins.length === 0) {\n throw new Error('At least one allowed origin must be specified');\n }\n\n this._allowedOrigins = options.allowedOrigins;\n this._channelId = options.channelId || 'mcp-default';\n }\n\n async start(): Promise<void> {\n if (this._started) {\n throw new Error('Transport already started');\n }\n\n this._messageHandler = (event: MessageEvent) => {\n if (!this._allowedOrigins.includes(event.origin) && !this._allowedOrigins.includes('*')) {\n return;\n }\n\n if (event.data?.channel !== this._channelId || event.data?.type !== 'mcp') {\n return;\n }\n\n if (event.data?.direction !== 'client-to-server') {\n return;\n }\n\n this._clientOrigin = event.origin;\n\n const payload = event.data.payload;\n\n if (typeof payload === 'string' && payload === 'mcp-check-ready') {\n // Respond with server ready\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n this._clientOrigin\n );\n return;\n }\n\n try {\n const message = JSONRPCMessageSchema.parse(payload);\n this.onmessage?.(message);\n } catch (error) {\n this.onerror?.(\n new Error(`Invalid message: ${error instanceof Error ? error.message : String(error)}`)\n );\n }\n };\n\n window.addEventListener('message', this._messageHandler);\n this._started = true;\n\n // Broadcast server ready to all allowed origins\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-ready',\n },\n '*'\n );\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n // If we have a known client origin, use it (for security)\n // Otherwise, use '*' for backwards compatibility with clients that don't do the handshake\n const targetOrigin = this._clientOrigin || '*';\n\n if (!this._clientOrigin) {\n console.debug(\n '[TabServerTransport] Sending to unknown client origin (backwards compatibility mode)'\n );\n }\n\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: message,\n },\n targetOrigin\n );\n }\n\n async close(): Promise<void> {\n if (this._messageHandler) {\n window.removeEventListener('message', this._messageHandler);\n }\n this._started = false;\n\n // Post message to notify content scripts that the MCP server has stopped\n window.postMessage(\n {\n channel: this._channelId,\n type: 'mcp',\n direction: 'server-to-client',\n payload: 'mcp-server-stopped',\n },\n '*'\n );\n\n this.onclose?.();\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for UserScriptClientTransport\n */\nexport interface UserScriptClientTransportOptions {\n /**\n * The extension ID to connect to (optional for same-extension connections)\n */\n extensionId?: string;\n\n /**\n * Port name for the connection\n * Default: 'mcp'\n */\n portName?: string;\n\n /**\n * Enable automatic reconnection on disconnect\n * Default: true\n */\n autoReconnect?: boolean;\n\n /**\n * Maximum number of reconnection attempts\n * Default: 10\n */\n maxReconnectAttempts?: number;\n\n /**\n * Initial reconnection delay in milliseconds\n * Default: 1000\n */\n reconnectDelay?: number;\n\n /**\n * Maximum reconnection delay in milliseconds\n * Default: 30000\n */\n maxReconnectDelay?: number;\n\n /**\n * Reconnection backoff multiplier\n * Default: 1.5\n */\n reconnectBackoffMultiplier?: number;\n}\n\n/**\n * Client transport for Chrome MV3 User Scripts using Port-based messaging.\n * This transport can be used inside a User Script context to connect to the\n * extension's background service worker. On the extension side, connections\n * are received via chrome.runtime.onUserScriptConnect.\n *\n * Features automatic reconnection to handle background service worker lifecycle.\n */\nexport class UserScriptClientTransport implements Transport {\n private _port: chrome.runtime.Port | undefined;\n private _extensionId: string | undefined;\n private _portName: string;\n private _messageHandler: ((message: any) => void) | undefined;\n private _disconnectHandler: (() => void) | undefined;\n private _isReconnecting = false;\n private _reconnectAttempts = 0;\n private _reconnectTimer: number | undefined;\n private _currentReconnectDelay: number;\n private _isStarted = false;\n private _isClosed = false;\n\n // Configuration\n private _autoReconnect: boolean;\n private _maxReconnectAttempts: number;\n private _reconnectDelay: number;\n private _maxReconnectDelay: number;\n private _reconnectBackoffMultiplier: number;\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(options: UserScriptClientTransportOptions = {}) {\n this._extensionId = options.extensionId;\n this._portName = options.portName || 'mcp';\n this._autoReconnect = options.autoReconnect ?? true;\n this._maxReconnectAttempts = options.maxReconnectAttempts ?? 10;\n this._reconnectDelay = options.reconnectDelay ?? 1000;\n this._maxReconnectDelay = options.maxReconnectDelay ?? 30000;\n this._reconnectBackoffMultiplier = options.reconnectBackoffMultiplier ?? 1.5;\n this._currentReconnectDelay = this._reconnectDelay;\n }\n\n /**\n * Starts the transport by connecting to the extension port\n */\n async start(): Promise<void> {\n if (this._isStarted && this._port) {\n console.warn(\n 'UserScriptClientTransport already started! If using Client class, note that connect() calls start() automatically.'\n );\n return;\n }\n\n this._isStarted = true;\n this._isClosed = false;\n\n await this._connect();\n }\n\n /**\n * Connects to the extension port\n */\n private async _connect(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!chrome?.runtime?.connect) {\n reject(\n new Error(\n 'Chrome runtime API not available. This transport must be used in a Chrome MV3 User Script context.'\n )\n );\n return;\n }\n\n try {\n // Connect to the extension. From a user script, this triggers onUserScriptConnect on the extension side.\n if (this._extensionId) {\n this._port = chrome.runtime.connect(this._extensionId, {\n name: this._portName,\n });\n } else {\n this._port = chrome.runtime.connect({ name: this._portName });\n }\n\n // Set up message handler\n this._messageHandler = (message: any) => {\n try {\n // Handle keep-alive messages\n if ((message as any).type === 'keep-alive') {\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n this._cleanup();\n\n // Only attempt reconnection if we're started and not manually closed\n if (this._isStarted && !this._isClosed && this._autoReconnect) {\n this._scheduleReconnect();\n } else {\n this.onclose?.();\n }\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Check for immediate connection errors\n const error = chrome.runtime.lastError;\n if (error) {\n this._cleanup();\n\n // If we're reconnecting and hit an error, schedule another attempt\n if (this._isReconnecting && this._isStarted && !this._isClosed && this._autoReconnect) {\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n reject(new Error(`Connection failed: ${error.message}`));\n return;\n }\n\n // Connection successful\n this._reconnectAttempts = 0;\n this._currentReconnectDelay = this._reconnectDelay;\n this._isReconnecting = false;\n\n resolve();\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /**\n * Sends a message to the server\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._isStarted) {\n throw new Error('Transport not started');\n }\n\n if (this._isClosed) {\n throw new Error('Transport is closed');\n }\n\n if (!this._port) {\n throw new Error('Not connected');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._isClosed = true;\n this._isStarted = false;\n\n // Cancel any pending reconnection\n if (this._reconnectTimer !== undefined) {\n clearTimeout(this._reconnectTimer);\n this._reconnectTimer = undefined;\n }\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n this._port = undefined;\n }\n\n /**\n * Schedules a reconnection attempt\n */\n private _scheduleReconnect(): void {\n if (this._isReconnecting || this._isClosed || !this._isStarted) {\n return;\n }\n\n this._isReconnecting = true;\n\n // Check if we've exceeded max attempts\n if (this._reconnectAttempts >= this._maxReconnectAttempts) {\n console.error('Maximum reconnection attempts reached');\n this._isReconnecting = false;\n this.onerror?.(new Error('Maximum reconnection attempts reached'));\n this.onclose?.();\n return;\n }\n\n this._reconnectAttempts++;\n\n console.log(\n `Scheduling reconnection attempt ${this._reconnectAttempts}/${this._maxReconnectAttempts} in ${this._currentReconnectDelay}ms`\n );\n\n this._reconnectTimer = setTimeout(() => {\n this._attemptReconnect();\n }, this._currentReconnectDelay) as unknown as number;\n\n // Apply exponential backoff\n this._currentReconnectDelay = Math.min(\n this._currentReconnectDelay * this._reconnectBackoffMultiplier,\n this._maxReconnectDelay\n );\n }\n\n /**\n * Attempts to reconnect to the extension\n */\n private async _attemptReconnect(): Promise<void> {\n if (this._isClosed || !this._isStarted) {\n return;\n }\n\n try {\n // First, try to wake up the service worker by sending a message\n if (chrome?.runtime?.sendMessage) {\n try {\n await chrome.runtime.sendMessage({ type: 'ping' });\n } catch (_error) {\n // Service worker might not be ready yet\n }\n }\n\n // Attempt to connect\n await this._connect();\n\n console.log('Reconnection successful');\n this._isReconnecting = false;\n } catch (error) {\n console.error('Reconnection failed:', error);\n\n // Schedule another attempt\n this._scheduleReconnect();\n }\n }\n}\n","import type {\n Transport,\n TransportSendOptions,\n} from '@modelcontextprotocol/sdk/shared/transport.js';\nimport { type JSONRPCMessage, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Configuration options for UserScriptServerTransport\n */\nexport type UserScriptServerTransportOptions = {\n /**\n * Enable keep-alive mechanism to prevent service worker shutdown\n * Default: true\n */\n keepAlive?: boolean;\n\n /**\n * Keep-alive interval in milliseconds\n * Default: 25000 (25 seconds, less than Chrome's 30-second timeout)\n */\n keepAliveInterval?: number;\n};\n\n/**\n * Server transport for Chrome MV3 User Scripts using Port-based messaging.\n * This transport handles a single client connection through Chrome's port\n * messaging API. It should be used in the extension's background service\n * worker. Connections are initiated from User Scripts via chrome.runtime.connect\n * and received here via chrome.runtime.onUserScriptConnect.\n *\n * Features:\n * - Keep-alive mechanism to prevent service worker shutdown\n * - Graceful connection state management\n */\nexport class UserScriptServerTransport implements Transport {\n private _port: chrome.runtime.Port;\n private _started = false;\n private _messageHandler: ((message: unknown, port: chrome.runtime.Port) => void) | undefined;\n private _disconnectHandler: ((port: chrome.runtime.Port) => void) | undefined;\n private _keepAliveTimer: number | undefined;\n private _options: UserScriptServerTransportOptions;\n private _connectionInfo: {\n connectedAt: number;\n lastMessageAt: number;\n messageCount: number;\n };\n\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n constructor(port: chrome.runtime.Port, options: UserScriptServerTransportOptions = {}) {\n this._port = port;\n this._options = {\n keepAlive: options.keepAlive ?? true,\n keepAliveInterval: options.keepAliveInterval ?? 1000,\n };\n this._connectionInfo = {\n connectedAt: Date.now(),\n lastMessageAt: Date.now(),\n messageCount: 0,\n };\n }\n\n /**\n * Starts the transport and begins handling messages\n */\n async start(): Promise<void> {\n if (this._started) {\n throw new Error(\n 'UserScriptServerTransport already started! If using Server class, note that connect() calls start() automatically.'\n );\n }\n\n if (!this._port) {\n throw new Error('Port not available');\n }\n\n this._started = true;\n\n // Set up message handler\n this._messageHandler = (message: unknown) => {\n try {\n // Update connection info\n this._connectionInfo.lastMessageAt = Date.now();\n this._connectionInfo.messageCount++;\n\n // Handle ping messages for keep-alive\n const msg = message as { type?: string };\n if (msg.type === 'ping') {\n this._port.postMessage({ type: 'pong' });\n return;\n }\n\n const mcpMessage = JSONRPCMessageSchema.parse(message);\n this.onmessage?.(mcpMessage);\n } catch (error) {\n this.onerror?.(new Error(`Failed to parse message: ${error}`));\n }\n };\n\n // Set up disconnect handler\n this._disconnectHandler = () => {\n console.log(\n `[UserScriptServerTransport] Client disconnected after ${Date.now() - this._connectionInfo.connectedAt}ms, processed ${this._connectionInfo.messageCount} messages`\n );\n this._cleanup();\n this.onclose?.();\n };\n\n this._port.onMessage.addListener(this._messageHandler);\n this._port.onDisconnect.addListener(this._disconnectHandler);\n\n // Start keep-alive mechanism if enabled\n if (this._options.keepAlive) {\n this._startKeepAlive();\n }\n\n console.log(\n `[UserScriptServerTransport] Started with client: ${this._port.sender?.id || 'unknown'}`\n );\n }\n\n /**\n * Sends a message to the client\n */\n async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {\n if (!this._started) {\n throw new Error('Transport not started');\n }\n\n if (!this._port) {\n throw new Error('Not connected to client');\n }\n\n try {\n this._port.postMessage(message);\n } catch (error) {\n // Check if the error is due to disconnection\n if (chrome.runtime.lastError || !this._port) {\n this._cleanup();\n this.onclose?.();\n throw new Error('Client disconnected');\n }\n throw new Error(`Failed to send message: ${error}`);\n }\n }\n\n /**\n * Closes the transport\n */\n async close(): Promise<void> {\n this._started = false;\n\n if (this._port) {\n try {\n this._port.disconnect();\n } catch (_error) {\n // Port might already be disconnected\n }\n }\n\n this._cleanup();\n this.onclose?.();\n }\n\n /**\n * Cleans up event listeners and references\n */\n private _cleanup(): void {\n // Stop keep-alive timer\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n\n if (this._port) {\n if (this._messageHandler) {\n this._port.onMessage.removeListener(this._messageHandler);\n }\n if (this._disconnectHandler) {\n this._port.onDisconnect.removeListener(this._disconnectHandler);\n }\n }\n }\n\n /**\n * Starts the keep-alive mechanism\n */\n private _startKeepAlive(): void {\n if (this._keepAliveTimer) {\n return;\n }\n\n console.log(\n `[UserScriptServerTransport] Starting keep-alive with ${this._options.keepAliveInterval}ms interval`\n );\n\n this._keepAliveTimer = setInterval(() => {\n if (!this._port) {\n this._stopKeepAlive();\n return;\n }\n\n try {\n // Send a keep-alive ping\n this._port.postMessage({ type: 'keep-alive', timestamp: Date.now() });\n } catch (error) {\n console.error('[UserScriptServerTransport] Keep-alive failed:', error);\n this._stopKeepAlive();\n }\n }, this._options.keepAliveInterval!) as unknown as number;\n }\n\n /**\n * Stops the keep-alive mechanism\n */\n private _stopKeepAlive(): void {\n if (this._keepAliveTimer !== undefined) {\n clearInterval(this._keepAliveTimer);\n this._keepAliveTimer = undefined;\n }\n }\n\n /**\n * Gets connection information\n */\n getConnectionInfo() {\n return {\n ...this._connectionInfo,\n uptime: Date.now() - this._connectionInfo.connectedAt,\n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