Skip to content
Open
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
22 changes: 12 additions & 10 deletions apisix/plugins/mcp-bridge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,41 @@ local function on_connect(conf, ctx)
-- if there is an incomplete message it is buffered and
-- spliced before the next message
repeat
local line, _
line, _, stdout_partial = proc:stdout_read_line()
local line, _, partial = proc:stdout_read_line()
if line then
local ok, err = server.transport:send(
stdout_partial and stdout_partial .. line or line
)
local msg = stdout_partial and (stdout_partial .. line) or line
stdout_partial = nil
local ok, err = server.transport:send(msg)
if not ok then
core.log.info("session ", server.session_id,
" exit, failed to send response message: ", err)
need_exit = true
break
end
stdout_partial = nil -- luacheck: ignore
elseif partial and #partial > 0 then
stdout_partial = (stdout_partial or "") .. partial
end
until not line
if need_exit then
break
end

repeat
local line, _
line, _, stderr_partial = proc:stderr_read_line()
local line, _, partial = proc:stderr_read_line()
if line then
local content = stderr_partial and (stderr_partial .. line) or line
stderr_partial = nil
local ok, err = server.transport:send(
'{"jsonrpc":"2.0","method":"notifications/stderr","params":{"content":"'
.. (stderr_partial and stderr_partial .. line or line) .. '"}}')
.. content .. '"}}')
if not ok then
core.log.info("session ", server.session_id,
" exit, failed to send response message: ", err)
need_exit = true
break
end
stderr_partial = "" -- luacheck: ignore
elseif partial and #partial > 0 then
stderr_partial = (stderr_partial or "") .. partial
end
until not line
if need_exit then
Expand Down
Loading