summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-07-12 20:25:41 -0400
committerDax Raad <[email protected]>2025-07-13 16:22:16 -0400
commit91f8477ef5862a3f28a6b6588ba3ae28e856322e (patch)
tree65d781be3a69257066436502455799abef5d66d4 /packages
parentf04a5e50ee771d190f1d5fdcb7780c156e3a70b3 (diff)
downloadopencode-91f8477ef5862a3f28a6b6588ba3ae28e856322e.tar.gz
opencode-91f8477ef5862a3f28a6b6588ba3ae28e856322e.zip
wip: mcp
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/package.json1
-rw-r--r--packages/opencode/src/cli/cmd/mcp.ts79
-rw-r--r--packages/opencode/src/cli/cmd/stats.ts1
-rw-r--r--packages/opencode/src/index.ts2
4 files changed, 82 insertions, 1 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json
index fae2e3425..c5b7e4ba9 100644
--- a/packages/opencode/package.json
+++ b/packages/opencode/package.json
@@ -29,6 +29,7 @@
"@flystorage/file-storage": "1.1.0",
"@flystorage/local-fs": "1.1.0",
"@hono/zod-validator": "0.5.0",
+ "@modelcontextprotocol/sdk": "1.15.1",
"@openauthjs/openauth": "0.4.3",
"@standard-schema/spec": "1.0.0",
"ai": "catalog:",
diff --git a/packages/opencode/src/cli/cmd/mcp.ts b/packages/opencode/src/cli/cmd/mcp.ts
new file mode 100644
index 000000000..5f8b6e5d8
--- /dev/null
+++ b/packages/opencode/src/cli/cmd/mcp.ts
@@ -0,0 +1,79 @@
+import { cmd } from "./cmd"
+import { Client } from "@modelcontextprotocol/sdk/client/index.js"
+import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
+import * as prompts from "@clack/prompts"
+import { UI } from "../ui"
+
+export const McpCommand = cmd({
+ command: "mcp",
+ builder: (yargs) => yargs.command(McpAddCommand).demandCommand(),
+ async handler() {},
+})
+
+export const McpAddCommand = cmd({
+ command: "add",
+ describe: "add an MCP server",
+ async handler() {
+ UI.empty()
+ prompts.intro("Add MCP server")
+
+ const name = await prompts.text({
+ message: "Enter MCP server name",
+ validate: (x) => (x.length > 0 ? undefined : "Required"),
+ })
+ if (prompts.isCancel(name)) throw new UI.CancelledError()
+
+ const type = await prompts.select({
+ message: "Select MCP server type",
+ options: [
+ {
+ label: "Local",
+ value: "local",
+ hint: "Run a local command",
+ },
+ {
+ label: "Remote",
+ value: "remote",
+ hint: "Connect to a remote URL",
+ },
+ ],
+ })
+ if (prompts.isCancel(type)) throw new UI.CancelledError()
+
+ if (type === "local") {
+ const command = await prompts.text({
+ message: "Enter command to run",
+ placeholder: "e.g., opencode x @modelcontextprotocol/server-filesystem",
+ validate: (x) => (x.length > 0 ? undefined : "Required"),
+ })
+ if (prompts.isCancel(command)) throw new UI.CancelledError()
+
+ prompts.log.info(`Local MCP server "${name}" configured with command: ${command}`)
+ prompts.outro("MCP server added successfully")
+ return
+ }
+
+ if (type === "remote") {
+ const url = await prompts.text({
+ message: "Enter MCP server URL",
+ placeholder: "e.g., https://example.com/mcp",
+ validate: (x) => {
+ if (x.length === 0) return "Required"
+ const isValid = URL.canParse(x)
+ return isValid ? undefined : "Invalid URL"
+ },
+ })
+ if (prompts.isCancel(url)) throw new UI.CancelledError()
+
+ const client = new Client({
+ name: "opencode",
+ version: "1.0.0",
+ })
+ const transport = new StreamableHTTPClientTransport(new URL(url))
+ await client.connect(transport)
+ prompts.log.info(`Remote MCP server "${name}" configured with URL: ${url}`)
+ }
+
+ prompts.outro("MCP server added successfully")
+ },
+})
diff --git a/packages/opencode/src/cli/cmd/stats.ts b/packages/opencode/src/cli/cmd/stats.ts
index 0db41651a..6c0b16003 100644
--- a/packages/opencode/src/cli/cmd/stats.ts
+++ b/packages/opencode/src/cli/cmd/stats.ts
@@ -27,7 +27,6 @@ interface SessionStats {
export const StatsCommand = cmd({
command: "stats",
- describe: "analyze and display statistics from message-v2 format",
handler: async () => {
await bootstrap({ cwd: process.cwd() }, async () => {
const stats: SessionStats = {
diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts
index 26129c10c..f0fc9e115 100644
--- a/packages/opencode/src/index.ts
+++ b/packages/opencode/src/index.ts
@@ -15,6 +15,7 @@ import { ServeCommand } from "./cli/cmd/serve"
import { TuiCommand } from "./cli/cmd/tui"
import { DebugCommand } from "./cli/cmd/debug"
import { StatsCommand } from "./cli/cmd/stats"
+import { McpCommand } from "./cli/cmd/mcp"
const cancel = new AbortController()
@@ -65,6 +66,7 @@ const cli = yargs(hideBin(process.argv))
})
})
.usage("\n" + UI.logo())
+ .command(McpCommand)
.command(TuiCommand)
.command(RunCommand)
.command(GenerateCommand)