opencode-mcp-server 0.1.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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +484 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +528 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-02-22
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release with full OpenCode API support
|
|
12
|
+
- Support for `opencode_chat` - send programming tasks
|
|
13
|
+
- Support for `opencode_create_session` - create new sessions
|
|
14
|
+
- Support for `opencode_list_sessions` - list all sessions
|
|
15
|
+
- Support for `opencode_get_session` - get session details
|
|
16
|
+
- Support for `opencode_get_messages` - get session messages
|
|
17
|
+
- Support for `opencode_check_health` - health check
|
|
18
|
+
- Dual transport mode: Stdio and SSE
|
|
19
|
+
- Multiple authentication methods: Bearer, Basic, None
|
|
20
|
+
- Per-request configuration override
|
|
21
|
+
- TypeScript implementation with full type safety
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
- Environment variable configuration with `.env` file support
|
|
25
|
+
- Runtime parameter override for each tool call
|
|
26
|
+
- Custom URL support for multi-server management
|
|
27
|
+
- Comprehensive error handling and reporting
|
|
28
|
+
- English-only codebase for international accessibility
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenCode MCP Server Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
# OpenCode MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that enables remote interaction with [OpenCode](https://opencode.ai) via HTTP API. This allows MCP clients like OpenClaw, Claude Desktop, or any MCP-compatible tool to control OpenCode agents remotely.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **🔧 Flexible Configuration**: Environment variable defaults with per-request overrides
|
|
8
|
+
- **🔐 Multiple Authentication**: Bearer Token, Basic Auth (username/password), or no auth
|
|
9
|
+
- **🌐 Custom URL Support**: Each tool call can target different OpenCode servers
|
|
10
|
+
- **📡 Dual Mode**: Stdio (local) / SSE (remote) transports
|
|
11
|
+
- **🏥 Health Check**: Built-in connectivity testing
|
|
12
|
+
|
|
13
|
+
## 📋 Prerequisites
|
|
14
|
+
|
|
15
|
+
- Node.js 18+
|
|
16
|
+
- OpenCode running in server mode (`opencode serve`)
|
|
17
|
+
|
|
18
|
+
## 🛠️ Installation
|
|
19
|
+
|
|
20
|
+
### Option 1: Install from npm (Recommended)
|
|
21
|
+
|
|
22
|
+
The easiest way to install is via npm:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install globally
|
|
26
|
+
npm install -g opencode-mcp-server
|
|
27
|
+
|
|
28
|
+
# Or use with npx (no installation required)
|
|
29
|
+
npx opencode-mcp-server
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then configure in OpenClaw:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"opencode-remote": {
|
|
38
|
+
"command": "npx",
|
|
39
|
+
"args": ["-y", "opencode-mcp-server"],
|
|
40
|
+
"env": {
|
|
41
|
+
"OPENCODE_URL": "http://127.0.0.1:4096",
|
|
42
|
+
"OPENCODE_USERNAME": "opencode", // optional, default is "opencode"
|
|
43
|
+
"OPENCODE_PASSWORD": "your-password", // optional, default is empty
|
|
44
|
+
"OPENCODE_AUTH_TYPE": "basic" // optional, default is "basic"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Option 2: Quick Setup via OpenClaw (Recommended for OpenClaw Users)
|
|
52
|
+
|
|
53
|
+
Copy and paste the following instructions to your OpenClaw agent to automatically configure this MCP server:
|
|
54
|
+
|
|
55
|
+
> Please help me set up the OpenCode MCP Server in OpenClaw. Follow these steps:
|
|
56
|
+
>
|
|
57
|
+
> **Step 1: Clone the repository**
|
|
58
|
+
>
|
|
59
|
+
> ```bash
|
|
60
|
+
> git clone https://github.com/shiquda/opencode-mcp-server.git ~/.openclaw/mcp-servers/opencode-mcp-server
|
|
61
|
+
> ```
|
|
62
|
+
>
|
|
63
|
+
> **Step 2: Install dependencies and build**
|
|
64
|
+
>
|
|
65
|
+
> ```bash
|
|
66
|
+
> cd ~/.openclaw/mcp-servers/opencode-mcp-server && npm install && npm run build
|
|
67
|
+
> ```
|
|
68
|
+
>
|
|
69
|
+
> **Step 3: Add to MCP configuration**
|
|
70
|
+
> Add the following to `~/.openclaw/config/mcporter.json` (replace `YOUR_OPENCODE_PASSWORD` with your OpenCode password):
|
|
71
|
+
>
|
|
72
|
+
> ```json
|
|
73
|
+
> {
|
|
74
|
+
> "mcpServers": {
|
|
75
|
+
> "opencode-remote": {
|
|
76
|
+
> "command": "node",
|
|
77
|
+
> "args": [
|
|
78
|
+
> "/home/USERNAME/.openclaw/mcp-servers/opencode-mcp-server/dist/index.js",
|
|
79
|
+
> "stdio"
|
|
80
|
+
> ],
|
|
81
|
+
> "env": {
|
|
82
|
+
> "OPENCODE_URL": "http://127.0.0.1:4096",
|
|
83
|
+
> "OPENCODE_USERNAME": "opencode",
|
|
84
|
+
> "OPENCODE_PASSWORD": "YOUR_OPENCODE_PASSWORD",
|
|
85
|
+
> "OPENCODE_AUTH_TYPE": "basic"
|
|
86
|
+
> }
|
|
87
|
+
> }
|
|
88
|
+
> }
|
|
89
|
+
> }
|
|
90
|
+
> ```
|
|
91
|
+
>
|
|
92
|
+
> Note: Replace `USERNAME` with your actual Linux username (use `whoami` to check).
|
|
93
|
+
>
|
|
94
|
+
> **Step 4: Test the connection**
|
|
95
|
+
> After configuration, call the `opencode_check_health` tool to test if the connection works.
|
|
96
|
+
>
|
|
97
|
+
> For remote OpenCode server (via Tailscale), use the Tailscale IP instead:
|
|
98
|
+
>
|
|
99
|
+
> ```json
|
|
100
|
+
> "OPENCODE_URL": "http://100.x.x.x:4096"
|
|
101
|
+
> ```
|
|
102
|
+
|
|
103
|
+
### Option 2: Manual Installation
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Clone the repository
|
|
107
|
+
git clone https://github.com/yourusername/opencode-mcp-server.git
|
|
108
|
+
cd opencode-mcp-server
|
|
109
|
+
|
|
110
|
+
# Install dependencies
|
|
111
|
+
npm install
|
|
112
|
+
|
|
113
|
+
# Build the project
|
|
114
|
+
npm run build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## ⚙️ Configuration
|
|
118
|
+
|
|
119
|
+
Create a `.env` file:
|
|
120
|
+
|
|
121
|
+
```env
|
|
122
|
+
# OpenCode server URL (default: local)
|
|
123
|
+
OPENCODE_URL=http://127.0.0.1:4096
|
|
124
|
+
|
|
125
|
+
# Authentication type: basic | bearer | none
|
|
126
|
+
OPENCODE_AUTH_TYPE=basic
|
|
127
|
+
|
|
128
|
+
# For Basic Auth (default for opencode serve)
|
|
129
|
+
OPENCODE_USERNAME=opencode
|
|
130
|
+
OPENCODE_PASSWORD=your-password
|
|
131
|
+
|
|
132
|
+
# For Bearer Token Auth (if configured)
|
|
133
|
+
# OPENCODE_AUTH_TYPE=bearer
|
|
134
|
+
# OPENCODE_TOKEN=your-token-here
|
|
135
|
+
|
|
136
|
+
# MCP Server port (for SSE mode)
|
|
137
|
+
PORT=3000
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 🌐 Remote Access Setup
|
|
141
|
+
|
|
142
|
+
To access your OpenCode server remotely, you can use one of these methods:
|
|
143
|
+
|
|
144
|
+
### Method 1: Tailscale (Recommended)
|
|
145
|
+
|
|
146
|
+
[Tailscale](https://tailscale.com) creates a secure mesh network between your devices.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Install Tailscale on both machines
|
|
150
|
+
curl -fsSL https://tailscale.com/install.sh | sh
|
|
151
|
+
|
|
152
|
+
# Start Tailscale
|
|
153
|
+
sudo tailscale up
|
|
154
|
+
|
|
155
|
+
# Get your Tailscale IP
|
|
156
|
+
tailscale ip -4
|
|
157
|
+
# Example: 100.x.x.x
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Then configure with Tailscale IP:
|
|
161
|
+
|
|
162
|
+
```env
|
|
163
|
+
OPENCODE_URL=http://100.x.x.x:4096
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Method 2: ngrok
|
|
167
|
+
|
|
168
|
+
[ngrok](https://ngrok.com) exposes local servers to the internet.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Install ngrok
|
|
172
|
+
# https://ngrok.com/download
|
|
173
|
+
|
|
174
|
+
# Expose your OpenCode server
|
|
175
|
+
ngrok http 4096
|
|
176
|
+
|
|
177
|
+
# Use the provided https URL
|
|
178
|
+
OPENCODE_URL=https://xxxx.ngrok-free.app
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Method 3: frp
|
|
182
|
+
|
|
183
|
+
[frp](https://github.com/fatedier/frp) is a fast reverse proxy for NAT traversal.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Run frpc on your local machine (where OpenCode runs)
|
|
187
|
+
./frpc -c frpc.ini
|
|
188
|
+
|
|
189
|
+
# Use your VPS IP in configuration
|
|
190
|
+
OPENCODE_URL=http://your-vps-ip:4096
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 🏃 Usage
|
|
194
|
+
|
|
195
|
+
### Stdio Mode (for Claude Desktop, local clients)
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npm start
|
|
199
|
+
# or
|
|
200
|
+
node dist/index.js stdio
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### SSE Mode (for OpenClaw, remote clients)
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
node dist/index.js sse
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Server will start at `http://localhost:3000`.
|
|
210
|
+
|
|
211
|
+
## 🔌 MCP Configuration
|
|
212
|
+
|
|
213
|
+
### OpenClaw
|
|
214
|
+
|
|
215
|
+
OpenClaw uses `~/.openclaw/config/mcporter.json` for MCP server configuration.
|
|
216
|
+
|
|
217
|
+
**Configuration format:**
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"mcpServers": {
|
|
222
|
+
"opencode-remote": {
|
|
223
|
+
"command": "node",
|
|
224
|
+
"args": ["/home/USERNAME/.openclaw/mcp-servers/opencode-mcp-server/dist/index.js", "stdio"],
|
|
225
|
+
"env": {
|
|
226
|
+
"OPENCODE_URL": "http://127.0.0.1:4096",
|
|
227
|
+
"OPENCODE_USERNAME": "opencode",
|
|
228
|
+
"OPENCODE_PASSWORD": "your-password",
|
|
229
|
+
"OPENCODE_AUTH_TYPE": "basic"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Security Best Practices:**
|
|
237
|
+
|
|
238
|
+
- Use absolute paths in `args` (avoid `$HOME` or `~`)
|
|
239
|
+
- Store sensitive credentials in environment variables
|
|
240
|
+
- Use `127.0.0.1` for local servers, Tailscale IP for remote
|
|
241
|
+
- Never commit passwords to version control
|
|
242
|
+
|
|
243
|
+
### Remote Server Example (using Tailscale)
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"mcpServers": {
|
|
248
|
+
"opencode-remote": {
|
|
249
|
+
"command": "node",
|
|
250
|
+
"args": ["/home/USERNAME/.openclaw/mcp-servers/opencode-mcp-server/dist/index.js", "stdio"],
|
|
251
|
+
"env": {
|
|
252
|
+
"OPENCODE_URL": "http://100.72.207.100:4096",
|
|
253
|
+
"OPENCODE_USERNAME": "opencode",
|
|
254
|
+
"OPENCODE_PASSWORD": "your-password",
|
|
255
|
+
"OPENCODE_AUTH_TYPE": "basic"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## 🛠️ Available Tools
|
|
265
|
+
|
|
266
|
+
### 1. `opencode_chat`
|
|
267
|
+
|
|
268
|
+
Send a programming task to OpenCode Agent. Automatically creates a new session if no `session_id` is provided.
|
|
269
|
+
|
|
270
|
+
**Parameters:**
|
|
271
|
+
- `message` (required): Task description
|
|
272
|
+
- `session_id` (optional): Session ID for context continuity
|
|
273
|
+
- `directory` (optional): Working directory
|
|
274
|
+
- `url`, `username`, `password`, `auth_type` (optional): Override default connection settings
|
|
275
|
+
|
|
276
|
+
**Example:**
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"name": "opencode_chat",
|
|
280
|
+
"arguments": {
|
|
281
|
+
"message": "Write a Python script to scrape web page titles"
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### 2. `opencode_create_session`
|
|
287
|
+
|
|
288
|
+
Create a new OpenCode session.
|
|
289
|
+
|
|
290
|
+
**Parameters:**
|
|
291
|
+
|
|
292
|
+
- `title` (optional): Session title
|
|
293
|
+
- `directory` (optional): Working directory
|
|
294
|
+
- `url`, `username`, `password`, `auth_type` (optional): Connection settings
|
|
295
|
+
|
|
296
|
+
### 3. `opencode_list_sessions`
|
|
297
|
+
|
|
298
|
+
List all OpenCode sessions.
|
|
299
|
+
|
|
300
|
+
**Parameters:**
|
|
301
|
+
|
|
302
|
+
- `directory` (optional): Filter by directory
|
|
303
|
+
- `limit` (optional): Maximum results
|
|
304
|
+
- Connection settings (optional)
|
|
305
|
+
|
|
306
|
+
### 4. `opencode_get_session`
|
|
307
|
+
|
|
308
|
+
Get detailed information about a specific session.
|
|
309
|
+
|
|
310
|
+
**Parameters:**
|
|
311
|
+
|
|
312
|
+
- `session_id` (required): Session ID
|
|
313
|
+
- Connection settings (optional)
|
|
314
|
+
|
|
315
|
+
### 5. `opencode_get_messages`
|
|
316
|
+
|
|
317
|
+
Get message list from a session.
|
|
318
|
+
|
|
319
|
+
**Parameters:**
|
|
320
|
+
|
|
321
|
+
- `session_id` (required): Session ID
|
|
322
|
+
- `limit` (optional): Maximum messages
|
|
323
|
+
- Connection settings (optional)
|
|
324
|
+
|
|
325
|
+
### 6. `opencode_check_health`
|
|
326
|
+
|
|
327
|
+
Check OpenCode server connectivity.
|
|
328
|
+
|
|
329
|
+
**Parameters:**
|
|
330
|
+
|
|
331
|
+
- `url` (optional): Server URL to check
|
|
332
|
+
- Other auth parameters (optional)
|
|
333
|
+
|
|
334
|
+
## 💡 Usage Examples
|
|
335
|
+
|
|
336
|
+
### Example 1: Local Development (127.0.0.1)
|
|
337
|
+
|
|
338
|
+
For local development with OpenCode running on the same machine:
|
|
339
|
+
|
|
340
|
+
```json
|
|
341
|
+
{
|
|
342
|
+
"name": "opencode_chat",
|
|
343
|
+
"arguments": {
|
|
344
|
+
"message": "Help me create a login function",
|
|
345
|
+
"url": "http://127.0.0.1:4096"
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Example 2: Connect via Tailscale
|
|
351
|
+
|
|
352
|
+
When your OpenCode server is on another machine in your Tailscale network:
|
|
353
|
+
|
|
354
|
+
```json
|
|
355
|
+
{
|
|
356
|
+
"name": "opencode_chat",
|
|
357
|
+
"arguments": {
|
|
358
|
+
"message": "Write me a web scraper",
|
|
359
|
+
"url": "http://100.72.207.100:4096"
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Example 3: Using Username/Password Authentication
|
|
365
|
+
|
|
366
|
+
```json
|
|
367
|
+
{
|
|
368
|
+
"auth_type": "basic",
|
|
369
|
+
"username": "opencode",
|
|
370
|
+
"password": "your-password"
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Example 4: Multi-Server Management
|
|
375
|
+
|
|
376
|
+
Manage multiple OpenCode instances across different machines:
|
|
377
|
+
|
|
378
|
+
```json
|
|
379
|
+
{
|
|
380
|
+
"name": "opencode_list_sessions",
|
|
381
|
+
"arguments": {
|
|
382
|
+
"url": "http://100.72.207.100:4096"
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## 🔐 Authentication Details
|
|
388
|
+
|
|
389
|
+
### Bearer Token (Recommended for token-based auth)
|
|
390
|
+
|
|
391
|
+
```env
|
|
392
|
+
OPENCODE_AUTH_TYPE=bearer
|
|
393
|
+
OPENCODE_TOKEN=your-token-here
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Request header:
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
Authorization: Bearer your-token-here
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Basic Auth (Default for `opencode serve`)
|
|
403
|
+
|
|
404
|
+
```env
|
|
405
|
+
OPENCODE_AUTH_TYPE=basic
|
|
406
|
+
OPENCODE_USERNAME=opencode
|
|
407
|
+
OPENCODE_PASSWORD=secret123
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Request header:
|
|
411
|
+
|
|
412
|
+
```
|
|
413
|
+
Authorization: Basic b3BlbmNvZGU6c2VjcmV0MTIz
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### No Authentication
|
|
417
|
+
|
|
418
|
+
```env
|
|
419
|
+
OPENCODE_AUTH_TYPE=none
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
No auth header sent.
|
|
423
|
+
|
|
424
|
+
## 🏥 Health Check
|
|
425
|
+
|
|
426
|
+
After starting the MCP Server, you can check:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
curl http://127.0.0.1:3000/health
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Response:
|
|
433
|
+
|
|
434
|
+
```json
|
|
435
|
+
{
|
|
436
|
+
"status": "ok",
|
|
437
|
+
"version": "0.1.0",
|
|
438
|
+
"defaultEndpoint": "http://127.0.0.1:4096",
|
|
439
|
+
"authType": "basic"
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## 🔧 Advanced Configuration
|
|
444
|
+
|
|
445
|
+
### Command Line Arguments
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
# Stdio mode (default)
|
|
449
|
+
node dist/index.js
|
|
450
|
+
|
|
451
|
+
# SSE mode
|
|
452
|
+
node dist/index.js sse
|
|
453
|
+
|
|
454
|
+
# View help
|
|
455
|
+
node dist/index.js --help
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Environment Variable Priority
|
|
459
|
+
|
|
460
|
+
1. Tool call parameters (highest priority)
|
|
461
|
+
2. Environment variables (`.env` file)
|
|
462
|
+
3. Built-in defaults (lowest priority)
|
|
463
|
+
|
|
464
|
+
## 📝 License
|
|
465
|
+
|
|
466
|
+
MIT
|
|
467
|
+
|
|
468
|
+
## 🤝 Contributing
|
|
469
|
+
|
|
470
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
471
|
+
|
|
472
|
+
## 🔗 Links
|
|
473
|
+
|
|
474
|
+
- [OpenCode](https://opencode.ai)
|
|
475
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
476
|
+
- [MCP SDK TypeScript](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
477
|
+
- [Tailscale](https://tailscale.com) - Secure networking
|
|
478
|
+
- [ngrok](https://ngrok.com) - Tunneling
|
|
479
|
+
- [frp](https://github.com/fatedier/frp) - Fast reverse proxy
|
|
480
|
+
|
|
481
|
+
## 🙏 Acknowledgments
|
|
482
|
+
|
|
483
|
+
- Built with [MCP SDK](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
484
|
+
- Inspired by the need to bridge OpenClaw and OpenCode workflows
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
5
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import express from "express";
|
|
7
|
+
import cors from "cors";
|
|
8
|
+
import fetch from "node-fetch";
|
|
9
|
+
import * as dotenv from "dotenv";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import { dirname, join } from "path";
|
|
12
|
+
// Load environment variables
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
dotenv.config({ path: join(__dirname, "../.env") });
|
|
16
|
+
// Default configuration (loaded from environment variables)
|
|
17
|
+
const DEFAULT_CONFIG = {
|
|
18
|
+
url: process.env.OPENCODE_URL || "http://127.0.0.1:4096",
|
|
19
|
+
username: process.env.OPENCODE_USERNAME || "opencode",
|
|
20
|
+
password: process.env.OPENCODE_PASSWORD || "",
|
|
21
|
+
token: process.env.OPENCODE_TOKEN || "",
|
|
22
|
+
authType: process.env.OPENCODE_AUTH_TYPE || "basic", // OpenCode uses basic auth by default
|
|
23
|
+
};
|
|
24
|
+
const PORT = parseInt(process.env.PORT || "3000");
|
|
25
|
+
// Generate authentication headers
|
|
26
|
+
function getAuthHeader(config) {
|
|
27
|
+
const headers = {};
|
|
28
|
+
switch (config.authType) {
|
|
29
|
+
case "bearer":
|
|
30
|
+
if (config.token) {
|
|
31
|
+
headers["Authorization"] = `Bearer ${config.token}`;
|
|
32
|
+
}
|
|
33
|
+
else if (config.password) {
|
|
34
|
+
headers["Authorization"] = `Bearer ${config.password}`;
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case "basic":
|
|
38
|
+
// OpenCode uses basic auth, username is "opencode", password is the one set during serve
|
|
39
|
+
const user = config.username || "opencode";
|
|
40
|
+
const pass = config.password;
|
|
41
|
+
if (pass) {
|
|
42
|
+
const credentials = Buffer.from(`${user}:${pass}`).toString("base64");
|
|
43
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case "none":
|
|
47
|
+
default:
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return headers;
|
|
51
|
+
}
|
|
52
|
+
// Define tools
|
|
53
|
+
const TOOLS = [
|
|
54
|
+
{
|
|
55
|
+
name: "opencode_chat",
|
|
56
|
+
description: "Send a message to OpenCode Agent to execute programming tasks. Creates a new session if no session_id is provided, then sends the message.",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
message: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "Message/task description to send to OpenCode (required)",
|
|
63
|
+
},
|
|
64
|
+
session_id: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "Optional session ID. If not provided, a new session will be created automatically",
|
|
67
|
+
},
|
|
68
|
+
directory: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Working directory (optional, for specifying project path)",
|
|
71
|
+
},
|
|
72
|
+
url: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
75
|
+
},
|
|
76
|
+
username: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: "Username (optional, default: opencode)",
|
|
79
|
+
},
|
|
80
|
+
password: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Password (optional, loaded from environment variable)",
|
|
83
|
+
},
|
|
84
|
+
auth_type: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Authentication type: basic | bearer | none (optional, default: basic)",
|
|
87
|
+
enum: ["basic", "bearer", "none"],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ["message"],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "opencode_create_session",
|
|
95
|
+
description: "Create a new OpenCode session",
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: "object",
|
|
98
|
+
properties: {
|
|
99
|
+
title: {
|
|
100
|
+
type: "string",
|
|
101
|
+
description: "Session title (optional)",
|
|
102
|
+
},
|
|
103
|
+
directory: {
|
|
104
|
+
type: "string",
|
|
105
|
+
description: "Working directory (optional)",
|
|
106
|
+
},
|
|
107
|
+
url: {
|
|
108
|
+
type: "string",
|
|
109
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
110
|
+
},
|
|
111
|
+
username: {
|
|
112
|
+
type: "string",
|
|
113
|
+
description: "Username (optional)",
|
|
114
|
+
},
|
|
115
|
+
password: {
|
|
116
|
+
type: "string",
|
|
117
|
+
description: "Password (optional)",
|
|
118
|
+
},
|
|
119
|
+
auth_type: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description: "Authentication type (optional, default: basic)",
|
|
122
|
+
enum: ["basic", "bearer", "none"],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "opencode_list_sessions",
|
|
129
|
+
description: 'List all OpenCode sessions. By default, filters out subagent sessions (those containing "subagent" in the title).',
|
|
130
|
+
inputSchema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {
|
|
133
|
+
directory: {
|
|
134
|
+
type: "string",
|
|
135
|
+
description: "Filter by directory (optional)",
|
|
136
|
+
},
|
|
137
|
+
limit: {
|
|
138
|
+
type: "number",
|
|
139
|
+
description: "Maximum number of results (optional)",
|
|
140
|
+
},
|
|
141
|
+
include_subagents: {
|
|
142
|
+
type: "boolean",
|
|
143
|
+
description: "Whether to include subagent sessions (default: false)",
|
|
144
|
+
},
|
|
145
|
+
url: {
|
|
146
|
+
type: "string",
|
|
147
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
148
|
+
},
|
|
149
|
+
username: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "Username (optional)",
|
|
152
|
+
},
|
|
153
|
+
password: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "Password (optional)",
|
|
156
|
+
},
|
|
157
|
+
auth_type: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Authentication type (optional, default: basic)",
|
|
160
|
+
enum: ["basic", "bearer", "none"],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "opencode_get_session",
|
|
167
|
+
description: "Get detailed information about a specific session",
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: {
|
|
171
|
+
session_id: {
|
|
172
|
+
type: "string",
|
|
173
|
+
description: "Session ID (required, format: ses_xxx)",
|
|
174
|
+
},
|
|
175
|
+
url: {
|
|
176
|
+
type: "string",
|
|
177
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
178
|
+
},
|
|
179
|
+
username: {
|
|
180
|
+
type: "string",
|
|
181
|
+
description: "Username (optional)",
|
|
182
|
+
},
|
|
183
|
+
password: {
|
|
184
|
+
type: "string",
|
|
185
|
+
description: "Password (optional)",
|
|
186
|
+
},
|
|
187
|
+
auth_type: {
|
|
188
|
+
type: "string",
|
|
189
|
+
description: "Authentication type (optional, default: basic)",
|
|
190
|
+
enum: ["basic", "bearer", "none"],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
required: ["session_id"],
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "opencode_get_messages",
|
|
198
|
+
description: "Get the message list from a session",
|
|
199
|
+
inputSchema: {
|
|
200
|
+
type: "object",
|
|
201
|
+
properties: {
|
|
202
|
+
session_id: {
|
|
203
|
+
type: "string",
|
|
204
|
+
description: "Session ID (required)",
|
|
205
|
+
},
|
|
206
|
+
limit: {
|
|
207
|
+
type: "number",
|
|
208
|
+
description: "Maximum number of messages (optional)",
|
|
209
|
+
},
|
|
210
|
+
url: {
|
|
211
|
+
type: "string",
|
|
212
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
213
|
+
},
|
|
214
|
+
username: {
|
|
215
|
+
type: "string",
|
|
216
|
+
description: "Username (optional)",
|
|
217
|
+
},
|
|
218
|
+
password: {
|
|
219
|
+
type: "string",
|
|
220
|
+
description: "Password (optional)",
|
|
221
|
+
},
|
|
222
|
+
auth_type: {
|
|
223
|
+
type: "string",
|
|
224
|
+
description: "Authentication type (optional, default: basic)",
|
|
225
|
+
enum: ["basic", "bearer", "none"],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
required: ["session_id"],
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "opencode_check_health",
|
|
233
|
+
description: "Check OpenCode server connection status",
|
|
234
|
+
inputSchema: {
|
|
235
|
+
type: "object",
|
|
236
|
+
properties: {
|
|
237
|
+
url: {
|
|
238
|
+
type: "string",
|
|
239
|
+
description: `OpenCode server address (optional, default: ${DEFAULT_CONFIG.url})`,
|
|
240
|
+
},
|
|
241
|
+
username: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description: "Username (optional)",
|
|
244
|
+
},
|
|
245
|
+
password: {
|
|
246
|
+
type: "string",
|
|
247
|
+
description: "Password (optional)",
|
|
248
|
+
},
|
|
249
|
+
auth_type: {
|
|
250
|
+
type: "string",
|
|
251
|
+
description: "Authentication type (optional, default: basic)",
|
|
252
|
+
enum: ["basic", "bearer", "none"],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
// Create MCP Server
|
|
259
|
+
const server = new Server({
|
|
260
|
+
name: "opencode-remote-mcp",
|
|
261
|
+
version: "0.1.0",
|
|
262
|
+
}, {
|
|
263
|
+
capabilities: {
|
|
264
|
+
tools: {},
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
// Handle tool list requests
|
|
268
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
269
|
+
return { tools: TOOLS };
|
|
270
|
+
});
|
|
271
|
+
// Handle tool call requests
|
|
272
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
273
|
+
const { name, arguments: args } = request.params;
|
|
274
|
+
try {
|
|
275
|
+
// Merge configuration: params > env vars > defaults
|
|
276
|
+
const config = {
|
|
277
|
+
url: args?.url || DEFAULT_CONFIG.url,
|
|
278
|
+
username: args?.username || DEFAULT_CONFIG.username,
|
|
279
|
+
password: args?.password || DEFAULT_CONFIG.password,
|
|
280
|
+
token: args?.password || DEFAULT_CONFIG.token,
|
|
281
|
+
authType: (args?.auth_type || DEFAULT_CONFIG.authType).toLowerCase(),
|
|
282
|
+
};
|
|
283
|
+
// Ensure URL format is correct
|
|
284
|
+
const baseUrl = config.url.replace(/\/$/, "");
|
|
285
|
+
const authHeaders = getAuthHeader(config);
|
|
286
|
+
switch (name) {
|
|
287
|
+
case "opencode_chat": {
|
|
288
|
+
const { message, session_id, directory } = args;
|
|
289
|
+
let targetSessionId = session_id;
|
|
290
|
+
// Create a new session if no session_id is provided
|
|
291
|
+
if (!targetSessionId) {
|
|
292
|
+
const queryParams = new URLSearchParams();
|
|
293
|
+
if (directory)
|
|
294
|
+
queryParams.append("directory", directory);
|
|
295
|
+
const createResponse = await fetch(`${baseUrl}/session?${queryParams}`, {
|
|
296
|
+
method: "POST",
|
|
297
|
+
headers: {
|
|
298
|
+
...authHeaders,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
if (!createResponse.ok) {
|
|
302
|
+
const error = await createResponse.text();
|
|
303
|
+
throw new Error(`Failed to create session: ${createResponse.status} - ${error}`);
|
|
304
|
+
}
|
|
305
|
+
const sessionData = (await createResponse.json());
|
|
306
|
+
targetSessionId = sessionData.id;
|
|
307
|
+
}
|
|
308
|
+
// Send message to session
|
|
309
|
+
const queryParams = new URLSearchParams();
|
|
310
|
+
if (directory)
|
|
311
|
+
queryParams.append("directory", directory);
|
|
312
|
+
const response = await fetch(`${baseUrl}/session/${targetSessionId}/message?${queryParams}`, {
|
|
313
|
+
method: "POST",
|
|
314
|
+
headers: {
|
|
315
|
+
"Content-Type": "application/json",
|
|
316
|
+
...authHeaders,
|
|
317
|
+
},
|
|
318
|
+
body: JSON.stringify({
|
|
319
|
+
parts: [{ type: "text", text: message }],
|
|
320
|
+
}),
|
|
321
|
+
});
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const error = await response.text();
|
|
324
|
+
throw new Error(`Failed to send message: ${response.status} - ${error}`);
|
|
325
|
+
}
|
|
326
|
+
const data = (await response.json());
|
|
327
|
+
return {
|
|
328
|
+
content: [
|
|
329
|
+
{
|
|
330
|
+
type: "text",
|
|
331
|
+
text: `✅ Message sent!\nSession ID: ${targetSessionId}\nMessage ID: ${data.info?.id || "unknown"}\n\nResponse:\n${JSON.stringify(data, null, 2)}`,
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
case "opencode_create_session": {
|
|
337
|
+
const { title, directory } = args;
|
|
338
|
+
const queryParams = new URLSearchParams();
|
|
339
|
+
if (directory)
|
|
340
|
+
queryParams.append("directory", directory);
|
|
341
|
+
const body = title ? JSON.stringify({ title }) : undefined;
|
|
342
|
+
const headers = body
|
|
343
|
+
? { "Content-Type": "application/json", ...authHeaders }
|
|
344
|
+
: authHeaders;
|
|
345
|
+
const response = await fetch(`${baseUrl}/session?${queryParams}`, {
|
|
346
|
+
method: "POST",
|
|
347
|
+
headers,
|
|
348
|
+
body,
|
|
349
|
+
});
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
const error = await response.text();
|
|
352
|
+
throw new Error(`Failed to create session: ${response.status} - ${error}`);
|
|
353
|
+
}
|
|
354
|
+
const data = (await response.json());
|
|
355
|
+
return {
|
|
356
|
+
content: [
|
|
357
|
+
{
|
|
358
|
+
type: "text",
|
|
359
|
+
text: `✅ Session created successfully!\nSession ID: ${data.id}\nTitle: ${data.title || "Untitled"}`,
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
case "opencode_list_sessions": {
|
|
365
|
+
const { directory, limit, include_subagents } = args;
|
|
366
|
+
const queryParams = new URLSearchParams();
|
|
367
|
+
if (directory)
|
|
368
|
+
queryParams.append("directory", directory);
|
|
369
|
+
// Request more sessions if we need to filter subagents
|
|
370
|
+
if (limit)
|
|
371
|
+
queryParams.append("limit", (limit * 2).toString());
|
|
372
|
+
const response = await fetch(`${baseUrl}/session?${queryParams}`, {
|
|
373
|
+
headers: authHeaders,
|
|
374
|
+
});
|
|
375
|
+
if (!response.ok) {
|
|
376
|
+
throw new Error(`Failed to list sessions: ${response.status}`);
|
|
377
|
+
}
|
|
378
|
+
let sessions = (await response.json());
|
|
379
|
+
// Filter out subagent sessions by default
|
|
380
|
+
const showSubagents = include_subagents ?? false;
|
|
381
|
+
if (!showSubagents) {
|
|
382
|
+
sessions = sessions.filter((s) => !s.title?.toLowerCase().includes("subagent"));
|
|
383
|
+
}
|
|
384
|
+
// Apply limit after filtering
|
|
385
|
+
if (limit && sessions.length > limit) {
|
|
386
|
+
sessions = sessions.slice(0, limit);
|
|
387
|
+
}
|
|
388
|
+
if (sessions.length === 0) {
|
|
389
|
+
return {
|
|
390
|
+
content: [{ type: "text", text: "No sessions found" }],
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const sessionList = sessions
|
|
394
|
+
.map((s, i) => `${i + 1}. ${s.title || "Untitled"}\n ID: ${s.id}\n Created: ${s.time?.created ? new Date(s.time.created).toLocaleString() : "unknown"}`)
|
|
395
|
+
.join("\n\n");
|
|
396
|
+
const filterInfo = showSubagents
|
|
397
|
+
? "(including subagents)"
|
|
398
|
+
: "(main sessions only)";
|
|
399
|
+
return {
|
|
400
|
+
content: [
|
|
401
|
+
{
|
|
402
|
+
type: "text",
|
|
403
|
+
text: `📋 Session List ${filterInfo} (${sessions.length}):\n\n${sessionList}`,
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
case "opencode_get_session": {
|
|
409
|
+
const { session_id } = args;
|
|
410
|
+
const response = await fetch(`${baseUrl}/session/${session_id}`, {
|
|
411
|
+
headers: authHeaders,
|
|
412
|
+
});
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
throw new Error(`Failed to get session: ${response.status}`);
|
|
415
|
+
}
|
|
416
|
+
const data = await response.json();
|
|
417
|
+
return {
|
|
418
|
+
content: [
|
|
419
|
+
{
|
|
420
|
+
type: "text",
|
|
421
|
+
text: `📄 Session Details:\n${JSON.stringify(data, null, 2)}`,
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
case "opencode_get_messages": {
|
|
427
|
+
const { session_id, limit } = args;
|
|
428
|
+
const queryParams = new URLSearchParams();
|
|
429
|
+
if (limit)
|
|
430
|
+
queryParams.append("limit", limit.toString());
|
|
431
|
+
const response = await fetch(`${baseUrl}/session/${session_id}/message?${queryParams}`, {
|
|
432
|
+
headers: authHeaders,
|
|
433
|
+
});
|
|
434
|
+
if (!response.ok) {
|
|
435
|
+
throw new Error(`Failed to get messages: ${response.status}`);
|
|
436
|
+
}
|
|
437
|
+
const messages = await response.json();
|
|
438
|
+
return {
|
|
439
|
+
content: [
|
|
440
|
+
{
|
|
441
|
+
type: "text",
|
|
442
|
+
text: `💬 Message List:\n${JSON.stringify(messages, null, 2)}`,
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
case "opencode_check_health": {
|
|
448
|
+
const response = await fetch(`${baseUrl}/global/health`, {
|
|
449
|
+
headers: authHeaders,
|
|
450
|
+
});
|
|
451
|
+
if (!response.ok) {
|
|
452
|
+
throw new Error(`Health check failed: ${response.status}`);
|
|
453
|
+
}
|
|
454
|
+
const data = (await response.json());
|
|
455
|
+
return {
|
|
456
|
+
content: [
|
|
457
|
+
{
|
|
458
|
+
type: "text",
|
|
459
|
+
text: `✅ OpenCode server is running normally\nVersion: ${data.version}\nHealthy: ${data.healthy ? "Yes" : "No"}\nAddress: ${baseUrl}`,
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
default:
|
|
465
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
catch (error) {
|
|
469
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
470
|
+
return {
|
|
471
|
+
content: [{ type: "text", text: `❌ Error: ${errorMessage}` }],
|
|
472
|
+
isError: true,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
// Select launch mode
|
|
477
|
+
const mode = process.argv[2] || "stdio";
|
|
478
|
+
if (mode === "stdio") {
|
|
479
|
+
const transport = new StdioServerTransport();
|
|
480
|
+
await server.connect(transport);
|
|
481
|
+
console.error("OpenCode MCP Server v0.1.0 running on stdio");
|
|
482
|
+
console.error(`Default endpoint: ${DEFAULT_CONFIG.url}`);
|
|
483
|
+
}
|
|
484
|
+
else if (mode === "sse") {
|
|
485
|
+
const app = express();
|
|
486
|
+
app.use(cors());
|
|
487
|
+
app.use(express.json());
|
|
488
|
+
let transport = null;
|
|
489
|
+
app.get("/sse", async (req, res) => {
|
|
490
|
+
transport = new SSEServerTransport("/messages", res);
|
|
491
|
+
await server.connect(transport);
|
|
492
|
+
console.log("Client connected via SSE");
|
|
493
|
+
});
|
|
494
|
+
app.post("/messages", async (req, res) => {
|
|
495
|
+
if (transport) {
|
|
496
|
+
await transport.handlePostMessage(req, res);
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
res.status(400).json({ error: "No active SSE connection" });
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
app.get("/health", (req, res) => {
|
|
503
|
+
res.json({
|
|
504
|
+
status: "ok",
|
|
505
|
+
version: "0.1.0",
|
|
506
|
+
defaultEndpoint: DEFAULT_CONFIG.url,
|
|
507
|
+
authType: DEFAULT_CONFIG.authType,
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
app.listen(PORT, () => {
|
|
511
|
+
console.log(`OpenCode MCP Server v0.1.0 running on http://localhost:${PORT}`);
|
|
512
|
+
console.log(`Default OpenCode endpoint: ${DEFAULT_CONFIG.url}`);
|
|
513
|
+
console.log(`Default auth type: ${DEFAULT_CONFIG.authType}`);
|
|
514
|
+
console.log("");
|
|
515
|
+
console.log("Available tools:");
|
|
516
|
+
console.log(" - opencode_chat: Send programming tasks (auto-creates session)");
|
|
517
|
+
console.log(" - opencode_create_session: Create session");
|
|
518
|
+
console.log(" - opencode_list_sessions: List sessions");
|
|
519
|
+
console.log(" - opencode_get_session: Get session details");
|
|
520
|
+
console.log(" - opencode_get_messages: Get session messages");
|
|
521
|
+
console.log(" - opencode_check_health: Health check");
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
console.error("Usage: node index.js [stdio|sse]");
|
|
526
|
+
process.exit(1);
|
|
527
|
+
}
|
|
528
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EACN,qBAAqB,EACrB,sBAAsB,GAEtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,aAAa,EAA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O,CAAC,GAAG,CACV,0DAA0D,IAAI,EAAE,CAChE,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,8BAA8B,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,sBAAsB,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CACV,kEAAkE,CAClE,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACJ,CAAC;KAAM,CAAC;IACP,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-mcp-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP Server for remote OpenCode HTTP API - Connect OpenClaw to OpenCode agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"opencode-mcp-server": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"dev": "tsc --watch & node --watch dist/index.js",
|
|
14
|
+
"start": "node dist/index.js",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"opencode",
|
|
21
|
+
"ai",
|
|
22
|
+
"coding",
|
|
23
|
+
"agent",
|
|
24
|
+
"model-context-protocol",
|
|
25
|
+
"openclaw",
|
|
26
|
+
"claude",
|
|
27
|
+
"automation",
|
|
28
|
+
"remote-server"
|
|
29
|
+
],
|
|
30
|
+
"author": "shiquda",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/shiquda/opencode-mcp-server.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/shiquda/opencode-mcp-server/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/shiquda/opencode-mcp-server#readme",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE",
|
|
47
|
+
"CHANGELOG.md"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
51
|
+
"express": "^4.18.2",
|
|
52
|
+
"node-fetch": "^3.3.2",
|
|
53
|
+
"dotenv": "^16.3.1",
|
|
54
|
+
"cors": "^2.8.5"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/express": "^4.17.21",
|
|
58
|
+
"@types/cors": "^2.8.17",
|
|
59
|
+
"@types/node": "^20.10.0",
|
|
60
|
+
"typescript": "^5.3.0"
|
|
61
|
+
}
|
|
62
|
+
}
|