opencode-toolbox 0.10.3 → 0.10.4

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/index.js +34 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -36280,21 +36280,21 @@ class LocalMCPClient {
36280
36280
  toolsCache;
36281
36281
  name;
36282
36282
  config;
36283
- constructor(config3) {
36283
+ transportFactory;
36284
+ constructor(config3, options) {
36284
36285
  this.transport = null;
36285
36286
  this.toolsCache = null;
36286
36287
  this.name = config3.name;
36287
36288
  this.config = config3;
36288
- this.client = new Client({
36289
- name: `opencode-toolbox-client-${this.name}`,
36290
- version: "0.1.0"
36291
- }, {});
36289
+ const clientFactory = options?.clientFactory ?? ((name) => new Client({ name: `opencode-toolbox-client-${name}`, version: "0.1.0" }, {}));
36290
+ this.transportFactory = options?.transportFactory ?? ((opts) => new StdioClientTransport(opts));
36291
+ this.client = clientFactory(this.name);
36292
36292
  }
36293
36293
  async connect() {
36294
36294
  if (!this.config.command || this.config.command.length === 0) {
36295
36295
  throw new Error(`Local MCP server ${this.name} has no command`);
36296
36296
  }
36297
- this.transport = new StdioClientTransport({
36297
+ this.transport = this.transportFactory({
36298
36298
  command: this.config.command[0],
36299
36299
  args: this.config.command.slice(1),
36300
36300
  env: {
@@ -38028,20 +38028,45 @@ class RemoteMCPClient {
38028
38028
  name;
38029
38029
  config;
38030
38030
  transportType;
38031
- constructor(config3) {
38031
+ options;
38032
+ constructor(config3, options) {
38032
38033
  this.transport = null;
38033
38034
  this.toolsCache = null;
38034
38035
  this.name = config3.name;
38035
38036
  this.config = config3;
38036
38037
  this.transportType = null;
38038
+ this.options = options ?? {};
38037
38039
  this.client = this.createClient();
38038
38040
  }
38039
38041
  createClient() {
38042
+ if (this.options.clientFactory) {
38043
+ return this.options.clientFactory(this.name);
38044
+ }
38040
38045
  return new Client({
38041
38046
  name: `opencode-toolbox-client-${this.name}`,
38042
38047
  version: "0.1.0"
38043
38048
  }, {});
38044
38049
  }
38050
+ createStreamableTransport(url3) {
38051
+ if (this.options.streamableTransportFactory) {
38052
+ return this.options.streamableTransportFactory(url3, this.config.headers);
38053
+ }
38054
+ return new StreamableHTTPClientTransport(url3, {
38055
+ requestInit: {
38056
+ headers: this.config.headers
38057
+ }
38058
+ });
38059
+ }
38060
+ createSSETransport(url3, headers) {
38061
+ if (this.options.sseTransportFactory) {
38062
+ return this.options.sseTransportFactory(url3, headers);
38063
+ }
38064
+ return new SSEClientTransport(url3, {
38065
+ requestInit: {
38066
+ headers
38067
+ }
38068
+ });
38069
+ }
38045
38070
  async connect() {
38046
38071
  if (!this.config.url) {
38047
38072
  throw new Error(`Remote MCP server ${this.name} has no URL`);
@@ -38050,11 +38075,7 @@ class RemoteMCPClient {
38050
38075
  this.transportType = null;
38051
38076
  let streamableTransport = null;
38052
38077
  try {
38053
- streamableTransport = new StreamableHTTPClientTransport(url3, {
38054
- requestInit: {
38055
- headers: this.config.headers
38056
- }
38057
- });
38078
+ streamableTransport = this.createStreamableTransport(url3);
38058
38079
  await this.client.connect(streamableTransport);
38059
38080
  this.transport = streamableTransport;
38060
38081
  this.transportType = "streamable-http";
@@ -38071,11 +38092,7 @@ class RemoteMCPClient {
38071
38092
  Accept: "text/event-stream",
38072
38093
  ...this.config.headers
38073
38094
  };
38074
- sseTransport = new SSEClientTransport(url3, {
38075
- requestInit: {
38076
- headers: sseHeaders
38077
- }
38078
- });
38095
+ sseTransport = this.createSSETransport(url3, sseHeaders);
38079
38096
  await this.client.connect(sseTransport);
38080
38097
  this.transport = sseTransport;
38081
38098
  this.transportType = "sse";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-toolbox",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "Tool Search Tool Plugin for OpenCode - search and execute tools from MCP servers on-demand",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",