feat(cli): support inline mcp add args

This commit is contained in:
opencode-agent[bot]
2026-06-01 04:23:08 +00:00
parent a9c115c220
commit 2ca7478b8a
4 changed files with 388 additions and 19 deletions
@@ -27,11 +27,11 @@ exports[`opencode CLI help-text snapshots every documented command emits stable
manage MCP (Model Context Protocol) servers
Commands:
opencode mcp add add an MCP server
opencode mcp list list MCP servers and their status [aliases: ls]
opencode mcp auth [name] authenticate with an OAuth-enabled MCP server
opencode mcp logout [name] remove OAuth credentials for an MCP server
opencode mcp debug <name> debug OAuth connection for an MCP server
opencode mcp add [name] [urlOrCommand..] add an MCP server
opencode mcp list list MCP servers and their status [aliases: ls]
opencode mcp auth [name] authenticate with an OAuth-enabled MCP server
opencode mcp logout [name] remove OAuth credentials for an MCP server
opencode mcp debug <name> debug OAuth connection for an MCP server
Options:
-h, --help show help [boolean]
@@ -425,16 +425,34 @@ Options:
`;
exports[`opencode CLI help-text snapshots every documented command emits stable help text: opencode mcp add --help 1`] = `
"opencode mcp add
"opencode mcp add [name] [urlOrCommand..]
add an MCP server
Positionals:
name name of the MCP server [string]
urlOrCommand URL for remote servers or command for local servers [array] [default: []]
Options:
-h, --help show help [boolean]
-v, --version show version number [boolean]
--print-logs print logs to stderr [boolean]
--log-level log level [string] [choices: "DEBUG", "INFO", "WARN", "ERROR"]
--pure run without external plugins [boolean]"
-h, --help show help [boolean]
-v, --version show version number [boolean]
--print-logs print logs to stderr [boolean]
--log-level log level [string] [choices: "DEBUG", "INFO", "WARN", "ERROR"]
--pure run without external plugins [boolean]
--type server type: local or remote [string] [choices: "local", "remote"]
--env environment variable for local servers (KEY=VALUE) [array]
--header HTTP header for remote servers (KEY=VALUE or 'KEY: VALUE') [array]
--scope where to save the server [string] [choices: "project", "global"]
-g, --global save to global config [boolean]
--enabled enable or disable the server on startup [boolean]
--timeout timeout in milliseconds for MCP server requests [number]
--oauth enable OAuth for remote servers, or use --no-oauth to disable
auto-detection [boolean]
--oauth-client-id OAuth client ID for remote servers [string]
--oauth-client-secret OAuth client secret for remote servers [string]
--oauth-scope OAuth scopes to request for remote servers [string]
--oauth-callback-port OAuth local callback port for remote servers [number]
--oauth-redirect-uri OAuth redirect URI for remote servers [string]"
`;
exports[`opencode CLI help-text snapshots every documented command emits stable help text: opencode mcp auth --help 1`] = `
+89
View File
@@ -0,0 +1,89 @@
import { describe, expect } from "bun:test"
import { Effect } from "effect"
import path from "node:path"
import { cliIt } from "../lib/cli-process"
describe("opencode mcp", () => {
cliIt.live(
"adds MCP servers from inline arguments",
({ home, opencode }) =>
Effect.gen(function* () {
const result = yield* opencode.spawn([
"mcp",
"add",
"github",
"https://api.githubcopilot.com/mcp",
"--type",
"remote",
"--header",
"Authorization: Bearer test-token",
"--global",
])
opencode.expectExit(result, 0, "opencode mcp add remote")
expect(yield* Effect.promise(() => Bun.file(path.join(home, ".config/opencode/opencode.json")).json())).toEqual(
{
mcp: {
github: {
type: "remote",
url: "https://api.githubcopilot.com/mcp",
headers: {
Authorization: "Bearer test-token",
},
},
},
},
)
const local = yield* opencode.spawn([
"mcp",
"add",
"everything",
"npx",
"-y",
"@modelcontextprotocol/server-everything",
"--env",
"FOO=bar",
"--global",
])
opencode.expectExit(local, 0, "opencode mcp add local")
expect(
yield* Effect.promise(() => Bun.file(path.join(home, ".config/opencode/opencode.json")).json()),
).toMatchObject({
mcp: {
everything: {
type: "local",
command: ["npx", "-y", "@modelcontextprotocol/server-everything"],
environment: {
FOO: "bar",
},
},
},
})
const noOAuth = yield* opencode.spawn([
"mcp",
"add",
"public",
"https://example.com/mcp",
"--no-oauth",
"--global",
])
opencode.expectExit(noOAuth, 0, "opencode mcp add no oauth")
expect(
yield* Effect.promise(() => Bun.file(path.join(home, ".config/opencode/opencode.json")).json()),
).toMatchObject({
mcp: {
public: {
type: "remote",
url: "https://example.com/mcp",
oauth: false,
},
},
})
}),
120_000,
)
})