Compare commits

...

2 Commits

Author SHA1 Message Date
Dax Raad 4fc32f7c9a better mcp support - should fix hanging when streamable http server is added
publish / publish (push) Waiting to run
2025-07-25 19:19:47 -04:00
Frank 39e0ae70fe wip: github actions
publish / publish (push) Waiting to run
2025-07-25 19:05:55 -04:00
3 changed files with 44 additions and 24 deletions
+4
View File
@@ -20,6 +20,10 @@
}
},
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/sse"
},
"weather": {
"type": "local",
"command": ["opencode", "x", "@h1deya/mcp-server-weather"]
+14 -10
View File
@@ -375,9 +375,6 @@ export const GithubRunCommand = cmd({
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
// TODO
console.log("payload", payload)
let appToken: string
let octoRest: Octokit
let octoGraph: typeof graphql
@@ -428,7 +425,7 @@ export const GithubRunCommand = cmd({
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
if (await branchIsDirty()) {
const summary = await summarize(response)
await pushToCurrentBranch(summary)
await pushToLocalBranch(summary)
}
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
await updateComment(`${response}${footer({ image: !hasShared })}`)
@@ -454,7 +451,7 @@ export const GithubRunCommand = cmd({
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
if (await branchIsDirty()) {
const summary = await summarize(response)
await pushToCurrentBranch(summary)
await pushToNewBranch(summary, branch)
const pr = await createPR(
repoData.data.default_branch,
branch,
@@ -540,6 +537,7 @@ export const GithubRunCommand = cmd({
const mdMatches = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
const tagMatches = prompt.matchAll(/<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi)
const matches = [...mdMatches, ...tagMatches].sort((a, b) => a.index - b.index)
console.log("Images", JSON.stringify(matches, null, 2))
let offset = 0
for (const m of matches) {
@@ -556,9 +554,6 @@ export const GithubRunCommand = cmd({
},
})
if (!res.ok) {
// TODO
//console.log(res)
//throw new Error("manual")
console.error(`Failed to download image: ${url}`)
continue
}
@@ -791,8 +786,17 @@ export const GithubRunCommand = cmd({
return `opencode/${type}${issueId}-${timestamp}`
}
async function pushToCurrentBranch(summary: string) {
console.log("Pushing to current branch...")
async function pushToNewBranch(summary: string, branch: string) {
console.log("Pushing to new branch...")
await $`git add .`
await $`git commit -m "${summary}
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
await $`git push -u origin ${branch}`
}
async function pushToLocalBranch(summary: string) {
console.log("Pushing to local branch...")
await $`git add .`
await $`git commit -m "${summary}
+26 -14
View File
@@ -1,5 +1,7 @@
import { experimental_createMCPClient, type Tool } from "ai"
import { Experimental_StdioMCPTransport } from "ai/mcp-stdio"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
import { App } from "../app/app"
import { Config } from "../config/config"
import { Log } from "../util/log"
@@ -32,15 +34,28 @@ export namespace MCP {
}
log.info("found", { key, type: mcp.type })
if (mcp.type === "remote") {
const client = await experimental_createMCPClient({
name: key,
transport: {
type: "sse",
url: mcp.url,
headers: mcp.headers,
},
}).catch(() => {})
if (!client) {
const transports = [
new StreamableHTTPClientTransport(new URL(mcp.url), {
requestInit: {
headers: mcp.headers,
},
}),
new SSEClientTransport(new URL(mcp.url), {
requestInit: {
headers: mcp.headers,
},
}),
]
for (const transport of transports) {
const client = await experimental_createMCPClient({
name: key,
transport,
}).catch(() => {})
if (!client) continue
clients[key] = client
break
}
if (!clients[key])
Bus.publish(Session.Event.Error, {
error: {
name: "UnknownError",
@@ -49,16 +64,13 @@ export namespace MCP {
},
},
})
continue
}
clients[key] = client
}
if (mcp.type === "local") {
const [cmd, ...args] = mcp.command
const client = await experimental_createMCPClient({
name: key,
transport: new Experimental_StdioMCPTransport({
transport: new StdioClientTransport({
stderr: "ignore",
command: cmd,
args,