mcp: whether MaxLineLength rejects a message depends on how the stream is read
维护者通常 1 天内回复
@Tangerg 已经在做这个了。
开始于 2026年11月6日。
评估
这个 Issue 还没有评估数据。
描述
Checklist
- I searched the existing issues, and this has not been reported before.
- This is a real problem that I ran into myself, using the latest release of the SDK.
- I ran into it in a production system, not in a toy example, a benchmark, or an automated or AI-driven scan of the code.
- I (a human) examined the relevant SDK code, and wrote or reviewed every line of this report. It is not unreviewed AI output.
- This report is brief and concise, and sticks to the facts needed to understand the problem.
What happened?
Whether MaxLineLength rejects an inbound message on IOTransport, StdioTransport or CommandTransport depends on how the reader splits the stream. In the program below, with a cap of 128 bytes, the same 153-byte message is accepted when the stream arrives in one read and rejected when it arrives one byte at a time.
frameLimitReader resets its count after each message, but json.Decoder reads ahead. Bytes of the next message that the decoder read while finishing the previous one are counted toward the previous one and then forgotten, so the next message can exceed the cap by that many bytes.
Expected: whether a message fits depends only on the message.
I'd like to fix this myself, by starting each message's count at the decoder's InputOffset instead of resetting it, so that bytes read ahead count toward the message they belong to.
AI assistance: the investigation was done with Claude; I reviewed the report and the SDK code.
How to reproduce
package main
import (
"context"
"fmt"
"io"
"strings"
"testing/iotest"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type nopCloser struct{ io.Writer }
func (nopCloser) Close() error { return nil }
func main() {
// With MaxLineLength 128, the second message (153 bytes) should be rejected.
stream := `{"jsonrpc":"2.0","method":"first"}` + "\n" +
`{"jsonrpc":"2.0","method":"second","params":{"p":"` + strings.Repeat("x", 100) + `"}}` + "\n"
for _, r := range []struct {
name string
r io.Reader
}{
{"whole stream per read", strings.NewReader(stream)},
{"one byte per read", iotest.OneByteReader(strings.NewReader(stream))},
} {
t := &mcp.IOTransport{Reader: io.NopCloser(r.r), Writer: nopCloser{io.Discard}, MaxLineLength: 128}
conn, err := t.Connect(context.Background())
if err != nil {
panic(err)
}
if _, err := conn.Read(context.Background()); err != nil {
panic(err)
}
_, err = conn.Read(context.Background())
fmt.Printf("%s: second message: %v\n", r.name, err)
}
}
Output with v1.8.0:
whole stream per read: second message: <nil>
one byte per read: second message: inbound JSON-RPC frame exceeded the configured maximum line length
Where did you hit this?
Flame's plugin runtime talks MCP to plugin processes over pipes with IOTransport, setting MaxLineLength to its process protocol's frame budget; Frame, the plugin framework under it, sets MaxLineLength to -1 and admits whole frames in its own reader instead.
Go MCP SDK version
v1.8.0 (also on main at 449d945)
Go version
go version go1.27.3 darwin/arm64
Logs
No response
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 607
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 81
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/go-sdk#1512 ·
维护者通常 1 天内回复
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions可能重新可做 关联的 PR 已关闭且未合并。 未关闭needs investigation
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/go-sdk#745 · 13 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
modelcontextprotocol/go-sdk#1506 · 2 条评论 ·
维护者通常 1 天内回复
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps running可能已有人在做 @vshalpnjabi 于 2 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
modelcontextprotocol/go-sdk#1505 · 1 条评论 ·
维护者通常 1 天内回复
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)可能已有人在做 @nahapetyan-serob 于 1 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 32/100
modelcontextprotocol/go-sdk#1480 · 1 条评论 · 已指派 2 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
book-layout.spec fails when the similar-books rail holds other projects' books可能已有人在做 @praetorianer777 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
praetorianer777/GoTome#373 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
-
/shutdown/ready can fail to return an HTTP response when readiness takes longer than the server write timeout可能已有人在做 @floriankoch 今天认领。 未关闭triage
难度 2/5 1-3 小时 新手友好度 76/100
envoyproxy/gateway#10562 ·
维护者通常 1 天内回复
-
Adding an LDAP group reports every search failure as "LDAP Group DN is not found"可能已有人在做 @Daksha1611 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复