opencode-idea 0.0.17 → 0.0.19

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/src/mcp/idea.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // HTTP header `IJ_MCP_SERVER_PROJECT_PATH` (see `serverConfig`).
14
14
  // * Availability probe: a single `initialize` POST to `/stream` succeeds when
15
15
  // the MCP server is up. We do NOT check whether a specific project is open —
16
- // the user triggers `/open-in-idea` for the project they want, so "server is
16
+ // the user triggers `/open-in-ide` for the project they want, so "server is
17
17
  // up" is the only thing worth knowing.
18
18
 
19
19
  export const PROJECT_HEADER = 'IJ_MCP_SERVER_PROJECT_PATH';
@@ -37,29 +37,23 @@ export function ideProjectPath(projectPath) {
37
37
  return projectPath.replace(/\\/g, '/');
38
38
  }
39
39
 
40
- /** OpenCode MCP server name registered for the IDE. */
41
- export const IDEA_SERVER_NAME = 'idea';
42
-
43
40
  /** Streamable-HTTP endpoint exposed by the IDE MCP server (IntelliJ 2026.2+). */
44
41
  export const MCP_STREAM_PATH = '/stream';
45
42
 
46
- /** Port the IDE MCP server listens on when not configured explicitly. */
47
- export const DEFAULT_PORTS = [64342];
48
-
49
43
  const PROTOCOL_VERSION = '2025-06-18';
50
- // A probe is only a local availability check. Keep it short: a disabled IDE
51
- // MCP endpoint must not make the user wait for the launch timeout before the
52
- // actionable notification is sent.
53
- const PROBE_TIMEOUT_MS = 1000;
54
44
  const CALL_TIMEOUT_MS = 15000;
55
45
 
56
46
  /**
57
47
  * Build the OpenCode MCP server config for a given IDE port + project.
58
48
  *
59
49
  * `codemode: false` exposes the IDE tools directly on the provider tool list
60
- * (as `idea_<tool>`) instead of routing them through Code Mode. Direct exposure
61
- * passes each tool's full schema to the model, so parameter names are known
62
- * without exploration. The rest of an MCP server's options are unchanged.
50
+ * (as `<server>_<tool>`) instead of routing them through Code Mode. Direct
51
+ * exposure passes each tool's full schema to the model, so parameter names are
52
+ * known without exploration. The rest of an MCP server's options are unchanged.
53
+ *
54
+ * The server NAME is not decided here: it is the project's tool prefix, chosen
55
+ * by the caller (root -> `ide`, a subproject -> its directory name). See
56
+ * `ide-projects.js` for why the prefix encodes the LEVEL, not the IDE product.
63
57
  *
64
58
  * @param {number} port
65
59
  * @param {string} projectPath
@@ -95,66 +89,6 @@ function withExecutionTimeout(config, options) {
95
89
  }
96
90
 
97
91
 
98
- /**
99
- * Is an IDE MCP server listening on `port`? One Streamable-HTTP `initialize`
100
- * POST decides it: any 2xx JSON reply means the server is up.
101
- *
102
- * @param {number} port
103
- * @param {{ fetchImpl?: typeof fetch, timeoutMs?: number }} [options]
104
- * @returns {Promise<boolean>}
105
- */
106
- export async function probePort(port, options = {}) {
107
- const fetchImpl = options.fetchImpl ?? fetch;
108
- const controller = new AbortController();
109
- const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? PROBE_TIMEOUT_MS);
110
- try {
111
- const response = await fetchImpl(`http://127.0.0.1:${port}${MCP_STREAM_PATH}`, {
112
- method: 'POST',
113
- headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream' },
114
- // Do not follow redirects. IntelliJ can keep its normal HTTP port open
115
- // while MCP is disabled and redirect `/stream` to an HTML 404 page;
116
- // following that redirect only adds latency and still means unavailable.
117
- redirect: 'manual',
118
- body: JSON.stringify({
119
- jsonrpc: '2.0',
120
- id: 1,
121
- method: 'initialize',
122
- params: {
123
- protocolVersion: PROTOCOL_VERSION,
124
- capabilities: {},
125
- clientInfo: { name: 'opencode-idea', version: '0.0.17' },
126
- },
127
- }),
128
- signal: controller.signal,
129
- });
130
- return response.ok;
131
- } catch {
132
- return false;
133
- } finally {
134
- clearTimeout(timer);
135
- controller.abort();
136
- }
137
- }
138
-
139
- /**
140
- * Find the first port whose IDE MCP server responds. Returns the port, or
141
- * `undefined` when none is available.
142
- *
143
- * @param {number[]} ports
144
- * @param {{ fetchImpl?: typeof fetch, timeoutMs?: number }} [options]
145
- * @returns {Promise<number | undefined>}
146
- */
147
- export async function findIdePort(ports, options = {}) {
148
- // Probe all candidate ports concurrently. These are fallback locations for
149
- // one IDE MCP endpoint, not several active MCP servers. Sequential probes
150
- // multiply the timeout by the number of candidates and made a disabled MCP
151
- // look like a hang.
152
- const results = await Promise.all(
153
- ports.map(async (port) => [port, await probePort(port, options)]),
154
- );
155
- return results.find(([, available]) => available)?.[0];
156
- }
157
-
158
92
  /**
159
93
  * Call one MCP tool over the Streamable-HTTP endpoint. Returns the raw tool
160
94
  * result (with `isError`), or `undefined` on transport/connect failure.
@@ -193,7 +127,7 @@ export async function callTool(port, projectPath, name, args = {}, options = {})
193
127
  params: {
194
128
  protocolVersion: PROTOCOL_VERSION,
195
129
  capabilities: {},
196
- clientInfo: { name: 'opencode-idea', version: '0.0.17' },
130
+ clientInfo: { name: 'opencode-idea', version: '0.0.19' },
197
131
  },
198
132
  });
199
133
  // The IDE's Streamable-HTTP endpoint binds follow-up requests to the session