dev3000 0.0.94 → 0.0.95
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/dev-environment.d.ts.map +1 -1
- package/dist/dev-environment.js +14 -10
- package/dist/dev-environment.js.map +1 -1
- package/mcp-server/.next/BUILD_ID +1 -1
- package/mcp-server/.next/build-manifest.json +2 -2
- package/mcp-server/.next/fallback-build-manifest.json +2 -2
- package/mcp-server/.next/next-server.js.nft.json +1 -1
- package/mcp-server/.next/prerender-manifest.json +3 -3
- package/mcp-server/.next/server/app/_global-error.html +2 -2
- package/mcp-server/.next/server/app/_global-error.rsc +1 -1
- package/mcp-server/.next/server/app/_not-found.html +1 -1
- package/mcp-server/.next/server/app/_not-found.rsc +1 -1
- package/mcp-server/.next/server/app/index.html +1 -1
- package/mcp-server/.next/server/app/index.rsc +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__94037b23._.js +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__94037b23._.js.map +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__cc74dbef._.js +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__cc74dbef._.js.map +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__dc0b0022._.js +1 -1
- package/mcp-server/.next/server/chunks/[root-of-the-server]__dc0b0022._.js.map +1 -1
- package/mcp-server/.next/server/server-reference-manifest.js +1 -1
- package/mcp-server/.next/server/server-reference-manifest.json +1 -1
- package/mcp-server/app/mcp/client-manager.ts +4 -3
- package/mcp-server/app/mcp/route.ts +52 -14
- package/package.json +1 -1
- /package/mcp-server/.next/static/{ZeZ7S325drnA0SH-odcGY → -TtqAPrTs-tn08AeRdCVu}/_buildManifest.js +0 -0
- /package/mcp-server/.next/static/{ZeZ7S325drnA0SH-odcGY → -TtqAPrTs-tn08AeRdCVu}/_clientMiddlewareManifest.json +0 -0
- /package/mcp-server/.next/static/{ZeZ7S325drnA0SH-odcGY → -TtqAPrTs-tn08AeRdCVu}/_ssgManifest.js +0 -0
|
@@ -2,6 +2,6 @@ module.exports=[76487,91478,469,97803,e=>{"use strict";let t;e.s([],72340),e.i(7
|
|
|
2
2
|
`)?l.slice(0,-1):l}),n=void 0,l="",c="");if(e.startsWith(":")){s&&s(e.slice(e.startsWith(": ")?2:1));return}let r=e.indexOf(":");if(-1!==r){let t=e.slice(0,r),a=" "===e[r+1]?2:1;d(t,e.slice(r+a),e);return}d(e,"",e)}function d(e,t,s){switch(e){case"event":c=t;break;case"data":l=`${l}${t}
|
|
3
3
|
`;break;case"id":n=t.includes("\0")?void 0:t;break;case"retry":/^\d+$/.test(t)?a(parseInt(t,10)):r(new x(`Invalid \`retry\` value: "${t}"`,{type:"invalid-retry",value:t,line:s}));break;default:r(new x(`Unknown field "${e.length>20?`${e.slice(0,20)}\u2026`:e}"`,{type:"unknown-field",field:e,value:t,line:s}))}}return{feed:function(e){let t=o?e.replace(/^\xEF\xBB\xBF/,""):e,[r,a]=function(e){let t=[],r="",a=0;for(;a<e.length;){let s=e.indexOf("\r",a),i=e.indexOf(`
|
|
4
4
|
`,a),o=-1;if(-1!==s&&-1!==i?o=Math.min(s,i):-1!==s?o=s===e.length-1?-1:s:-1!==i&&(o=i),-1===o){r=e.slice(a);break}{let r=e.slice(a,o);t.push(r),"\r"===e[(a=o+1)-1]&&e[a]===`
|
|
5
|
-
`&&a++}}return[t,r]}(`${i}${t}`);for(let e of r)u(e);i=a,o=!1},reset:function(e={}){i&&e.consume&&u(i),o=!0,n=void 0,l="",c="",i=""}}}({onEvent:e=>{s.enqueue(e)},onError(t){"terminate"===e?s.error(t):"function"==typeof e&&e(t)},onRetry:t,onComment:r})},transform(e){a.feed(e)}})}}let R={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2};class O extends Error{constructor(e,t){super(`Streamable HTTP error: ${t}`),this.code=e}}class C{constructor(e,t){var r;this._url=e,this._resourceMetadataUrl=void 0,this._requestInit=null==t?void 0:t.requestInit,this._authProvider=null==t?void 0:t.authProvider,this._fetch=null==t?void 0:t.fetch,this._sessionId=null==t?void 0:t.sessionId,this._reconnectionOptions=null!=(r=null==t?void 0:t.reconnectionOptions)?r:R}async _authThenStart(){var e;let t;if(!this._authProvider)throw new l("No auth provider");try{t=await h(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch})}catch(t){throw null==(e=this.onerror)||e.call(this,t),t}if("AUTHORIZED"!==t)throw new l;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){var e;let t={};if(this._authProvider){let e=await this._authProvider.tokens();e&&(t.Authorization=`Bearer ${e.access_token}`)}this._sessionId&&(t["mcp-session-id"]=this._sessionId),this._protocolVersion&&(t["mcp-protocol-version"]=this._protocolVersion);let r=this._normalizeHeaders(null==(e=this._requestInit)?void 0:e.headers);return new Headers({...t,...r})}async _startOrAuthSse(e){var t,r,a;let{resumptionToken:s}=e;try{let a=await this._commonHeaders();a.set("Accept","text/event-stream"),s&&a.set("last-event-id",s);let i=await (null!=(t=this._fetch)?t:fetch)(this._url,{method:"GET",headers:a,signal:null==(r=this._abortController)?void 0:r.signal});if(!i.ok){if(401===i.status&&this._authProvider)return await this._authThenStart();if(405===i.status)return;throw new O(i.status,`Failed to open SSE stream: ${i.statusText}`)}this._handleSseStream(i.body,e,!0)}catch(e){throw null==(a=this.onerror)||a.call(this,e),e}}_getNextReconnectionDelay(e){let t=this._reconnectionOptions.initialReconnectionDelay;return Math.min(t*Math.pow(this._reconnectionOptions.reconnectionDelayGrowFactor,e),this._reconnectionOptions.maxReconnectionDelay)}_normalizeHeaders(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):{...e}:{}}_scheduleReconnection(e,t=0){var r;let a=this._reconnectionOptions.maxRetries;if(a>0&&t>=a){null==(r=this.onerror)||r.call(this,Error(`Maximum reconnection attempts (${a}) exceeded.`));return}setTimeout(()=>{this._startOrAuthSse(e).catch(r=>{var a;null==(a=this.onerror)||a.call(this,Error(`Failed to reconnect SSE stream: ${r instanceof Error?r.message:String(r)}`)),this._scheduleReconnection(e,t+1)})},this._getNextReconnectionDelay(t))}_handleSseStream(e,t,r){let s;if(!e)return;let{onresumptiontoken:i,replayMessageId:o}=t;(async()=>{var t,n,l,c;try{let r=e.pipeThrough(new TextDecoderStream).pipeThrough(new k).getReader();for(;;){let{value:e,done:l}=await r.read();if(l)break;if(e.id&&(s=e.id,null==i||i(e.id)),!e.event||"message"===e.event)try{let r=a.JSONRPCMessageSchema.parse(JSON.parse(e.data));void 0!==o&&(0,a.isJSONRPCResponse)(r)&&(r.id=o),null==(t=this.onmessage)||t.call(this,r)}catch(e){null==(n=this.onerror)||n.call(this,e)}}}catch(e){if(null==(l=this.onerror)||l.call(this,Error(`SSE stream disconnected: ${e}`)),r&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:s,onresumptiontoken:i,replayMessageId:o},0)}catch(e){null==(c=this.onerror)||c.call(this,Error(`Failed to reconnect: ${e instanceof Error?e.message:String(e)}`))}}})()}async start(){if(this._abortController)throw Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(e){if(!this._authProvider)throw new l("No auth provider");if("AUTHORIZED"!==await h(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch}))throw new l("Failed to authorize")}async close(){var e,t;null==(e=this._abortController)||e.abort(),null==(t=this.onclose)||t.call(this)}async send(e,t){var r,s,i,o;try{let{resumptionToken:o,onresumptiontoken:n}=t||{};if(o)return void this._startOrAuthSse({resumptionToken:o,replayMessageId:(0,a.isJSONRPCRequest)(e)?e.id:void 0}).catch(e=>{var t;return null==(t=this.onerror)?void 0:t.call(this,e)});let c=await this._commonHeaders();c.set("content-type","application/json"),c.set("accept","application/json, text/event-stream");let u={...this._requestInit,method:"POST",headers:c,body:JSON.stringify(e),signal:null==(r=this._abortController)?void 0:r.signal},d=await (null!=(s=this._fetch)?s:fetch)(this._url,u),p=d.headers.get("mcp-session-id");if(p&&(this._sessionId=p),!d.ok){if(401===d.status&&this._authProvider){this._resourceMetadataUrl=function(e){let t=e.headers.get("WWW-Authenticate");if(!t)return;let[r,a]=t.split(" ");if("bearer"!==r.toLowerCase()||!a)return;let s=/resource_metadata="([^"]*)"/.exec(t);if(s)try{return new URL(s[1])}catch(e){return}}(d);let t=await h(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch});if("AUTHORIZED"!==t)throw new l;return this.send(e)}let t=await d.text().catch(()=>null);throw Error(`Error POSTing to endpoint (HTTP ${d.status}): ${t}`)}if(202===d.status){(0,a.isInitializedNotification)(e)&&this._startOrAuthSse({resumptionToken:void 0}).catch(e=>{var t;return null==(t=this.onerror)?void 0:t.call(this,e)});return}let m=(Array.isArray(e)?e:[e]).filter(e=>"method"in e&&"id"in e&&void 0!==e.id).length>0,f=d.headers.get("content-type");if(m)if(null==f?void 0:f.includes("text/event-stream"))this._handleSseStream(d.body,{onresumptiontoken:n},!1);else if(null==f?void 0:f.includes("application/json")){let e=await d.json();for(let t of Array.isArray(e)?e.map(e=>a.JSONRPCMessageSchema.parse(e)):[a.JSONRPCMessageSchema.parse(e)])null==(i=this.onmessage)||i.call(this,t)}else throw new O(-1,`Unexpected content type: ${f}`)}catch(e){throw null==(o=this.onerror)||o.call(this,e),e}}get sessionId(){return this._sessionId}async terminateSession(){var e,t,r;if(this._sessionId)try{let r=await this._commonHeaders(),a={...this._requestInit,method:"DELETE",headers:r,signal:null==(e=this._abortController)?void 0:e.signal},s=await (null!=(t=this._fetch)?t:fetch)(this._url,a);if(!s.ok&&405!==s.status)throw new O(s.status,`Failed to terminate session: ${s.statusText}`);this._sessionId=void 0}catch(e){throw null==(r=this.onerror)||r.call(this,e),e}}setProtocolVersion(e){this._protocolVersion=e}get protocolVersion(){return this._protocolVersion}}class T{clients=new Map;transports=new Map;tools=new Map;reconnectTimers=new Map;lastConfigs=new Map;toolDiscoveryListeners=[];toolUpdateSubscribers=[];async initialize(e){let t=[];for(let r of(e.chromeDevtools?.enabled&&t.push({name:"chrome-devtools",type:"stdio",command:e.chromeDevtools.command,args:e.chromeDevtools.args,enabled:!0}),e.nextjsDev?.enabled&&t.push({name:"nextjs-dev",type:"http",url:e.nextjsDev.url,enabled:!0}),t))try{await this.connectToMCP(r);let e="http"===r.type?r.url:`${r.command} ${r.args?.join(" ")}`;console.log(`[MCP Orchestrator] Connected to ${r.name} (${r.type}) at ${e}`)}catch(e){console.warn(`[MCP Orchestrator] Failed to connect to ${r.name}:`,e)}}async connectToMCP(e){let a;this.lastConfigs.set(e.name,e);let s=new t.Client({name:"dev3000-orchestrator",version:"1.0.0"},{capabilities:{}});if(s.onerror=t=>{console.error(`[MCP Orchestrator] ${e.name} error:`,t),"http"===e.type&&this.scheduleReconnect(e.name)},"http"===e.type&&e.url)a=new C(new URL(e.url));else if("stdio"===e.type&&e.command)a=new r.StdioClientTransport({command:e.command,args:e.args||[]});else throw Error(`Invalid MCP config for ${e.name}`);await s.connect(a),this.clients.set(e.name,s),this.transports.set(e.name,a);try{let t=await s.listTools(),r=Array.isArray(t?.tools)?t.tools:[];this.tools.set(e.name,r),r.length>0?(console.log(`[MCP Orchestrator] Discovered ${r.length} tools from ${e.name}`),this.notifyToolDiscovery()):console.log(`[MCP Orchestrator] No tools discovered from ${e.name} (will retry on first use)`),this.notifyToolsUpdated(e.name)}catch(t){this.tools.set(e.name,[]),console.log(`[MCP Orchestrator] Tool discovery deferred for ${e.name} (will discover on first tool call)`),this.notifyToolsUpdated(e.name)}}getAllTools(){let e=[];for(let[t,r]of this.tools.entries())for(let a of r)e.push({mcpName:t,tool:a});return e}async callTool(e,t,r){let a=this.clients.get(e);if(!a)throw Error(`MCP client '${e}' not connected`);try{return await a.callTool({name:t,arguments:r})}catch(r){throw console.error(`[MCP Orchestrator] Error calling ${e}.${t}:`,r),r}}isConnected(e){return this.clients.has(e)}getConnectedMCPs(){return Array.from(this.clients.keys())}onToolsUpdated(e){return this.toolUpdateSubscribers.push(e),()=>{this.toolUpdateSubscribers=this.toolUpdateSubscribers.filter(t=>t!==e)}}async waitForInitialTools(e=8e3){this.getAllTools().length>0||await new Promise(t=>{let r,a=()=>{clearTimeout(r),this.toolDiscoveryListeners=this.toolDiscoveryListeners.filter(e=>e!==a),t()};r=setTimeout(()=>{this.toolDiscoveryListeners=this.toolDiscoveryListeners.filter(e=>e!==a),t()},e),this.toolDiscoveryListeners.push(a)})}notifyToolDiscovery(){if(0===this.toolDiscoveryListeners.length||0===this.getAllTools().length)return;let e=[...this.toolDiscoveryListeners];for(let t of(this.toolDiscoveryListeners=[],e))t()}notifyToolsUpdated(e){let t=this.tools.get(e)??[];for(let r of this.toolUpdateSubscribers)try{r({mcpName:e,tools:t})}catch(t){console.warn(`[MCP Orchestrator] Tool update subscriber error for ${e}:`,t)}}scheduleReconnect(e){let t=this.reconnectTimers.get(e);t&&clearTimeout(t);let r=setTimeout(async()=>{let t=this.lastConfigs.get(e);if(!t)return void console.warn(`[MCP Orchestrator] No config found for reconnection: ${e}`);console.log(`[MCP Orchestrator] Attempting to reconnect to ${e}...`);try{let r=this.transports.get(e);if(r)try{await r.close()}catch{}this.clients.delete(e),this.transports.delete(e),await this.connectToMCP(t),console.log(`[MCP Orchestrator] Successfully reconnected to ${e}`)}catch(t){console.warn(`[MCP Orchestrator] Reconnection to ${e} failed:`,t),this.scheduleReconnect(e)}},3e3);this.reconnectTimers.set(e,r)}async disconnect(){for(let e of this.reconnectTimers.values())clearTimeout(e);for(let[e,t]of(this.reconnectTimers.clear(),this.transports.entries()))try{await t.close(),console.log(`[MCP Orchestrator] Disconnected from ${e}`)}catch(t){console.error(`[MCP Orchestrator] Error disconnecting from ${e}:`,t)}this.clients.clear(),this.transports.clear(),this.tools.clear(),this.lastConfigs.clear()}}let j=null;function $(){return j||(j=new T),j}e.s(["MCPClientManager",()=>T,"getMCPClientManager",()=>$],20539)}];
|
|
5
|
+
`&&a++}}return[t,r]}(`${i}${t}`);for(let e of r)u(e);i=a,o=!1},reset:function(e={}){i&&e.consume&&u(i),o=!0,n=void 0,l="",c="",i=""}}}({onEvent:e=>{s.enqueue(e)},onError(t){"terminate"===e?s.error(t):"function"==typeof e&&e(t)},onRetry:t,onComment:r})},transform(e){a.feed(e)}})}}let R={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2};class O extends Error{constructor(e,t){super(`Streamable HTTP error: ${t}`),this.code=e}}class C{constructor(e,t){var r;this._url=e,this._resourceMetadataUrl=void 0,this._requestInit=null==t?void 0:t.requestInit,this._authProvider=null==t?void 0:t.authProvider,this._fetch=null==t?void 0:t.fetch,this._sessionId=null==t?void 0:t.sessionId,this._reconnectionOptions=null!=(r=null==t?void 0:t.reconnectionOptions)?r:R}async _authThenStart(){var e;let t;if(!this._authProvider)throw new l("No auth provider");try{t=await h(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch})}catch(t){throw null==(e=this.onerror)||e.call(this,t),t}if("AUTHORIZED"!==t)throw new l;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){var e;let t={};if(this._authProvider){let e=await this._authProvider.tokens();e&&(t.Authorization=`Bearer ${e.access_token}`)}this._sessionId&&(t["mcp-session-id"]=this._sessionId),this._protocolVersion&&(t["mcp-protocol-version"]=this._protocolVersion);let r=this._normalizeHeaders(null==(e=this._requestInit)?void 0:e.headers);return new Headers({...t,...r})}async _startOrAuthSse(e){var t,r,a;let{resumptionToken:s}=e;try{let a=await this._commonHeaders();a.set("Accept","text/event-stream"),s&&a.set("last-event-id",s);let i=await (null!=(t=this._fetch)?t:fetch)(this._url,{method:"GET",headers:a,signal:null==(r=this._abortController)?void 0:r.signal});if(!i.ok){if(401===i.status&&this._authProvider)return await this._authThenStart();if(405===i.status)return;throw new O(i.status,`Failed to open SSE stream: ${i.statusText}`)}this._handleSseStream(i.body,e,!0)}catch(e){throw null==(a=this.onerror)||a.call(this,e),e}}_getNextReconnectionDelay(e){let t=this._reconnectionOptions.initialReconnectionDelay;return Math.min(t*Math.pow(this._reconnectionOptions.reconnectionDelayGrowFactor,e),this._reconnectionOptions.maxReconnectionDelay)}_normalizeHeaders(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):{...e}:{}}_scheduleReconnection(e,t=0){var r;let a=this._reconnectionOptions.maxRetries;if(a>0&&t>=a){null==(r=this.onerror)||r.call(this,Error(`Maximum reconnection attempts (${a}) exceeded.`));return}setTimeout(()=>{this._startOrAuthSse(e).catch(r=>{var a;null==(a=this.onerror)||a.call(this,Error(`Failed to reconnect SSE stream: ${r instanceof Error?r.message:String(r)}`)),this._scheduleReconnection(e,t+1)})},this._getNextReconnectionDelay(t))}_handleSseStream(e,t,r){let s;if(!e)return;let{onresumptiontoken:i,replayMessageId:o}=t;(async()=>{var t,n,l,c;try{let r=e.pipeThrough(new TextDecoderStream).pipeThrough(new k).getReader();for(;;){let{value:e,done:l}=await r.read();if(l)break;if(e.id&&(s=e.id,null==i||i(e.id)),!e.event||"message"===e.event)try{let r=a.JSONRPCMessageSchema.parse(JSON.parse(e.data));void 0!==o&&(0,a.isJSONRPCResponse)(r)&&(r.id=o),null==(t=this.onmessage)||t.call(this,r)}catch(e){null==(n=this.onerror)||n.call(this,e)}}}catch(e){if(null==(l=this.onerror)||l.call(this,Error(`SSE stream disconnected: ${e}`)),r&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:s,onresumptiontoken:i,replayMessageId:o},0)}catch(e){null==(c=this.onerror)||c.call(this,Error(`Failed to reconnect: ${e instanceof Error?e.message:String(e)}`))}}})()}async start(){if(this._abortController)throw Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(e){if(!this._authProvider)throw new l("No auth provider");if("AUTHORIZED"!==await h(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch}))throw new l("Failed to authorize")}async close(){var e,t;null==(e=this._abortController)||e.abort(),null==(t=this.onclose)||t.call(this)}async send(e,t){var r,s,i,o;try{let{resumptionToken:o,onresumptiontoken:n}=t||{};if(o)return void this._startOrAuthSse({resumptionToken:o,replayMessageId:(0,a.isJSONRPCRequest)(e)?e.id:void 0}).catch(e=>{var t;return null==(t=this.onerror)?void 0:t.call(this,e)});let c=await this._commonHeaders();c.set("content-type","application/json"),c.set("accept","application/json, text/event-stream");let u={...this._requestInit,method:"POST",headers:c,body:JSON.stringify(e),signal:null==(r=this._abortController)?void 0:r.signal},d=await (null!=(s=this._fetch)?s:fetch)(this._url,u),p=d.headers.get("mcp-session-id");if(p&&(this._sessionId=p),!d.ok){if(401===d.status&&this._authProvider){this._resourceMetadataUrl=function(e){let t=e.headers.get("WWW-Authenticate");if(!t)return;let[r,a]=t.split(" ");if("bearer"!==r.toLowerCase()||!a)return;let s=/resource_metadata="([^"]*)"/.exec(t);if(s)try{return new URL(s[1])}catch(e){return}}(d);let t=await h(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch});if("AUTHORIZED"!==t)throw new l;return this.send(e)}let t=await d.text().catch(()=>null);throw Error(`Error POSTing to endpoint (HTTP ${d.status}): ${t}`)}if(202===d.status){(0,a.isInitializedNotification)(e)&&this._startOrAuthSse({resumptionToken:void 0}).catch(e=>{var t;return null==(t=this.onerror)?void 0:t.call(this,e)});return}let m=(Array.isArray(e)?e:[e]).filter(e=>"method"in e&&"id"in e&&void 0!==e.id).length>0,f=d.headers.get("content-type");if(m)if(null==f?void 0:f.includes("text/event-stream"))this._handleSseStream(d.body,{onresumptiontoken:n},!1);else if(null==f?void 0:f.includes("application/json")){let e=await d.json();for(let t of Array.isArray(e)?e.map(e=>a.JSONRPCMessageSchema.parse(e)):[a.JSONRPCMessageSchema.parse(e)])null==(i=this.onmessage)||i.call(this,t)}else throw new O(-1,`Unexpected content type: ${f}`)}catch(e){throw null==(o=this.onerror)||o.call(this,e),e}}get sessionId(){return this._sessionId}async terminateSession(){var e,t,r;if(this._sessionId)try{let r=await this._commonHeaders(),a={...this._requestInit,method:"DELETE",headers:r,signal:null==(e=this._abortController)?void 0:e.signal},s=await (null!=(t=this._fetch)?t:fetch)(this._url,a);if(!s.ok&&405!==s.status)throw new O(s.status,`Failed to terminate session: ${s.statusText}`);this._sessionId=void 0}catch(e){throw null==(r=this.onerror)||r.call(this,e),e}}setProtocolVersion(e){this._protocolVersion=e}get protocolVersion(){return this._protocolVersion}}class T{clients=new Map;transports=new Map;tools=new Map;reconnectTimers=new Map;lastConfigs=new Map;toolDiscoveryListeners=[];toolUpdateSubscribers=[];async initialize(e){let t=[];for(let r of(e.chromeDevtools?.enabled&&t.push({name:"chrome-devtools",type:"stdio",command:e.chromeDevtools.command,args:e.chromeDevtools.args,enabled:!0}),e.nextjsDev?.enabled&&t.push({name:"nextjs-dev",type:"stdio",command:e.nextjsDev.command,args:e.nextjsDev.args,enabled:!0}),t))try{await this.connectToMCP(r);let e="http"===r.type?r.url:`${r.command} ${r.args?.join(" ")}`;console.log(`[MCP Orchestrator] Connected to ${r.name} (${r.type}) at ${e}`)}catch(e){console.warn(`[MCP Orchestrator] Failed to connect to ${r.name}:`,e)}}async connectToMCP(e){let a;this.lastConfigs.set(e.name,e);let s=new t.Client({name:"dev3000-orchestrator",version:"1.0.0"},{capabilities:{}});if(s.onerror=t=>{console.error(`[MCP Orchestrator] ${e.name} error:`,t),"http"===e.type&&this.scheduleReconnect(e.name)},"http"===e.type&&e.url)a=new C(new URL(e.url));else if("stdio"===e.type&&e.command)a=new r.StdioClientTransport({command:e.command,args:e.args||[]});else throw Error(`Invalid MCP config for ${e.name}`);await s.connect(a),this.clients.set(e.name,s),this.transports.set(e.name,a);try{let t=await s.listTools(),r=Array.isArray(t?.tools)?t.tools:[];this.tools.set(e.name,r),r.length>0?(console.log(`[MCP Orchestrator] Discovered ${r.length} tools from ${e.name}`),this.notifyToolDiscovery()):console.log(`[MCP Orchestrator] No tools discovered from ${e.name} (will retry on first use)`),this.notifyToolsUpdated(e.name)}catch(t){this.tools.set(e.name,[]),console.log(`[MCP Orchestrator] Tool discovery deferred for ${e.name} (will discover on first tool call)`),this.notifyToolsUpdated(e.name)}}getAllTools(){let e=[];for(let[t,r]of this.tools.entries())for(let a of r)e.push({mcpName:t,tool:a});return e}async callTool(e,t,r){let a=this.clients.get(e);if(!a)throw Error(`MCP client '${e}' not connected`);try{return await a.callTool({name:t,arguments:r})}catch(r){throw console.error(`[MCP Orchestrator] Error calling ${e}.${t}:`,r),r}}isConnected(e){return this.clients.has(e)}getConnectedMCPs(){return Array.from(this.clients.keys())}onToolsUpdated(e){return this.toolUpdateSubscribers.push(e),()=>{this.toolUpdateSubscribers=this.toolUpdateSubscribers.filter(t=>t!==e)}}async waitForInitialTools(e=8e3){this.getAllTools().length>0||await new Promise(t=>{let r,a=()=>{clearTimeout(r),this.toolDiscoveryListeners=this.toolDiscoveryListeners.filter(e=>e!==a),t()};r=setTimeout(()=>{this.toolDiscoveryListeners=this.toolDiscoveryListeners.filter(e=>e!==a),t()},e),this.toolDiscoveryListeners.push(a)})}notifyToolDiscovery(){if(0===this.toolDiscoveryListeners.length||0===this.getAllTools().length)return;let e=[...this.toolDiscoveryListeners];for(let t of(this.toolDiscoveryListeners=[],e))t()}notifyToolsUpdated(e){let t=this.tools.get(e)??[];for(let r of this.toolUpdateSubscribers)try{r({mcpName:e,tools:t})}catch(t){console.warn(`[MCP Orchestrator] Tool update subscriber error for ${e}:`,t)}}scheduleReconnect(e){let t=this.reconnectTimers.get(e);t&&clearTimeout(t);let r=setTimeout(async()=>{let t=this.lastConfigs.get(e);if(!t)return void console.warn(`[MCP Orchestrator] No config found for reconnection: ${e}`);console.log(`[MCP Orchestrator] Attempting to reconnect to ${e}...`);try{let r=this.transports.get(e);if(r)try{await r.close()}catch{}this.clients.delete(e),this.transports.delete(e),await this.connectToMCP(t),console.log(`[MCP Orchestrator] Successfully reconnected to ${e}`)}catch(t){console.warn(`[MCP Orchestrator] Reconnection to ${e} failed:`,t),this.scheduleReconnect(e)}},3e3);this.reconnectTimers.set(e,r)}async disconnect(){for(let e of this.reconnectTimers.values())clearTimeout(e);for(let[e,t]of(this.reconnectTimers.clear(),this.transports.entries()))try{await t.close(),console.log(`[MCP Orchestrator] Disconnected from ${e}`)}catch(t){console.error(`[MCP Orchestrator] Error disconnecting from ${e}:`,t)}this.clients.clear(),this.transports.clear(),this.tools.clear(),this.lastConfigs.clear()}}let j=null;function $(){return j||(j=new T),j}e.s(["MCPClientManager",()=>T,"getMCPClientManager",()=>$],20539)}];
|
|
6
6
|
|
|
7
7
|
//# sourceMappingURL=%5Broot-of-the-server%5D__cc74dbef._.js.map
|