@mcp-use/inspector 1.0.0-canary.9 → 1.0.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/cdn/inspector.css +1 -1
- package/dist/cdn/inspector.js +79424 -78744
- package/dist/client/index.js +13657 -775
- package/dist/web/assets/{browser-ctrPxPGG.js → browser-BwHKNEau.js} +4 -4
- package/dist/web/assets/{chunk-62CHIOHA-BqLxpYpN.js → chunk-BBSBHVGK-D4wCPq_w.js} +1 -1
- package/dist/web/assets/{chunk-VAZ3ORZF-xdDkmZd3.js → chunk-ECXMLUNG-CSRGaMIB.js} +1 -1
- package/dist/web/assets/{chunk-JU7W27UC-B2439jaH.js → chunk-JU7W27UC-CMTI_w7A.js} +1 -1
- package/dist/web/assets/{chunk-QWQYAQCK-CyFuZlX8.js → chunk-QWQYAQCK-BR4V0xsV.js} +1 -1
- package/dist/web/assets/{chunk-RPN2XO5I-BhkUchqc.js → chunk-RPN2XO5I-Cr13Miz-.js} +1 -1
- package/dist/web/assets/{chunk-UJPHRNQP-C5slpjuZ.js → chunk-UJPHRNQP-B14ZPq5a.js} +1 -1
- package/dist/web/assets/{chunk_array-DyR0murc.js → chunk_array-Bw1lTtex.js} +1 -1
- package/dist/web/assets/{client-SJZVAN5F-B1CFq11b.js → client-2BTCLEUX-BhvJZmo-.js} +3 -3
- package/dist/web/assets/{client-DbpdPhaZ.js → client-z1GrRUEs.js} +2 -2
- package/dist/web/assets/{display-A5IEINAP-C6oc4kO3.js → display-A5IEINAP-B8BJrcag.js} +1 -1
- package/dist/web/assets/{dist-B902efBV.js → dist-BZmXa__p.js} +1 -1
- package/dist/web/assets/{dist-CZy-FXZn.js → dist-JsQmV3pO.js} +1 -1
- package/dist/web/assets/{dist-DgSb0Sz-.js → dist-t5Yo0YiG.js} +1 -1
- package/dist/web/assets/{function_calling-BfpScnEV.js → function_calling-kK7um7Ye.js} +1 -1
- package/dist/web/assets/index-CM9P_1sf.css +2 -0
- package/dist/web/assets/index-zlrXpRSB.js +720 -0
- package/dist/web/assets/langfuse-U2OEF7K7-BF5JV8uu.js +1 -0
- package/dist/web/assets/{llms-BsPQSnXF.js → llms-ByyTYk2T.js} +1 -1
- package/dist/web/assets/{messages-CARqPn1v.js → messages-D4_mH1tk.js} +1 -1
- package/dist/web/assets/react-C6BFTceN.js +1 -0
- package/dist/web/assets/rpc-logger-TPNV75J4-CMVlzCN7.js +1 -0
- package/dist/web/assets/{schemas-R05rZMzG.js → schemas-BrqAD_Qo.js} +1 -1
- package/dist/web/assets/{stdio-LCWQPR45-CGHsqeDK.js → stdio-RWLH66ZO-C753VwJ7.js} +1 -1
- package/dist/web/assets/{tools-Dk1xpPiY.js → tools-kLe9X8V8.js} +1 -1
- package/dist/web/index.html +13 -13
- package/package.json +8 -17
- package/dist/web/assets/index-DAB6h2wg.css +0 -2
- package/dist/web/assets/index-DdgwtcKr.js +0 -430
- package/dist/web/assets/langfuse-U2OEF7K7-CXu1ftDi.js +0 -1
- package/dist/web/assets/react-CR79PxS-.js +0 -1
- package/dist/web/assets/rpc-logger-TPNV75J4-DvyEg0Mj.js +0 -1
- /package/dist/web/assets/{chunk-3GQAWCBQ-C-9Cm0Np.js → chunk-3GQAWCBQ-ntjTDD_C.js} +0 -0
- /package/dist/web/assets/{json-schema-processors-BJc5OsHH.js → json-schema-processors-DNSjFPrk.js} +0 -0
- /package/dist/web/assets/{preload-helper-7Icc4Czl.js → preload-helper-ckxxtgMM.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./chunk-3GQAWCBQ-
|
|
1
|
+
import{t as e}from"./chunk-3GQAWCBQ-ntjTDD_C.js";import{_ as t,a as n,b as r,i,m as a,o,p as s,s as c,v as l}from"./schemas-BrqAD_Qo.js";import{f as u}from"./chunk-ECXMLUNG-CSRGaMIB.js";var d=class{static{e(this,`JSONSchemaToZod`)}static convert(e){return this.parseSchema(e)}static matchesCondition(e,t){if(!t.properties)return!0;if(typeof e!=`object`||!e||Array.isArray(e))return!1;let n=e;for(let[e,r]of Object.entries(t.properties)){if(!(e in n)){if(`const`in r)return!1;continue}let t=n[e];if(`const`in r&&t!==r.const||`minimum`in r&&typeof t==`number`&&t<r.minimum||`maximum`in r&&typeof t==`number`&&t>r.maximum)return!1}return!0}static validateConditionalSchema(e,t,n){this.validateRequiredProperties(e,t,n),this.validatePropertyPatterns(e,t,n),this.validateNestedConditions(e,t,n)}static validateRequiredProperties(e,t,n){if(t.required){if(typeof e!=`object`||!e){for(let e of t.required)n.addIssue({code:u.custom,message:`Required property '${e}' is missing`,path:[e]});return}for(let r of t.required)r in e||n.addIssue({code:u.custom,message:`Required property '${r}' is missing`,path:[r]})}}static validatePropertyPatterns(e,t,n){if(!t.properties||typeof e!=`object`||!e||Array.isArray(e))return;let r=e;for(let[e,i]of Object.entries(t.properties)){if(!(e in r))continue;let t=r[e];i.pattern&&typeof t==`string`&&(new RegExp(i.pattern).test(t)||n.addIssue({code:u.custom,message:`String '${t}' does not match pattern '${i.pattern}'`,path:[e]}))}}static validateNestedConditions(e,t,n){!t.if||!t.then||(this.matchesCondition(e,t.if)?this.validateConditionalSchema(e,t.then,n):t.else&&this.validateConditionalSchema(e,t.else,n))}static parseSchema(e){let t;return t=Array.isArray(e.type)?this.handleTypeArray(e):e.oneOf||e.anyOf||e.allOf?this.parseCombinator(e):e.if&&e.then||e.properties&&(!e.type||e.type===`object`)?this.parseObject(e):this.handleSingleType(e),e.description&&typeof t.describe==`function`&&(t=t.describe(e.description)),t}static handleTypeArray(e){if(!Array.isArray(e.type))throw Error(`Expected schema.type to be an array`);return e.type.includes(`null`)?this.handleNullableType(e):this.createUnionFromTypes(e.type,e)}static handleNullableType(e){if(!Array.isArray(e.type))throw Error(`Expected schema.type to be an array`);let t={...e};return t.type=e.type.filter(e=>e!==`null`),t.type.length===1?this.handleSingleType({...e,type:t.type[0]}).nullable():this.parseSchema(t).nullable()}static createUnionFromTypes(e,t){return r(e.map(e=>{let n={...t,type:e};return this.parseSchema(n)}))}static handleSingleType(e){if(e.type===void 0)return e.oneOf||e.anyOf||e.allOf?this.parseCombinator(e):e.properties?this.parseObject(e):n();switch(e.type){case`string`:return this.parseString(e);case`number`:case`integer`:return this.parseNumberSchema(e);case`boolean`:return c();case`array`:return this.parseArray(e);case`object`:return this.parseObject(e);default:throw Error(`Unsupported schema type`)}}static parseNumberSchema(e){let t=s(),n=t;return n=this.applyNumberBounds(t,e),n=this.applyNumberMultipleOf(t,e),n=this.applyNumberEnum(t,e),n=this.applyIntegerConstraint(t,e),n}static applyNumberBounds(e,t){let n=e;return t.minimum!==void 0&&(n=t.exclusiveMinimum?n.gt(t.minimum):n.gte(t.minimum)),t.maximum!==void 0&&(n=t.exclusiveMaximum?n.lt(t.maximum):n.lte(t.maximum)),n}static applyNumberMultipleOf(e,t){return t.multipleOf===void 0?e:e.refine(e=>e%t.multipleOf===0,{message:`Number must be a multiple of ${t.multipleOf}`})}static applyNumberEnum(e,t){if(!t.enum)return e;let n=t.enum.filter(e=>typeof e==`number`);return n.length===0?e:e.refine(e=>n.includes(e),{message:`Number must be one of: ${n.join(`, `)}`})}static applyIntegerConstraint(e,t){return t.type===`integer`?e.refine(e=>Number.isInteger(e),{message:`Number must be an integer`}):e}static parseString(e){let t=l(),n=t;return e.format?this.applyStringFormat(t,e):(n=this.applyStringPattern(t,e),n=this.applyStringLength(t,e),n=this.applyStringEnum(t,e),n)}static applyStringFormat(e,t){if(!t.format)return e;switch(t.format){case`email`:return e.email();case`date-time`:return e.datetime();case`uri`:return e.url();case`uuid`:return e.uuid();case`date`:return e.date();default:return e}}static applyStringPattern(e,t){if(!t.pattern)return e;let n=new RegExp(t.pattern);return e.regex(n,{message:`String must match pattern: ${t.pattern}`})}static applyStringLength(e,t){let n=e;return t.minLength!==void 0&&(e=e.min(t.minLength)),t.maxLength!==void 0&&(e=e.max(t.maxLength)),n}static applyStringEnum(e,t){return t.enum?e.refine(e=>t.enum?.includes(e),{message:`Value must be one of: ${t.enum?.join(`, `)}`}):e}static parseArray(e){if(Array.isArray(e.items))return r(e.items.map(e=>this.parseSchema(e)));let t=o(e.items?this.parseSchema(e.items):n()),i=t;return i=this.applyArrayConstraints(t,e),i}static applyArrayConstraints(e,t){return t.minItems!==void 0&&(e=e.min(t.minItems)),t.maxItems!==void 0&&(e=e.max(t.maxItems)),t.uniqueItems?e.refine(e=>new Set(e).size===e.length,{message:`Array items must be unique`}):e}static parseObject(e){if(e.if&&e.then)return this.parseConditional(e);if(!e.properties&&e.additionalProperties&&typeof e.additionalProperties==`object`){let n=this.parseSchema(e.additionalProperties);return t(l(),n)}let n={};return this.processObjectProperties(e,n),this.processAdditionalProperties(e,a(n))}static processObjectProperties(e,t){let n=new Set(e.required||[]);if(e.properties)for(let[r,i]of Object.entries(e.properties)){let e=this.parseSchema(i);t[r]=n.has(r)?e:e.optional()}}static processAdditionalProperties(e,t){if(e.additionalProperties===!0)return t.passthrough();if(e.additionalProperties&&typeof e.additionalProperties==`object`){let n=this.parseSchema(e.additionalProperties);return t.catchall(n)}else return t.strict()}static parseConditional(e){let t=this.createBaseObjectSchema(e),n=e.if,r=e.then,i=e.else;return t.superRefine((t,a)=>{let o=this.applyDefaultValues(t,e);this.matchesCondition(o,n)?this.validateConditionalSchema(o,r,a):i&&this.validateConditionalSchema(o,i,a)})}static createBaseObjectSchema(e){let t={},n=new Set(e.required||[]);for(let[r,i]of Object.entries(e.properties||{})){let e=this.parseSchema(i);t[r]=n.has(r)?e:e.optional()}let r=a(t);return this.processAdditionalProperties(e,r)}static applyDefaultValues(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return e;let n={...e};if(!t.properties)return n;for(let[e,r]of Object.entries(t.properties))!(e in n)&&`default`in r&&(n[e]=r.default);return n}static parseCombinator(e){if(e.oneOf)return this.parseOneOf(e.oneOf);if(e.anyOf)return this.parseAnyOf(e.anyOf);if(e.allOf)return this.parseAllOf(e.allOf);throw Error(`Unsupported schema type`)}static parseOneOf(e){return this.createUnionFromSchemas(e)}static parseAnyOf(e){return this.createUnionFromSchemas(e)}static createUnionFromSchemas(e){if(e.length===0)return n();if(e.length===1)return this.parseSchema(e[0]);let t=[];for(let n of e)n.type===`null`?t.push(i()):t.push(this.parseSchema(n));return t.length>=2?r(t):t.length===1?t[0]:n()}static parseAllOf(e){if(e.length===0)return n();if(e.length===1)return this.parseSchema(e[0]);let t=e.reduce((e,t)=>this.mergeSchemas(e,t));return this.parseSchema(t)}static mergeSchemas(e,t){let n={...e,...t};return e.properties&&t.properties&&(n.properties={...e.properties,...t.properties}),e.required&&t.required&&(n.required=[...new Set([...e.required,...t.required])]),n}};export{d as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./chunk-3GQAWCBQ-
|
|
1
|
+
import{t as e}from"./chunk-3GQAWCBQ-ntjTDD_C.js";import{n as t}from"./chunk-QWQYAQCK-BR4V0xsV.js";import{t as n}from"./preload-helper-ckxxtgMM.js";function r(e){if(typeof process<`u`)return{}[e]}e(r,`getEnvVar`);var i=r(`MCP_USE_LANGFUSE`)?.toLowerCase()===`false`,a={handler:null,client:null,initPromise:null};async function o(i,o,s,c){try{let l=await n(()=>import(`langfuse-langchain`),[]).catch(()=>null);if(!l){t.debug(`Langfuse package not installed - tracing disabled. Install with: npm install @langfuse/langchain`);return}let{CallbackHandler:u}=l;class d extends u{static{e(this,`LoggingCallbackHandler`)}agentId;metadata;metadataProvider;tagsProvider;verbose;constructor(e,t,n,r,i){super(e),this.agentId=t,this.metadata=n,this.metadataProvider=r,this.tagsProvider=i,this.verbose=e?.verbose??!1}async handleChainStart(e,n,r,i,a,o,s,c){t.debug(`Langfuse: Chain start intercepted`);let l=this.getCustomTags(),u=this.getMetadata(),d=[...a||[],...l],f={...o||{},...u};return this.verbose&&(t.debug(`Langfuse: Chain start with custom tags: ${JSON.stringify(d)}`),t.debug(`Langfuse: Chain start with metadata: ${JSON.stringify(f)}`)),super.handleChainStart(e,n,r,i,d,f,s,c)}getCustomTags(){let e=[],t=this.getEnvironmentTag();if(t&&e.push(`env:${t}`),this.agentId&&e.push(`agent_id:${this.agentId}`),this.tagsProvider){let t=this.tagsProvider();t&&t.length>0&&e.push(...t)}return e}getMetadata(){let e={},t=this.getEnvironmentTag();if(t&&(e.env=t),this.agentId&&(e.agent_id=this.agentId),this.metadata&&Object.assign(e,this.metadata),this.metadataProvider){let t=this.metadataProvider();t&&Object.assign(e,t)}return e}getEnvironmentTag(){let e=r(`MCP_USE_AGENT_ENV`);if(!e)return`unknown`;let t=e.toLowerCase();return t===`local`||t===`development`?`local`:t===`production`||t===`prod`?`production`:t===`staging`||t===`stage`?`staging`:t===`hosted`||t===`cloud`?`hosted`:t.replace(/[^a-z0-9_-]/g,`_`)}async handleLLMStart(...e){return t.debug(`Langfuse: LLM start intercepted`),this.verbose&&t.debug(`Langfuse: LLM start args: ${JSON.stringify(e)}`),super.handleLLMStart(...e)}async handleToolStart(...e){return t.debug(`Langfuse: Tool start intercepted`),this.verbose&&t.debug(`Langfuse: Tool start args: ${JSON.stringify(e)}`),super.handleToolStart(...e)}async handleRetrieverStart(...e){return t.debug(`Langfuse: Retriever start intercepted`),this.verbose&&t.debug(`Langfuse: Retriever start args: ${JSON.stringify(e)}`),super.handleRetrieverStart(...e)}async handleAgentAction(...e){return t.debug(`Langfuse: Agent action intercepted`),this.verbose&&t.debug(`Langfuse: Agent action args: ${JSON.stringify(e)}`),super.handleAgentAction(...e)}async handleAgentEnd(...e){return t.debug(`Langfuse: Agent end intercepted`),this.verbose&&t.debug(`Langfuse: Agent end args: ${JSON.stringify(e)}`),super.handleAgentEnd(...e)}}let f=o||(s?s():{}),p=c?c():[],m={publicKey:r(`LANGFUSE_PUBLIC_KEY`),secretKey:r(`LANGFUSE_SECRET_KEY`),baseUrl:r(`LANGFUSE_HOST`)||r(`LANGFUSE_BASEURL`)||`https://cloud.langfuse.com`,flushAt:Number.parseInt(r(`LANGFUSE_FLUSH_AT`)||`15`),flushInterval:Number.parseInt(r(`LANGFUSE_FLUSH_INTERVAL`)||`10000`),release:r(`LANGFUSE_RELEASE`),requestTimeout:Number.parseInt(r(`LANGFUSE_REQUEST_TIMEOUT`)||`10000`),enabled:r(`LANGFUSE_ENABLED`)!==`false`,traceName:f.trace_name||r(`LANGFUSE_TRACE_NAME`)||`mcp-use-agent`,sessionId:f.session_id||void 0,userId:f.user_id||void 0,tags:p.length>0?p:void 0,metadata:f||void 0};t.debug(`Langfuse handler config:`,JSON.stringify({traceName:m.traceName,sessionId:m.sessionId,userId:m.userId,tags:m.tags},null,2)),a.handler=new d(m,i,o,s,c),t.debug(`Langfuse observability initialized successfully with logging enabled`);try{let e=await n(()=>import(`langfuse`),[]).catch(()=>null);if(e){let{Langfuse:n}=e;a.client=new n({publicKey:r(`LANGFUSE_PUBLIC_KEY`),secretKey:r(`LANGFUSE_SECRET_KEY`),baseUrl:r(`LANGFUSE_HOST`)||`https://cloud.langfuse.com`}),t.debug(`Langfuse client initialized`)}}catch(e){t.debug(`Langfuse client initialization failed: ${e}`)}}catch(e){t.debug(`Langfuse initialization error: ${e}`)}}e(o,`initializeLangfuse`),i?t.debug(`Langfuse tracing disabled via MCP_USE_LANGFUSE environment variable`):!r(`LANGFUSE_PUBLIC_KEY`)||!r(`LANGFUSE_SECRET_KEY`)?t.debug(`Langfuse API keys not found - tracing disabled. Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY to enable`):a.initPromise=o();var s=e(()=>a.handler,`langfuseHandler`),c=e(()=>a.initPromise,`langfuseInitPromise`);export{s as n,c as r,o as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{nt as e,zn as t}from"./messages-
|
|
1
|
+
import{nt as e,zn as t}from"./messages-D4_mH1tk.js";var n={};t(n,{Embeddings:()=>r});var r=class{caller;constructor(t){this.caller=new e(t??{})}},i={};t(i,{chunkArray:()=>a});var a=(e,t)=>e.reduce((e,n,r)=>{let i=Math.floor(r/t);return e[i]=(e[i]||[]).concat([n]),e},[]);export{r as n,n as r,i as t};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/stdio-
|
|
2
|
-
import{n as e,t}from"./chunk-3GQAWCBQ-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/stdio-RWLH66ZO-C753VwJ7.js","assets/chunk-zsgVPwQN.js","assets/client-z1GrRUEs.js","assets/preload-helper-ckxxtgMM.js","assets/schemas-BrqAD_Qo.js","assets/json-schema-processors-DNSjFPrk.js","assets/chunk-3GQAWCBQ-ntjTDD_C.js","assets/chunk-QWQYAQCK-BR4V0xsV.js","assets/path-CG3438uq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{n as e,t}from"./chunk-3GQAWCBQ-ntjTDD_C.js";import{n}from"./chunk-QWQYAQCK-BR4V0xsV.js";import{c as r,i,n as a}from"./client-z1GrRUEs.js";import{a as o,i as s,o as c,r as l,t as u}from"./chunk-ECXMLUNG-CSRGaMIB.js";import{t as d}from"./preload-helper-ckxxtgMM.js";import{t as f}from"./chunk-RPN2XO5I-Cr13Miz-.js";import{i as p,n as m,o as h,t as g}from"./path-CG3438uq.js";h(),g();var _=class{static{t(this,`BaseCodeExecutor`)}client;_connecting=!1;constructor(e){this.client=e}async ensureServersConnected(){let e=this.client.getServerNames(),t=Object.keys(this.client.getAllActiveSessions()),r=e.filter(e=>!t.includes(e));if(r.length>0&&!this._connecting){this._connecting=!0;try{n.debug(`Connecting to configured servers for code execution: ${r.join(`, `)}`),await this.client.createAllSessions()}finally{this._connecting=!1}}else if(r.length>0&&this._connecting){n.debug(`Waiting for ongoing server connection...`);let e=Date.now();for(;this._connecting&&Date.now()-e<5e3;)await new Promise(e=>setTimeout(e,100))}}getToolNamespaces(){let e=[],t=this.client.getAllActiveSessions();for(let[r,i]of Object.entries(t))if(r!==`code_mode`)try{let t=i.connector,a;try{a=t.tools}catch(e){n.warn(`Tools not available for server ${r}: ${e}`);continue}if(!a||a.length===0)continue;e.push({serverName:r,tools:a,session:i})}catch(e){n.warn(`Failed to load tools for server ${r}: ${e}`)}return e}createSearchToolsFunction(){return async(e=``,t=`full`)=>{let r=[],i=new Set,a=e.toLowerCase(),o=this.client.getAllActiveSessions();for(let[e,a]of Object.entries(o))if(e!==`code_mode`)try{let n=a.connector.tools;n&&n.length>0&&i.add(e);for(let i of n)t===`names`?r.push({name:i.name,server:e}):t===`descriptions`?r.push({name:i.name,server:e,description:i.description}):r.push({name:i.name,server:e,description:i.description,input_schema:i.inputSchema})}catch(t){n.warn(`Failed to search tools in server ${e}: ${t}`)}let s=r;return e&&(s=r.filter(e=>{let t=e.name.toLowerCase().includes(a),n=e.description?.toLowerCase().includes(a),r=e.server.toLowerCase().includes(a);return t||n||r})),{meta:{total_tools:r.length,namespaces:Array.from(i).sort(),result_count:s.length},results:s}}}},v=class extends _{static{t(this,`E2BCodeExecutor`)}e2bApiKey;codeExecSandbox=null;SandboxClass=null;timeoutMs;constructor(e,t){super(e),this.e2bApiKey=t.apiKey,this.timeoutMs=t.timeoutMs??3e5}async ensureSandboxClass(){if(!this.SandboxClass)try{this.SandboxClass=(await d(()=>import(`@e2b/code-interpreter`),[])).Sandbox}catch{throw Error(`@e2b/code-interpreter is not installed. The E2B code executor requires this optional dependency. Install it with: yarn add @e2b/code-interpreter`)}}async getOrCreateCodeExecSandbox(){return this.codeExecSandbox?this.codeExecSandbox:(await this.ensureSandboxClass(),n.debug(`Starting E2B sandbox for code execution...`),this.codeExecSandbox=await this.SandboxClass.create(`base`,{apiKey:this.e2bApiKey,timeoutMs:this.timeoutMs}),this.codeExecSandbox)}generateShim(e){let t=`
|
|
3
3
|
// MCP Bridge Shim
|
|
4
4
|
global.__callMcpTool = async (server, tool, args) => {
|
|
5
5
|
const id = Math.random().toString(36).substring(7);
|
|
@@ -88,4 +88,4 @@ ${this.generateShim(c)}
|
|
|
88
88
|
throw e;
|
|
89
89
|
}
|
|
90
90
|
})()
|
|
91
|
-
`;o=await new y.Script(n,{filename:`agent_code.js`}).runInNewContext(t,{timeout:r,displayErrors:!0})}catch(e){s=e.message||String(e),(e.code===`ERR_SCRIPT_EXECUTION_TIMEOUT`||e.message===`Script execution timed out.`||typeof s==`string`&&(s.includes(`timed out`)||s.includes(`timeout`)))&&(s=`Script execution timed out`),e.stack&&n.debug(`Code execution error stack: ${e.stack}`)}let c=(Date.now()-a)/1e3;return{result:o,logs:i,error:s,execution_time:c}}async _buildContext(e){let n=t((...t)=>{e.push(t.map(e=>typeof e==`object`?JSON.stringify(e,null,2):String(e)).join(` `))},`logHandler`),r={console:{log:n,error:t((...e)=>{n(`[ERROR]`,...e)},`error`),warn:t((...e)=>{n(`[WARN]`,...e)},`warn`),info:n,debug:n},Object,Array,String,Number,Boolean,Date,Math,JSON,RegExp,Map,Set,Promise,parseInt,parseFloat,isNaN,isFinite,encodeURI,decodeURI,encodeURIComponent,decodeURIComponent,setTimeout,clearTimeout,search_tools:this.createSearchToolsFunction(),__tool_namespaces:[]},i={},a=this.getToolNamespaces();for(let{serverName:e,tools:t,session:n}of a){let a={};for(let e of t){let t=e.name;a[t]=async e=>{let r=await n.connector.callTool(t,e||{});if(r.content&&r.content.length>0){let e=r.content[0];if(e.type===`text`)try{return JSON.parse(e.text)}catch{return e.text}return e}return r}}r[e]=a,i[e]=!0}return r.__tool_namespaces=Object.keys(i),y.createContext(r)}async cleanup(){}},E=class extends a{static{t(this,`CodeModeConnector`)}mcpClient;_tools;constructor(e){super(),this.mcpClient=e,this.connected=!0,this._tools=this._createToolsList()}async connect(){this.connected=!0}async disconnect(){this.connected=!1}get publicIdentifier(){return{name:`code_mode`,version:`1.0.0`}}_createToolsList(){return[{name:`execute_code`,description:`Execute JavaScript/TypeScript code with access to MCP tools. This is the PRIMARY way to interact with MCP servers in code mode. Write code that discovers tools using search_tools(), calls tools as async functions (e.g., await github.get_pull_request(...)), processes data efficiently, and returns results. Use 'await' for async operations and 'return' to return values. Available in code: search_tools(), __tool_namespaces, and server.tool_name() functions.`,inputSchema:{type:`object`,properties:{code:{type:`string`,description:`JavaScript/TypeScript code to execute. Use 'await' for async operations. Use 'return' to return a value. Available: search_tools(), server.tool_name(), __tool_namespaces`},timeout:{type:`number`,description:`Execution timeout in milliseconds`,default:3e4}},required:[`code`]}},{name:`search_tools`,description:`Search and discover available MCP tools across all servers. Use this to find out what tools are available before writing code. Returns tool information including names, descriptions, and schemas. Can filter by query and control detail level.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search query to filter tools by name or description`,default:``},detail_level:{type:`string`,description:`Detail level: 'names', 'descriptions', or 'full'`,enum:[`names`,`descriptions`,`full`],default:`full`}}}}]}get tools(){return this._tools}async initialize(){return this.toolsCache=this._tools,{capabilities:{},version:`1.0.0`}}async callTool(e,t){if(e===`execute_code`){let e=t.code,n=t.timeout||3e4,r=await this.mcpClient.executeCode(e,n);return{content:[{type:`text`,text:JSON.stringify(r)}]}}else if(e===`search_tools`){let e=t.query||``,n=t.detail_level,r=await this.mcpClient.searchTools(e,n&&n in[`names`,`descriptions`,`full`]?n:`full`);return{content:[{type:`text`,text:JSON.stringify(r)}]}}throw Error(`Unknown tool: ${e}`)}};function D(t){let{readFileSync:n}=e(`fs`),r=n(t,`utf-8`);return JSON.parse(r)}t(D,`loadConfigFile`);function O(e){return`requestedSchema`in e&&e.requestedSchema!=null}t(O,`hasRequestedSchema`);function k(e){let t={};if(!O(e))return t;let n=e.requestedSchema.properties??{};for(let[e,r]of Object.entries(n)){let n=r;if(`default`in n){let r=n.default;(typeof r==`string`||typeof r==`number`||typeof r==`boolean`||Array.isArray(r)&&r.every(e=>typeof e==`string`))&&(t[e]=r)}}return t}t(k,`getDefaults`);function A(e,t){let n=k(e);return t==null?n:{...n,...t}}t(A,`applyDefaults`);function j(e){return{action:`accept`,content:k(e)}}t(j,`acceptWithDefaults`);function M(e){return{action:`accept`,content:e}}t(M,`accept`);function N(e){return{action:`decline`}}t(N,`decline`);function P(){return{action:`cancel`}}t(P,`cancel`);function F(e){return N(e)}t(F,`reject`);function I(e,t){if(!O(e))return{valid:!0};try{let n=f.convert(e.requestedSchema).safeParse(t);return n.success?{valid:!0}:{valid:!1,errors:n.error.issues.map(e=>e.path.length>0?`${e.path.join(`.`)}: ${e.message}`:e.message)}}catch{return{valid:!1,errors:[`Unsupported or invalid schema`]}}}t(I,`validate`);function L(e,t,r){let a=Object.keys(e.mcpServers??{}),o=!!(r.onSampling??r.samplingCallback),s=!!(r.onElicitation??r.elicitationCallback);i.getInstance().trackMCPClientInit({codeMode:t,sandbox:!1,allCallbacks:o&&s,verify:!1,servers:a,numServers:a.length,isBrowser:!1}).catch(e=>n.debug(`Failed to track MCPClient init: ${e}`))}t(L,`trackNodeClientInit`);var R=class e extends u{static{t(this,`MCPClient`)}static getPackageVersion(){return r()}codeMode=!1;_codeExecutor=null;_customCodeExecutor=null;_codeExecutorConfig=`vm`;_executorOptions;_globalCallbacks;constructor(e,t){e?super(typeof e==`string`?D(e):e):super();let n=!1,r=`vm`,i;t?.codeMode&&(typeof t.codeMode==`boolean`?n=t.codeMode:(n=t.codeMode.enabled,r=t.codeMode.executor??`vm`,i=t.codeMode.executorOptions)),this.codeMode=n,this._codeExecutorConfig=r,this._executorOptions=i;let a=this.config;this._globalCallbacks={onSampling:t?.onSampling??t?.samplingCallback??a?.onSampling??a?.samplingCallback,samplingCallback:t?.samplingCallback??a?.samplingCallback,onElicitation:t?.onElicitation??t?.elicitationCallback??a?.onElicitation??a?.elicitationCallback,elicitationCallback:t?.elicitationCallback??a?.elicitationCallback,onNotification:t?.onNotification??a?.onNotification},t?.samplingCallback&&!t?.onSampling&&console.warn(`[MCPClient] The "samplingCallback" option is deprecated. Use "onSampling" instead.`),t?.elicitationCallback&&!t?.onElicitation&&console.warn(`[MCPClient] The "elicitationCallback" option is deprecated. Use "onElicitation" instead.`),this.codeMode&&this._setupCodeModeConnector(),L(this.config,this.codeMode,this._globalCallbacks)}static fromDict(t,n){return new e(t,n)}static fromConfigFile(t,n){return new e(D(t),n)}saveConfig(e){let t=m.dirname(e);p.existsSync(t)||p.mkdirSync(t,{recursive:!0}),p.writeFileSync(e,JSON.stringify(this.config,null,2),`utf-8`)}async createConnectorFromConfig(e){let t=c(e,this._globalCallbacks),n={...e,clientInfo:e.clientInfo??this.config.clientInfo};if(`command`in n&&`args`in n){let{StdioConnector:e}=await d(async()=>{let{StdioConnector:e}=await import(`./stdio-
|
|
91
|
+
`;o=await new y.Script(n,{filename:`agent_code.js`}).runInNewContext(t,{timeout:r,displayErrors:!0})}catch(e){s=e.message||String(e),(e.code===`ERR_SCRIPT_EXECUTION_TIMEOUT`||e.message===`Script execution timed out.`||typeof s==`string`&&(s.includes(`timed out`)||s.includes(`timeout`)))&&(s=`Script execution timed out`),e.stack&&n.debug(`Code execution error stack: ${e.stack}`)}let c=(Date.now()-a)/1e3;return{result:o,logs:i,error:s,execution_time:c}}async _buildContext(e){let n=t((...t)=>{e.push(t.map(e=>typeof e==`object`?JSON.stringify(e,null,2):String(e)).join(` `))},`logHandler`),r={console:{log:n,error:t((...e)=>{n(`[ERROR]`,...e)},`error`),warn:t((...e)=>{n(`[WARN]`,...e)},`warn`),info:n,debug:n},Object,Array,String,Number,Boolean,Date,Math,JSON,RegExp,Map,Set,Promise,parseInt,parseFloat,isNaN,isFinite,encodeURI,decodeURI,encodeURIComponent,decodeURIComponent,setTimeout,clearTimeout,search_tools:this.createSearchToolsFunction(),__tool_namespaces:[]},i={},a=this.getToolNamespaces();for(let{serverName:e,tools:t,session:n}of a){let a={};for(let e of t){let t=e.name;a[t]=async e=>{let r=await n.connector.callTool(t,e||{});if(r.content&&r.content.length>0){let e=r.content[0];if(e.type===`text`)try{return JSON.parse(e.text)}catch{return e.text}return e}return r}}r[e]=a,i[e]=!0}return r.__tool_namespaces=Object.keys(i),y.createContext(r)}async cleanup(){}},E=class extends a{static{t(this,`CodeModeConnector`)}mcpClient;_tools;constructor(e){super(),this.mcpClient=e,this.connected=!0,this._tools=this._createToolsList()}async connect(){this.connected=!0}async disconnect(){this.connected=!1}get publicIdentifier(){return{name:`code_mode`,version:`1.0.0`}}_createToolsList(){return[{name:`execute_code`,description:`Execute JavaScript/TypeScript code with access to MCP tools. This is the PRIMARY way to interact with MCP servers in code mode. Write code that discovers tools using search_tools(), calls tools as async functions (e.g., await github.get_pull_request(...)), processes data efficiently, and returns results. Use 'await' for async operations and 'return' to return values. Available in code: search_tools(), __tool_namespaces, and server.tool_name() functions.`,inputSchema:{type:`object`,properties:{code:{type:`string`,description:`JavaScript/TypeScript code to execute. Use 'await' for async operations. Use 'return' to return a value. Available: search_tools(), server.tool_name(), __tool_namespaces`},timeout:{type:`number`,description:`Execution timeout in milliseconds`,default:3e4}},required:[`code`]}},{name:`search_tools`,description:`Search and discover available MCP tools across all servers. Use this to find out what tools are available before writing code. Returns tool information including names, descriptions, and schemas. Can filter by query and control detail level.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search query to filter tools by name or description`,default:``},detail_level:{type:`string`,description:`Detail level: 'names', 'descriptions', or 'full'`,enum:[`names`,`descriptions`,`full`],default:`full`}}}}]}get tools(){return this._tools}async initialize(){return this.toolsCache=this._tools,{capabilities:{},version:`1.0.0`}}async callTool(e,t){if(e===`execute_code`){let e=t.code,n=t.timeout||3e4,r=await this.mcpClient.executeCode(e,n);return{content:[{type:`text`,text:JSON.stringify(r)}]}}else if(e===`search_tools`){let e=t.query||``,n=t.detail_level,r=await this.mcpClient.searchTools(e,n&&n in[`names`,`descriptions`,`full`]?n:`full`);return{content:[{type:`text`,text:JSON.stringify(r)}]}}throw Error(`Unknown tool: ${e}`)}};function D(t){let{readFileSync:n}=e(`fs`),r=n(t,`utf-8`);return JSON.parse(r)}t(D,`loadConfigFile`);function O(e){return`requestedSchema`in e&&e.requestedSchema!=null}t(O,`hasRequestedSchema`);function k(e){let t={};if(!O(e))return t;let n=e.requestedSchema.properties??{};for(let[e,r]of Object.entries(n)){let n=r;if(`default`in n){let r=n.default;(typeof r==`string`||typeof r==`number`||typeof r==`boolean`||Array.isArray(r)&&r.every(e=>typeof e==`string`))&&(t[e]=r)}}return t}t(k,`getDefaults`);function A(e,t){let n=k(e);return t==null?n:{...n,...t}}t(A,`applyDefaults`);function j(e){return{action:`accept`,content:k(e)}}t(j,`acceptWithDefaults`);function M(e){return{action:`accept`,content:e}}t(M,`accept`);function N(e){return{action:`decline`}}t(N,`decline`);function P(){return{action:`cancel`}}t(P,`cancel`);function F(e){return N(e)}t(F,`reject`);function I(e,t){if(!O(e))return{valid:!0};try{let n=f.convert(e.requestedSchema).safeParse(t);return n.success?{valid:!0}:{valid:!1,errors:n.error.issues.map(e=>e.path.length>0?`${e.path.join(`.`)}: ${e.message}`:e.message)}}catch{return{valid:!1,errors:[`Unsupported or invalid schema`]}}}t(I,`validate`);function L(e,t,r){let a=Object.keys(e.mcpServers??{}),o=!!(r.onSampling??r.samplingCallback),s=!!(r.onElicitation??r.elicitationCallback);i.getInstance().trackMCPClientInit({codeMode:t,sandbox:!1,allCallbacks:o&&s,verify:!1,servers:a,numServers:a.length,isBrowser:!1}).catch(e=>n.debug(`Failed to track MCPClient init: ${e}`))}t(L,`trackNodeClientInit`);var R=class e extends u{static{t(this,`MCPClient`)}static getPackageVersion(){return r()}codeMode=!1;_codeExecutor=null;_customCodeExecutor=null;_codeExecutorConfig=`vm`;_executorOptions;_globalCallbacks;constructor(e,t){e?super(typeof e==`string`?D(e):e):super();let n=!1,r=`vm`,i;t?.codeMode&&(typeof t.codeMode==`boolean`?n=t.codeMode:(n=t.codeMode.enabled,r=t.codeMode.executor??`vm`,i=t.codeMode.executorOptions)),this.codeMode=n,this._codeExecutorConfig=r,this._executorOptions=i;let a=this.config;this._globalCallbacks={onSampling:t?.onSampling??t?.samplingCallback??a?.onSampling??a?.samplingCallback,samplingCallback:t?.samplingCallback??a?.samplingCallback,onElicitation:t?.onElicitation??t?.elicitationCallback??a?.onElicitation??a?.elicitationCallback,elicitationCallback:t?.elicitationCallback??a?.elicitationCallback,onNotification:t?.onNotification??a?.onNotification},t?.samplingCallback&&!t?.onSampling&&console.warn(`[MCPClient] The "samplingCallback" option is deprecated. Use "onSampling" instead.`),t?.elicitationCallback&&!t?.onElicitation&&console.warn(`[MCPClient] The "elicitationCallback" option is deprecated. Use "onElicitation" instead.`),this.codeMode&&this._setupCodeModeConnector(),L(this.config,this.codeMode,this._globalCallbacks)}static fromDict(t,n){return new e(t,n)}static fromConfigFile(t,n){return new e(D(t),n)}saveConfig(e){let t=m.dirname(e);p.existsSync(t)||p.mkdirSync(t,{recursive:!0}),p.writeFileSync(e,JSON.stringify(this.config,null,2),`utf-8`)}async createConnectorFromConfig(e){let t=c(e,this._globalCallbacks),n={...e,clientInfo:e.clientInfo??this.config.clientInfo};if(`command`in n&&`args`in n){let{StdioConnector:e}=await d(async()=>{let{StdioConnector:e}=await import(`./stdio-RWLH66ZO-C753VwJ7.js`);return{StdioConnector:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8])),r=n;return new e({command:r.command,args:r.args,env:r.env,clientInfo:o(n.clientInfo),onSampling:t.onSampling,onElicitation:t.onElicitation,onNotification:t.onNotification})}return s(n,{onSampling:t.onSampling,onElicitation:t.onElicitation,onNotification:t.onNotification})}_setupCodeModeConnector(){n.debug(`Code mode connector initialized as internal meta server`);let e=new l(new E(this));this.sessions.code_mode=e,this.activeSessions.push(`code_mode`)}_ensureCodeExecutor(){if(!this._codeExecutor){let e=this._codeExecutorConfig;if(e instanceof _)this._codeExecutor=e;else if(typeof e==`function`)throw this._customCodeExecutor=e,Error(`Custom executor function should be handled in executeCode`);else if(e===`e2b`){let e=this._executorOptions;if(e?.apiKey)this._codeExecutor=new v(this,e);else{n.warn(`E2B executor requires apiKey. Falling back to VM.`);try{this._codeExecutor=new T(this,this._executorOptions)}catch{throw Error(`VM executor is not available in this environment and E2B API key is not provided. Please provide an E2B API key or run in a Node.js environment.`)}}}else try{this._codeExecutor=new T(this,this._executorOptions)}catch{let e=this._executorOptions,t=e?.apiKey||{}.E2B_API_KEY;if(t)n.info(`VM executor not available in this environment. Falling back to E2B.`),this._codeExecutor=new v(this,{...e,apiKey:t});else throw Error(`VM executor is not available in this environment. Please provide an E2B API key via executorOptions or E2B_API_KEY environment variable, or run in a Node.js environment.`)}}return this._codeExecutor}async executeCode(e,t){if(!this.codeMode)throw Error(`Code execution mode is not enabled`);return this._customCodeExecutor?this._customCodeExecutor(e,t):this._ensureCodeExecutor().execute(e,t)}async searchTools(e=``,t=`full`){if(!this.codeMode)throw Error(`Code execution mode is not enabled`);return this._ensureCodeExecutor().createSearchToolsFunction()(e,t)}getServerNames(){let e=this.codeMode;return super.getServerNames().filter(t=>!e||t!==`code_mode`)}async close(){this._codeExecutor&&=(await this._codeExecutor.cleanup(),null),await this.closeAllSessions()}};export{R as MCPClient};
|