Skip to content

Commit 58d9bbe

Browse files
committed
RequestExtra
1 parent 508b132 commit 58d9bbe

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

mcp/shared.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func handleReceive[S Session](ctx context.Context, session S, jreq *jsonrpc.Requ
133133
}
134134

135135
mh := session.receivingMethodHandler().(MethodHandler)
136-
ti, _ := jreq.Extra.(*RequestExtra)
137-
req := info.newRequest(session, params, ti)
136+
re, _ := jreq.Extra.(*RequestExtra)
137+
req := info.newRequest(session, params, re)
138138
// mh might be user code, so ensure that it returns the right values for the jsonrpc2 protocol.
139139
res, err := mh(ctx, jreq.Method, req)
140140
if err != nil {
@@ -181,7 +181,7 @@ type methodInfo struct {
181181
// Unmarshal params from the wire into a Params struct.
182182
// Used on the receive side.
183183
unmarshalParams func(json.RawMessage) (Params, error)
184-
newRequest func(Session, Params, *auth.TokenInfo) Request
184+
newRequest func(Session, Params, *RequestExtra) Request
185185
// Run the code when a call to the method is received.
186186
// Used on the receive side.
187187
handleMethod methodHandler
@@ -216,7 +216,7 @@ const (
216216

217217
func newClientMethodInfo[P paramsPtr[T], R Result, T any](d typedClientMethodHandler[P, R], flags methodFlags) methodInfo {
218218
mi := newMethodInfo[P, R](flags)
219-
mi.newRequest = func(s Session, p Params, _ *auth.TokenInfo) Request {
219+
mi.newRequest = func(s Session, p Params, _ *RequestExtra) Request {
220220
r := &ClientRequest[P]{Session: s.(*ClientSession)}
221221
if p != nil {
222222
r.Params = p.(P)
@@ -231,8 +231,8 @@ func newClientMethodInfo[P paramsPtr[T], R Result, T any](d typedClientMethodHan
231231

232232
func newServerMethodInfo[P paramsPtr[T], R Result, T any](d typedServerMethodHandler[P, R], flags methodFlags) methodInfo {
233233
mi := newMethodInfo[P, R](flags)
234-
mi.newRequest = func(s Session, p Params, ti *auth.TokenInfo) Request {
235-
r := &ServerRequest[P]{Session: s.(*ServerSession), Extra: RequestExtra{TokenInfo: ti}}
234+
mi.newRequest = func(s Session, p Params, re *RequestExtra) Request {
235+
r := &ServerRequest[P]{Session: s.(*ServerSession), Extra: re}
236236
if p != nil {
237237
r.Params = p.(P)
238238
}
@@ -395,7 +395,7 @@ type ClientRequest[P Params] struct {
395395
type ServerRequest[P Params] struct {
396396
Session *ServerSession
397397
Params P
398-
Extra RequestExtra
398+
Extra *RequestExtra
399399
}
400400

401401
// RequestExtra is extra information included in requests, typically from

mcp/streamable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func (c *streamableServerConn) servePOST(w http.ResponseWriter, req *http.Reques
511511
http.Error(w, err.Error(), http.StatusBadRequest)
512512
return
513513
}
514-
req.Extra = tokenInfo
514+
req.Extra = &RequestExtra{TokenInfo: tokenInfo}
515515
if req.ID.IsValid() {
516516
requests[req.ID] = struct{}{}
517517
}

mcp/streamable_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ func TestTokenInfo(t *testing.T) {
10471047

10481048
// Create a server with a tool that returns TokenInfo.
10491049
tokenInfo := func(ctx context.Context, req *ServerRequest[*CallToolParamsFor[struct{}]]) (*CallToolResultFor[any], error) {
1050-
return &CallToolResultFor[any]{Content: []Content{&TextContent{Text: fmt.Sprintf("%v", req.TokenInfo)}}}, nil
1050+
return &CallToolResultFor[any]{Content: []Content{&TextContent{Text: fmt.Sprintf("%v", req.Extra.TokenInfo)}}}, nil
10511051
}
10521052
server := NewServer(testImpl, nil)
10531053
AddTool(server, &Tool{Name: "tokenInfo", Description: "return token info"}, tokenInfo)

mcp/tool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func newServerTool[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*serverTool
6666
}
6767
// TODO(jba): improve copy
6868
res, err := h(ctx, &ServerRequest[*CallToolParamsFor[In]]{
69-
Session: req.Session,
70-
Params: params,
71-
TokenInfo: req.TokenInfo,
69+
Session: req.Session,
70+
Params: params,
71+
Extra: req.Extra,
7272
})
7373
// TODO(rfindley): investigate why server errors are embedded in this strange way,
7474
// rather than returned as jsonrpc2 server errors.

mcp/transport.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ type serverConnection interface {
8686

8787
// A StdioTransport is a [Transport] that communicates over stdin/stdout using
8888
// newline-delimited JSON.
89-
type StdioTransport struct {
90-
}
89+
type StdioTransport struct{}
9190

9291
// Connect implements the [Transport] interface.
9392
func (*StdioTransport) Connect(context.Context) (Connection, error) {

0 commit comments

Comments
 (0)