mcp: introduce Requests (#267)
Handlers and client/server methods take a single request argument combining the session and params. This slightly simplifies the signature for handlers, since there is no longer an often-ignored session argument. But more importantly, it opens the door to adding more information in requests, such as auth info and HTTP request headers. For #243.
This commit is contained in:
parent
e097918484
commit
6e03217c83
1 changed files with 517 additions and 380 deletions
|
|
@ -21,11 +21,11 @@ func Example_progressMiddleware() {
|
|||
_ = c
|
||||
}
|
||||
|
||||
func addProgressToken[S mcp.Session](h mcp.MethodHandler[S]) mcp.MethodHandler[S] {
|
||||
return func(ctx context.Context, s S, method string, params mcp.Params) (result mcp.Result, err error) {
|
||||
if rp, ok := params.(mcp.RequestParams); ok {
|
||||
func addProgressToken[S mcp.Session](h mcp.MethodHandler) mcp.MethodHandler {
|
||||
return func(ctx context.Context, method string, req mcp.Request) (result mcp.Result, err error) {
|
||||
if rp, ok := req.GetParams().(mcp.RequestParams); ok {
|
||||
rp.SetProgressToken(nextProgressToken.Add(1))
|
||||
}
|
||||
return h(ctx, s, method, params)
|
||||
return h(ctx, method, req)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue