The official Go SDK for Model Context Protocol servers and clients. Maintained in collaboration with Google.
by modelcontextprotocolGo
Last 12 weeks · 89 commits
5 of 6 standards met
What did you do? Called a tool that takes a while to return, over Streamable HTTP, with a client that applies a first-byte or idle timeout. Minimal reproduction (added as a test in ): ``CodeMethodNotFoundCodeInvalidParamsCodeUnsupportedProtocolVersionCodeMissingRequiredClientCapabilitiesTestStreamableStateless_NewProtocolSession_NoFakeInitsuperfluous response.WriteHeaderdeliverLockedflushEarlyAfterstreamstream.mudeliverLockeds.wheadersFlushed-raceStreamableHTTPOptions`, gated on protocol version, or shaped differently — filing this first per CONTRIBUTING.md.
Fixes #1191. previously closed the session signal without draining buffered client messages. Because and select between the message queue and the closed signal, a closed session could deliver stale messages or acknowledge a POST with even though the message would never be processed. This change: Drains buffered incoming messages when the server connection closes. Checks the closed state before and after queue operations so close races return or . Adds regression tests for stale post-close reads and POST responses after close. Tests: (the MCP package still has the pre-existing localhost protection failure where the case receives HTTP 200 instead of 403; all other packages pass)
The bug () carries json:"text,omitempty"\`anyOf[TextResourceContents, BlobResourceContents]textTextResourceContents&ResourceContents{URI: "u"}{"uri":"u"}textMarshalJSONResourceContentsTextContent.MarshalJSONBlobBlob == niltextblobBlob != nil[]byte{}blobtext_metaMetaUnmarshalJSONResourceContentscontent.go// TODO(findleyr): update JSON marshalling of all content types to preserve required fields.TextContentImageContentAudioContentResourceContentsmcp/content_test.goTestEmbeddedResource{"uri":"u"}&ResourceContents{URI: "u"}{"uri":"u","text":""}&ResourceContents{URI: "u", Blob: []byte{}}{"uri":"u","blob":""}gofmt -l ./go build ./...go vet ./...go test ./...go test ./mcp/ -run TestEmbeddedResource -vResourceContentsMarshalJSONtextBlobjson:"blob,omitzero"BlobTextcontent.go`. This isn't a duplicate of prior work; it's the same series continued. AI assistance disclosure Per the modelcontextprotocol AI policy: this change was made in conjunction with my pair programmer, Claude Code. Extent, so you know how much scrutiny to apply: the defect was surfaced by an automated sweep I run across MCP-ecosystem repos, and the patch was written with Claude Code working alongside me. I reviewed it before filing — the before/after test output, the baseline test counts, and the lint/format runs quoted above were executed on my machine, not pasted from a model. I understand what the change does and why, and replies on this PR are mine.
Repository: modelcontextprotocol/go-sdk. Description: The official Go SDK for Model Context Protocol servers and clients. Maintained in collaboration with Google. Stars: 5009, Forks: 519. Primary language: Go. Languages: Go (99.6%), Shell (0.4%). Homepage: https://modelcontextprotocol.io Topics: go, mcp. Latest release: v1.7.0 (3w ago). Open PRs: 43, open issues: 48. Last activity: 2d ago. Community health: 87%. Top contributors: findleyr, jba, guglielmo-san, maciej-kisiel, samthanawalla, dependabot[bot], cryo-zd, IAmSurajBobade, ravyg, yarolegovich and others.