tg-agent 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/mcp.js +5 -5
  2. package/package.json +1 -1
package/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
- import R from"node:fs";import H from"node:fs/promises";import q from"node:path";import J from"node:readline";import{spawn as U}from"node:child_process";const G=6e4,A=2e5,Q=40,X=3500;let w=null,P=!1;const h=new Map,V=1500;function z(t){return q.join(t,"config.toml")}function dt(t){const e=z(t);try{const r=R.readFileSync(e,"utf8");return O(r)}catch{return[]}}async function Y(t){const e=z(t);try{const r=await H.readFile(e,"utf8");return O(r)}catch{return[]}}async function pt(t,e={}){if(w)return w;const r=await Y(t);if(r.length===0)return w="","";const n=e.maxTools??Q,s=e.maxChars??X,i=e.timeoutMs??4e3,o=e.maxBytes??A,a=["MCP catalog (auto-discovered):","Use tool 'mcp' with server=<name> method=<tool> params=<object>."];for(const u of r){const l=await K(u,{timeoutMs:i,maxBytes:o});if(a.push(`${u.name} (${u.type})`),l.length===0){a.push(" - tools unavailable");continue}const d=l.slice(0,n);for(const p of d){const y=p.description?`: ${p.description}`:"";a.push(` - ${p.name}${y}`)}l.length>d.length&&a.push(` - ...and ${l.length-d.length} more`)}let c=a.join(`
2
- `);return c.length>s&&(c=`${c.slice(0,s-20)}...
3
- (truncated)`),w=c,c}function mt(){w&&(P=!0)}function ht(){w=null,P=!1,h.clear()}function gt(t){if(t.type==="http")return t.url?`url=${t.url}`:"url=(missing)";const e=t.args&&t.args.length>0?` ${t.args.join(" ")}`:"";return t.command?`command=${t.command}${e}`:"command=(missing)"}async function yt(t,e=5e3){const r=Date.now();try{return await $(t,"tools/list",{},{timeoutMs:e}),{ok:!0,durationMs:Date.now()-r}}catch(n){const s=n instanceof Error?n.message:String(n);return{ok:!1,durationMs:Date.now()-r,error:s}}}async function $(t,e,r,n={}){const s=j(n.timeoutMs??G,1e3,12e4),i=j(n.maxBytes??A,1024,5e6),o=new AbortController,a=()=>o.abort();n.signal?.addEventListener("abort",a,{once:!0});const c=setTimeout(()=>o.abort(),s);try{return t.type==="http"?(e!=="initialize"&&e!=="notifications/initialized"&&await v(t,i,o.signal),await B(t,e,r,i,o.signal)):await nt(t,e,r,i,o.signal)}finally{clearTimeout(c),n.signal?.removeEventListener("abort",a)}}function j(t,e,r){return Number.isNaN(t)?e:Math.min(r,Math.max(e,t))}async function K(t,e){try{const r=await $(t,"tools/list",{},e);return Z(r.output)}catch(r){const n=r instanceof Error?r.message:String(r);return console.warn(`[tg-agent] mcp tools/list failed server=${t.name} error=${n}`),[]}}function Z(t){let e;try{e=JSON.parse(t)}catch{return[]}if(!e||typeof e!="object")return[];const r=e,s=(r.result??r).tools??r.tools;if(!Array.isArray(s))return[];const i=[];for(const o of s){if(!o||typeof o!="object")continue;const a=o,c=typeof a.name=="string"?a.name:"";if(!c)continue;const u=typeof a.description=="string"?a.description:void 0,l=a.inputSchema;i.push({name:c,description:u,inputSchema:l})}return i}async function B(t,e,r,n,s){if(!t.url)throw new Error("MCP server url is missing.");const i=Date.now(),o=await k(t,e,r,n,s),a=I(o.parsed);if(a)throw new Error(a);let c=o.bodyText;return o.parsed&&(c=JSON.stringify(o.parsed,null,2)),{ok:o.statusCode>=200&&o.statusCode<300,output:c,durationMs:Date.now()-i,bytes:o.bytes,truncated:o.truncated,statusCode:o.statusCode,statusText:o.statusText,contentType:o.contentType}}async function k(t,e,r,n,s){if(!t.url)throw new Error("MCP server url is missing.");const i=h.get(t.name),o={jsonrpc:"2.0",id:`tg-agent-${Date.now()}`,method:e,params:r??{}},a={"content-type":"application/json"};t.auth&&(a.authorization=t.auth.startsWith("Bearer ")?t.auth:`Bearer ${t.auth}`),i?.cookie&&(a.cookie=i.cookie),i?.sessionId&&(a["mcp-session-id"]=i.sessionId);const c=await fetch(t.url,{method:"POST",headers:a,body:JSON.stringify(o),signal:s});tt(t.name,c);const u=await ot(c,n,s);let l;try{l=JSON.parse(u.text)}catch{l=void 0}return et(t.name,l),{statusCode:c.status,statusText:c.statusText,contentType:c.headers.get("content-type"),bodyText:u.text,parsed:l,bytes:u.bytes,truncated:u.truncated}}function I(t){if(!t||typeof t!="object")return null;const e=t;if(e.error&&typeof e.error=="object"){const r=e.error;if(typeof r.message=="string")return r.message}return typeof e.error_description=="string"?e.error_description:typeof e.error=="string"?e.error:null}async function v(t,e,r){const n=h.get(t.name);if(n?.initializedAt)return;if(n?.inFlight){await n.inFlight;return}const s=(async()=>{const i=await k(t,"initialize",{protocolVersion:"2024-11-05",clientInfo:{name:"tg-agent",version:process.env.npm_package_version??"dev"},capabilities:{}},e,r),o=I(i.parsed);if(o){const u=o.toLowerCase();if(u.includes("method")&&u.includes("not"))return;throw new Error(o)}const a=new AbortController,c=setTimeout(()=>a.abort(),V);try{await k(t,"notifications/initialized",{},e,a.signal)}catch{}finally{clearTimeout(c)}})();h.set(t.name,{initializedAt:Date.now(),inFlight:s});try{await s;const i=h.get(t.name);h.set(t.name,{initializedAt:Date.now(),cookie:i?.cookie,sessionId:i?.sessionId})}catch(i){throw h.delete(t.name),i}}function tt(t,e){const n=h.get(t)??{initializedAt:0},s=e.headers.get("set-cookie"),i=e.headers.getSetCookie?.(),o=i&&i.length>0?i.join("; "):s;o&&h.set(t,{...n,cookie:o});const a=e.headers.get("mcp-session-id")??e.headers.get("x-mcp-session-id");a&&h.set(t,{...n,sessionId:a})}function et(t,e){if(!e||typeof e!="object")return;const n=e.result;if(!n)return;const s=typeof n.sessionId=="string"&&n.sessionId||typeof n.session_id=="string"&&n.session_id;if(!s)return;const i=h.get(t)??{initializedAt:0};h.set(t,{...i,sessionId:s})}async function nt(t,e,r,n,s){if(!t.command)throw new Error("MCP server command is missing.");const i=Date.now(),o=U(t.command,t.args??[],{stdio:["pipe","pipe","pipe"]}),a=()=>{o.killed||o.kill("SIGTERM")};if(s.aborted)throw a(),new Error("MCP request aborted.");const c=new Map;let u=!1,l="";const d=new Error("MCP request aborted."),p=J.createInterface({input:o.stdout,terminal:!1});p.on("line",f=>{if(f.length>n){u=!0;return}let m=null;try{m=JSON.parse(f)}catch{return}const g=typeof m.id=="string"?m.id:typeof m.id=="number"?String(m.id):"";if(!g)return;const x=c.get(g);x&&(c.delete(g),x.resolve(m))}),o.stderr?.on("data",f=>{const m=f.toString();if(l.length+m.length>n){u=!0;return}l+=m});const y=()=>{for(const f of c.values())f.reject(d);c.clear(),a()};s.addEventListener("abort",y,{once:!0});const b=f=>{const m=f===0?"MCP stdio exited.":l.trim()||"MCP stdio exited with error.";for(const g of c.values())g.reject(new Error(m));c.clear()};o.once("exit",f=>b(f));const _=async(f,m)=>{const g=`tg-agent-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,x={jsonrpc:"2.0",id:g,method:f,params:m??{}};return await new Promise((W,N)=>{c.set(g,{resolve:W,reject:N}),o.stdin?.write(`${JSON.stringify(x)}
4
- `)})},S=await _("initialize",{protocolVersion:"2024-11-05",clientInfo:{name:"tg-agent",version:process.env.npm_package_version??"dev"},capabilities:{}});if(S.error&&typeof S.error=="object"){const f=S.error.message??"MCP initialize failed.";throw a(),new Error(String(f))}const L={jsonrpc:"2.0",method:"notifications/initialized"};o.stdin?.write(`${JSON.stringify(L)}
5
- `);const T=await _(e,r);s.removeEventListener("abort",y),p.close(),o.stdin?.end(),a();const D=new Promise(f=>{o.once("exit",()=>f())});if(await Promise.race([D,new Promise(f=>setTimeout(f,500))]),T.error&&typeof T.error=="object"){const f=T.error.message??"MCP request failed.";throw new Error(String(f))}const M=JSON.stringify(T,null,2),F=M.length>n?M.slice(0,n):M;return M.length>n&&(u=!0),{ok:!0,output:F,durationMs:Date.now()-i,bytes:Math.min(M.length,n),truncated:u}}async function ot(t,e,r){const n=t.body?.getReader?.();if(!n){const d=await t.text(),p=Math.min(d.length,e);return{text:d.slice(0,e),bytes:p,truncated:d.length>e}}const s=new TextDecoder("utf-8"),i=[];let o=0,a=!1;for(;;){if(r.aborted){try{await n.cancel()}catch{}throw new Error("MCP request aborted.")}const{done:d,value:p}=await n.read();if(d)break;if(!p)continue;const y=o+p.byteLength;if(y>e){const b=Math.max(0,e-o);b>0&&(i.push(p.slice(0,b)),o+=b),a=!0;try{await n.cancel()}catch{}break}i.push(p),o=y}const c=new Uint8Array(o);let u=0;for(const d of i)c.set(d,u),u+=d.byteLength;return{text:s.decode(c),bytes:o,truncated:a}}function O(t){const e=[];let r=null,n={};const s=()=>{if(!r)return;const i=n.type??(n.url?"http":n.command?"stdio":void 0);if(!i)return;const o=i==="http"||i==="stdio"?i:void 0;o&&(o==="http"&&!n.url||o==="stdio"&&!n.command||e.push({name:r,type:o,url:n.url,command:n.command,args:n.args,auth:n.auth}))};for(const i of t.split(/\r?\n/)){const o=it(i).trim();if(!o)continue;if(o.startsWith("[")&&o.endsWith("]")){s();const l=o.slice(1,-1).trim();if(!l.startsWith("mcp_servers.")){r=null,n={};continue}let d=l.slice(12).trim();if(d=E(d),!d){r=null,n={};continue}r=d,n={};continue}if(!r)continue;const a=o.indexOf("=");if(a===-1)continue;const c=o.slice(0,a).trim(),u=o.slice(a+1).trim();if(c)switch(c){case"type":n.type=C(u).toLowerCase();break;case"url":n.url=C(u);break;case"command":n.command=C(u);break;case"args":n.args=rt(u);break;case"auth":case"authorization":case"token":n.auth=C(u);break;default:break}}return s(),e}function E(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function C(t){const e=t.trim();return e?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\"/g,'"'):e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e:""}function rt(t){const e=t.trim();if(!e.startsWith("[")||!e.endsWith("]"))return[];const r=e.slice(1,-1).trim();if(!r)return[];const n=[];let s="",i=!1,o="";for(let c=0;c<r.length;c+=1){const u=r[c];if(!i&&(u==='"'||u==="'")){i=!0,o=u;continue}if(i&&u===o){i=!1;continue}if(!i&&u===","){const l=s.trim();l&&n.push(E(l)),s="";continue}s+=u}const a=s.trim();return a&&n.push(E(a)),n}function it(t){let e=!1,r="";for(let n=0;n<t.length;n+=1){const s=t[n];if(!e&&(s==='"'||s==="'")){e=!0,r=s;continue}if(e&&s===r){e=!1;continue}if(!e&&(s==="#"||s===";"))return t.slice(0,n)}return t}export{$ as callMcpServer,gt as formatMcpTarget,mt as freezeMcpCatalog,pt as getMcpCatalog,z as getMcpConfigPath,Y as loadMcpServers,dt as loadMcpServersSync,yt as probeMcpServer,ht as refreshMcpCatalog};
1
+ import J from"node:fs";import R from"node:fs/promises";import W from"node:path";import q from"node:readline";import{spawn as H}from"node:child_process";import*as U from"@iarna/toml";const G=6e4,A=2e5,Q=40,X=3500;let w=null,_=!1;const m=new Map,V=1500;function I(t){return W.join(t,"config.toml")}function lt(t){const e=I(t);try{const r=J.readFileSync(e,"utf8");return O(r)}catch{return[]}}async function Y(t){const e=I(t);try{const r=await R.readFile(e,"utf8");return O(r)}catch{return[]}}async function ft(t,e={}){if(w)return w;const r=await Y(t);if(r.length===0)return w="","";const o=e.maxTools??Q,a=e.maxChars??X,i=e.timeoutMs??4e3,n=e.maxBytes??A,s=["MCP catalog (auto-discovered):","Use tool 'mcp' with server=<name> method=<tool> params=<object>."];for(const u of r){const l=await B(u,{timeoutMs:i,maxBytes:n});if(s.push(`${u.name} (${u.type})`),l.length===0){s.push(" - tools unavailable");continue}const d=l.slice(0,o);for(const p of d){const g=p.description?`: ${p.description}`:"";s.push(` - ${p.name}${g}`)}l.length>d.length&&s.push(` - ...and ${l.length-d.length} more`)}let c=s.join(`
2
+ `);return c.length>a&&(c=`${c.slice(0,a-20)}...
3
+ (truncated)`),w=c,c}function dt(){w&&(_=!0)}function pt(){w=null,_=!1,m.clear()}function ht(t){if(t.type==="http")return t.url?`url=${t.url}`:"url=(missing)";const e=t.args&&t.args.length>0?` ${t.args.join(" ")}`:"";return t.command?`command=${t.command}${e}`:"command=(missing)"}async function mt(t,e=5e3){const r=Date.now();try{return await P(t,"tools/list",{},{timeoutMs:e}),{ok:!0,durationMs:Date.now()-r}}catch(o){const a=o instanceof Error?o.message:String(o);return{ok:!1,durationMs:Date.now()-r,error:a}}}async function P(t,e,r,o={}){const a=k(o.timeoutMs??G,1e3,12e4),i=k(o.maxBytes??A,1024,5e6),n=new AbortController,s=()=>n.abort();o.signal?.addEventListener("abort",s,{once:!0});const c=setTimeout(()=>n.abort(),a);try{return t.type==="http"?(e!=="initialize"&&e!=="notifications/initialized"&&await v(t,i,n.signal),await Z(t,e,r,i,n.signal)):await nt(t,e,r,i,n.signal)}finally{clearTimeout(c),o.signal?.removeEventListener("abort",s)}}function k(t,e,r){return Number.isNaN(t)?e:Math.min(r,Math.max(e,t))}async function B(t,e){try{const r=await P(t,"tools/list",{},e);return K(r.output)}catch(r){const o=r instanceof Error?r.message:String(r);return console.warn(`[tg-agent] mcp tools/list failed server=${t.name} error=${o}`),[]}}function K(t){let e;try{e=JSON.parse(t)}catch{return[]}if(!e||typeof e!="object")return[];const r=e,a=(r.result??r).tools??r.tools;if(!Array.isArray(a))return[];const i=[];for(const n of a){if(!n||typeof n!="object")continue;const s=n,c=typeof s.name=="string"?s.name:"";if(!c)continue;const u=typeof s.description=="string"?s.description:void 0,l=s.inputSchema;i.push({name:c,description:u,inputSchema:l})}return i}async function Z(t,e,r,o,a){if(!t.url)throw new Error("MCP server url is missing.");const i=Date.now(),n=await x(t,e,r,o,a),s=j(n.parsed);if(s)throw new Error(s);let c=n.bodyText;return n.parsed&&(c=JSON.stringify(n.parsed,null,2)),{ok:n.statusCode>=200&&n.statusCode<300,output:c,durationMs:Date.now()-i,bytes:n.bytes,truncated:n.truncated,statusCode:n.statusCode,statusText:n.statusText,contentType:n.contentType}}async function x(t,e,r,o,a){if(!t.url)throw new Error("MCP server url is missing.");const i=m.get(t.name),n={jsonrpc:"2.0",id:`tg-agent-${Date.now()}`,method:e,params:r??{}},s={"content-type":"application/json"};t.auth&&(s.authorization=t.auth.startsWith("Bearer ")?t.auth:`Bearer ${t.auth}`),i?.cookie&&(s.cookie=i.cookie),i?.sessionId&&(s["mcp-session-id"]=i.sessionId);const c=await fetch(t.url,{method:"POST",headers:s,body:JSON.stringify(n),signal:a});tt(t.name,c);const u=await ot(c,o,a);let l;try{l=JSON.parse(u.text)}catch{l=void 0}return et(t.name,l),{statusCode:c.status,statusText:c.statusText,contentType:c.headers.get("content-type"),bodyText:u.text,parsed:l,bytes:u.bytes,truncated:u.truncated}}function j(t){if(!t||typeof t!="object")return null;const e=t;if(e.error&&typeof e.error=="object"){const r=e.error;if(typeof r.message=="string")return r.message}return typeof e.error_description=="string"?e.error_description:typeof e.error=="string"?e.error:null}async function v(t,e,r){const o=m.get(t.name);if(o?.initializedAt)return;if(o?.inFlight){await o.inFlight;return}const a=(async()=>{const i=await x(t,"initialize",{protocolVersion:"2024-11-05",clientInfo:{name:"tg-agent",version:process.env.npm_package_version??"dev"},capabilities:{}},e,r),n=j(i.parsed);if(n){const u=n.toLowerCase();if(u.includes("method")&&u.includes("not"))return;throw new Error(n)}const s=new AbortController,c=setTimeout(()=>s.abort(),V);try{await x(t,"notifications/initialized",{},e,s.signal)}catch{}finally{clearTimeout(c)}})();m.set(t.name,{initializedAt:Date.now(),inFlight:a});try{await a;const i=m.get(t.name);m.set(t.name,{initializedAt:Date.now(),cookie:i?.cookie,sessionId:i?.sessionId})}catch(i){throw m.delete(t.name),i}}function tt(t,e){const o=m.get(t)??{initializedAt:0},a=e.headers.get("set-cookie"),i=e.headers.getSetCookie?.(),n=i&&i.length>0?i.join("; "):a;n&&m.set(t,{...o,cookie:n});const s=e.headers.get("mcp-session-id")??e.headers.get("x-mcp-session-id");s&&m.set(t,{...o,sessionId:s})}function et(t,e){if(!e||typeof e!="object")return;const o=e.result;if(!o)return;const a=typeof o.sessionId=="string"&&o.sessionId||typeof o.session_id=="string"&&o.session_id;if(!a)return;const i=m.get(t)??{initializedAt:0};m.set(t,{...i,sessionId:a})}async function nt(t,e,r,o,a){if(!t.command)throw new Error("MCP server command is missing.");const i=Date.now(),n=H(t.command,t.args??[],{stdio:["pipe","pipe","pipe"]}),s=()=>{n.killed||n.kill("SIGTERM")};if(a.aborted)throw s(),new Error("MCP request aborted.");const c=new Map;let u=!1,l="";const d=new Error("MCP request aborted."),p=q.createInterface({input:n.stdout,terminal:!1});p.on("line",f=>{if(f.length>o){u=!0;return}let h=null;try{h=JSON.parse(f)}catch{return}const y=typeof h.id=="string"?h.id:typeof h.id=="number"?String(h.id):"";if(!y)return;const C=c.get(y);C&&(c.delete(y),C.resolve(h))}),n.stderr?.on("data",f=>{const h=f.toString();if(l.length+h.length>o){u=!0;return}l+=h});const g=()=>{for(const f of c.values())f.reject(d);c.clear(),s()};a.addEventListener("abort",g,{once:!0});const b=f=>{const h=f===0?"MCP stdio exited.":l.trim()||"MCP stdio exited with error.";for(const y of c.values())y.reject(new Error(h));c.clear()};n.once("exit",f=>b(f));const E=async(f,h)=>{const y=`tg-agent-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,C={jsonrpc:"2.0",id:y,method:f,params:h??{}};return await new Promise((F,N)=>{c.set(y,{resolve:F,reject:N}),n.stdin?.write(`${JSON.stringify(C)}
4
+ `)})};fetch("http://127.0.0.1:7243/ingest/9e452bb4-cc67-4519-89fa-8fb51d810231",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({location:"mcp.ts:callStdioMcp:beforeInit",message:"sending initialize request",data:{elapsed:Date.now()-i},timestamp:Date.now(),sessionId:"debug-session",hypothesisId:"B,C"})}).catch(()=>{});const T=await E("initialize",{protocolVersion:"2024-11-05",clientInfo:{name:"tg-agent",version:process.env.npm_package_version??"dev"},capabilities:{}});if(fetch("http://127.0.0.1:7243/ingest/9e452bb4-cc67-4519-89fa-8fb51d810231",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({location:"mcp.ts:callStdioMcp:afterInit",message:"initialize response received",data:{elapsed:Date.now()-i,hasError:!!T.error},timestamp:Date.now(),sessionId:"debug-session",hypothesisId:"B,C"})}).catch(()=>{}),T.error&&typeof T.error=="object"){const f=T.error.message??"MCP initialize failed.";throw s(),new Error(String(f))}const D={jsonrpc:"2.0",method:"notifications/initialized"};n.stdin?.write(`${JSON.stringify(D)}
5
+ `),fetch("http://127.0.0.1:7243/ingest/9e452bb4-cc67-4519-89fa-8fb51d810231",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({location:"mcp.ts:callStdioMcp:beforeMethod",message:"sending method request",data:{method:e,elapsed:Date.now()-i},timestamp:Date.now(),sessionId:"debug-session",hypothesisId:"C"})}).catch(()=>{});const S=await E(e,r);a.removeEventListener("abort",g),p.close(),n.stdin?.end(),s();const $=new Promise(f=>{n.once("exit",()=>f())});if(await Promise.race([$,new Promise(f=>setTimeout(f,500))]),S.error&&typeof S.error=="object"){const f=S.error.message??"MCP request failed.";throw new Error(String(f))}const M=JSON.stringify(S,null,2),L=M.length>o?M.slice(0,o):M;return M.length>o&&(u=!0),{ok:!0,output:L,durationMs:Date.now()-i,bytes:Math.min(M.length,o),truncated:u}}async function ot(t,e,r){const o=t.body?.getReader?.();if(!o){const d=await t.text(),p=Math.min(d.length,e);return{text:d.slice(0,e),bytes:p,truncated:d.length>e}}const a=new TextDecoder("utf-8"),i=[];let n=0,s=!1;for(;;){if(r.aborted){try{await o.cancel()}catch{}throw new Error("MCP request aborted.")}const{done:d,value:p}=await o.read();if(d)break;if(!p)continue;const g=n+p.byteLength;if(g>e){const b=Math.max(0,e-n);b>0&&(i.push(p.slice(0,b)),n+=b),s=!0;try{await o.cancel()}catch{}break}i.push(p),n=g}const c=new Uint8Array(n);let u=0;for(const d of i)c.set(d,u),u+=d.byteLength;return{text:a.decode(c),bytes:n,truncated:s}}function O(t){const e=[];let r;try{r=U.parse(t)}catch{return e}const o=r.mcp_servers;if(!o||typeof o!="object")return e;for(const[a,i]of Object.entries(o)){if(!i||typeof i!="object")continue;const n=i,s=typeof n.type=="string"?n.type.toLowerCase():void 0,c=typeof n.url=="string"?n.url:void 0,u=typeof n.command=="string"?n.command:void 0,l=s==="http"||s==="stdio"?s:c?"http":u?"stdio":void 0;if(!l||l==="http"&&!c||l==="stdio"&&!u)continue;let d;Array.isArray(n.args)&&(d=n.args.filter(g=>typeof g=="string").map(g=>g.trim()));const p=typeof n.auth=="string"?n.auth:typeof n.authorization=="string"?n.authorization:typeof n.token=="string"?n.token:void 0;e.push({name:a,type:l,url:c,command:u,args:d,auth:p})}return e}function z(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function gt(t){const e=t.trim();return e?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\"/g,'"'):e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e:""}function yt(t){const e=t.trim();if(!e.startsWith("[")||!e.endsWith("]"))return[];const r=e.slice(1,-1).trim();if(!r)return[];const o=[];let a="",i=!1,n="";for(let c=0;c<r.length;c+=1){const u=r[c];if(!i&&(u==='"'||u==="'")){i=!0,n=u;continue}if(i&&u===n){i=!1;continue}if(!i&&u===","){const l=a.trim();l&&o.push(z(l)),a="";continue}a+=u}const s=a.trim();return s&&o.push(z(s)),o}function wt(t){let e=!1,r="";for(let o=0;o<t.length;o+=1){const a=t[o];if(!e&&(a==='"'||a==="'")){e=!0,r=a;continue}if(e&&a===r){e=!1;continue}if(!e&&(a==="#"||a===";"))return t.slice(0,o)}return t}export{P as callMcpServer,ht as formatMcpTarget,dt as freezeMcpCatalog,ft as getMcpCatalog,I as getMcpConfigPath,Y as loadMcpServers,lt as loadMcpServersSync,mt as probeMcpServer,pt as refreshMcpCatalog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tg-agent",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Telegram Codex agent",
5
5
  "type": "module",
6
6
  "bin": {