Skip to content

Commit 28b8d19

Browse files
committed
Switch this up to be more clear on what it's doing
1 parent 2824a8f commit 28b8d19

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pkg/github/server.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci
9898

9999
ghServer := NewServer(cfg.Version, serverOpts)
100100

101-
// We always want the GitHub API error middleware to run first so that any errors from the,
102-
// GitHub API are captured in the context for downstream middlewares and handlers, even if MCP parsing fails and prevents later middlewares from running.
103-
middlewareToInject := []mcp.Middleware{addGitHubAPIErrorToContext, InjectDepsMiddleware(deps)}
104-
middlewareToInject = append(middlewareToInject, middleware...)
105-
106-
// Add middlewares
107-
ghServer.AddReceivingMiddleware(middlewareToInject...)
101+
// Add middlewares. Order matters - for example, the error context middleware should be applied last so that it runs FIRST (closest to the handler) to ensure all errors are captured,
102+
// and any middleware that needs to read or modify the context should be before it.
103+
ghServer.AddReceivingMiddleware(middleware...)
104+
ghServer.AddReceivingMiddleware(InjectDepsMiddleware(deps))
105+
ghServer.AddReceivingMiddleware(addGitHubAPIErrorToContext)
108106

109107
if unrecognized := inv.UnrecognizedToolsets(); len(unrecognized) > 0 {
110108
cfg.Logger.Warn("Warning: unrecognized toolsets ignored", "toolsets", strings.Join(unrecognized, ", "))

0 commit comments

Comments
 (0)