Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export const McpDebugCommand = cmd({
jsonrpc: "2.0",
method: "initialize",
params: {
protocolVersion: "2024-11-05",
protocolVersion: "2025-03-26",
capabilities: {},
clientInfo: { name: "opencode-debug", version: Installation.VERSION },
},
Expand Down
23 changes: 23 additions & 0 deletions packages/opencode/src/cli/cmd/tui/context/sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ProviderAuthMethod,
VcsInfo,
} from "@opencode-ai/sdk/v2"
import type { Elicitation } from "@/mcp/elicitation"
import { createStore, produce, reconcile } from "solid-js/store"
import { useSDK } from "@tui/context/sdk"
import { Binary } from "@opencode-ai/util/binary"
Expand Down Expand Up @@ -46,6 +47,9 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
question: {
[sessionID: string]: QuestionRequest[]
}
elicitation: {
[id: string]: Elicitation.Request
}
config: Config
session: Session[]
session_status: {
Expand Down Expand Up @@ -85,6 +89,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
agent: [],
permission: {},
question: {},
elicitation: {},
command: [],
provider: [],
provider_default: {},
Expand Down Expand Up @@ -304,6 +309,24 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
setStore("vcs", { branch: event.properties.branch })
break
}

case "mcp.elicitation.requested": {
const request = event.properties
setStore("elicitation", request.id, request)
break
}

case "mcp.elicitation.completed":
case "mcp.elicitation.rejected": {
const { id } = event.properties
setStore(
"elicitation",
produce((draft) => {
delete draft[id]
}),
)
break
}
}
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { Elicitation } from "@/mcp/elicitation"

// Field type derived from schema
export type FieldType = "string" | "number" | "boolean" | "enum" | "multiselect"

export interface FormField {
key: string
type: FieldType
title: string
description?: string
required: boolean
default?: string | number | boolean | string[]
// For enum/multiselect
options?: Array<{ value: string; label: string }>
// For validation
format?: string
minLength?: number
maxLength?: number
minimum?: number
maximum?: number
}

export function schemaToFields(schema: Elicitation.RequestedSchema): FormField[] {
const fields: FormField[] = []
const required = new Set(schema.required ?? [])

for (const [key, prop] of Object.entries(schema.properties)) {
const field: FormField = {
key,
type: "string",
title: prop.title ?? key,
description: prop.description,
required: required.has(key),
default: prop.default as string | number | boolean | string[] | undefined,
}

if (prop.type === "string") {
// Check for enum types
if (prop.oneOf) {
field.type = "enum"
field.options = prop.oneOf.map((o) => ({ value: o.const, label: o.title }))
} else if (prop.enum) {
field.type = "enum"
field.options = prop.enum.map((v, i) => ({
value: v,
label: prop.enumNames?.[i] ?? v,
}))
} else {
field.type = "string"
field.format = prop.format
field.minLength = prop.minLength
field.maxLength = prop.maxLength
}
} else if (prop.type === "number" || prop.type === "integer") {
field.type = "number"
field.minimum = prop.minimum
field.maximum = prop.maximum
} else if (prop.type === "boolean") {
field.type = "boolean"
} else if (prop.type === "array") {
field.type = "multiselect"
if (prop.items.anyOf) {
field.options = prop.items.anyOf.map((o) => ({ value: o.const, label: o.title }))
} else if (prop.items.enum) {
field.options = prop.items.enum.map((v) => ({ value: v, label: v }))
}
}

fields.push(field)
}

return fields
}
Loading