docs: add feature and troubleshooting documentation (#463)
Add a framework for feature documentation, and start populating it with our SDK documentation. This framework is as follows: - internal/docs/**.src.md is the markdown source for the docs/ directory. - The x/example/internal/cmd/weave tool is used to compile these docs to the top-level docs, supporting both linked code samples and generated tables of contents. - The readme-check workflow is updated to check these docs as well. - The structure of these docs follows the MCP spec. - Wherever possible, example code is linked from actual Go documentation examples, so that it is testable. Some minor modifications to the weave tool were made to support this framework. Additionally, partially fill out this documentation with content on base protocol and client features, as well as troubleshooting help. Along the way, a bug was encountered that our LoggingTransport was not concurrency safe. This is fixed with a mutex. Fixes https://github.com/modelcontextprotocol/go-sdk/issues/466 Fixes https://github.com/modelcontextprotocol/go-sdk/issues/409 Updates https://github.com/modelcontextprotocol/go-sdk/issues/442
This commit is contained in:
parent
ab4d6218c6
commit
ac2f175214
1 changed files with 1566 additions and 30 deletions
|
|
@ -70,9 +70,12 @@ type StreamableHTTPOptions struct {
|
|||
// documentation for [StreamableServerTransport].
|
||||
Stateless bool
|
||||
|
||||
// TODO: support session retention (?)
|
||||
// TODO(#148): support session retention (?)
|
||||
|
||||
// JSONResponse is forwarded to StreamableServerTransport.jsonResponse.
|
||||
// JSONResponse causes streamable responses to return application/json rather
|
||||
// than text/event-stream ([§2.1.5] of the spec).
|
||||
//
|
||||
// [§2.1.5]: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server
|
||||
JSONResponse bool
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +184,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
|
|||
return
|
||||
}
|
||||
|
||||
// Section 2.7 of the spec (2025-06-18) states:
|
||||
// [§2.7] of the spec (2025-06-18) states:
|
||||
//
|
||||
// "If using HTTP, the client MUST include the MCP-Protocol-Version:
|
||||
// <protocol-version> HTTP header on all subsequent requests to the MCP
|
||||
|
|
@ -209,6 +212,8 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
|
|||
// assume 2025-03-26 if the client doesn't say anything).
|
||||
//
|
||||
// This logic matches the typescript SDK.
|
||||
//
|
||||
// [§2.7]: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#protocol-version-header
|
||||
protocolVersion := req.Header.Get(protocolVersionHeader)
|
||||
if protocolVersion == "" {
|
||||
protocolVersion = protocolVersion20250326
|
||||
|
|
@ -370,6 +375,9 @@ type StreamableServerTransport struct {
|
|||
// request contain only a single message. In this case, notifications or
|
||||
// requests made within the context of a server request will be sent to the
|
||||
// hanging GET request, if any.
|
||||
//
|
||||
// TODO(rfindley): jsonResponse should be exported, since
|
||||
// StreamableHTTPOptions.JSONResponse is exported.
|
||||
jsonResponse bool
|
||||
|
||||
// connection is non-nil if and only if the transport has been connected.
|
||||
|
|
@ -1188,7 +1196,7 @@ func (c *streamableClientConn) Write(ctx context.Context, msg jsonrpc.Message) e
|
|||
return fmt.Errorf("%s: %v", requestSummary, err)
|
||||
}
|
||||
|
||||
// Section 2.5.3: "The server MAY terminate the session at any time, after
|
||||
// §2.5.3: "The server MAY terminate the session at any time, after
|
||||
// which it MUST respond to requests containing that session ID with HTTP
|
||||
// 404 Not Found."
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
|
|
|
|||
Loading…
Reference in a new issue