mcp: add lastEventIDHeader for streamable implementation
Use a constant, to be consistent with other headers.
This commit is contained in:
parent
afe8888129
commit
b8c21e9fc0
1 changed files with 5 additions and 4 deletions
|
|
@ -32,6 +32,7 @@ import (
|
||||||
const (
|
const (
|
||||||
protocolVersionHeader = "Mcp-Protocol-Version"
|
protocolVersionHeader = "Mcp-Protocol-Version"
|
||||||
sessionIDHeader = "Mcp-Session-Id"
|
sessionIDHeader = "Mcp-Session-Id"
|
||||||
|
lastEventIDHeader = "Last-Event-ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A StreamableHTTPHandler is an http.Handler that serves streamable MCP
|
// A StreamableHTTPHandler is an http.Handler that serves streamable MCP
|
||||||
|
|
@ -713,8 +714,8 @@ func (c *streamableServerConn) serveGET(w http.ResponseWriter, req *http.Request
|
||||||
// By default, we haven't seen a last index. Since indices start at 0, we represent
|
// By default, we haven't seen a last index. Since indices start at 0, we represent
|
||||||
// that by -1. This is incremented just before each event is written.
|
// that by -1. This is incremented just before each event is written.
|
||||||
lastIdx := -1
|
lastIdx := -1
|
||||||
if len(req.Header.Values("Last-Event-ID")) > 0 {
|
if len(req.Header.Values(lastEventIDHeader)) > 0 {
|
||||||
eid := req.Header.Get("Last-Event-ID")
|
eid := req.Header.Get(lastEventIDHeader)
|
||||||
var ok bool
|
var ok bool
|
||||||
streamID, lastIdx, ok = parseEventID(eid)
|
streamID, lastIdx, ok = parseEventID(eid)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -931,7 +932,7 @@ func (c *streamableServerConn) acquireStream(ctx context.Context, w http.Respons
|
||||||
//
|
//
|
||||||
// It returns an HTTP status code and error message.
|
// It returns an HTTP status code and error message.
|
||||||
func (c *streamableServerConn) servePOST(w http.ResponseWriter, req *http.Request) {
|
func (c *streamableServerConn) servePOST(w http.ResponseWriter, req *http.Request) {
|
||||||
if len(req.Header.Values("Last-Event-ID")) > 0 {
|
if len(req.Header.Values(lastEventIDHeader)) > 0 {
|
||||||
http.Error(w, "can't send Last-Event-ID for POST request", http.StatusBadRequest)
|
http.Error(w, "can't send Last-Event-ID for POST request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1923,7 +1924,7 @@ func (c *streamableClientConn) connectSSE(ctx context.Context, lastEventID strin
|
||||||
}
|
}
|
||||||
c.setMCPHeaders(req)
|
c.setMCPHeaders(req)
|
||||||
if lastEventID != "" {
|
if lastEventID != "" {
|
||||||
req.Header.Set("Last-Event-ID", lastEventID)
|
req.Header.Set(lastEventIDHeader, lastEventID)
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "text/event-stream")
|
req.Header.Set("Accept", "text/event-stream")
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue