-
Notifications
You must be signed in to change notification settings - Fork 209
Description
Hello everyone. I’m developing a gateway for the company where I work, in which we will centralize several security rules, auditing, etc., so that this does not need to be replicated in different MCP applications. In this way, the gateway will have multiple servers and clients started, one for each destination.
The difficulty I’m having is using the headers received by a server at the moment of executing a client’s tool. Each path of my gateway points to a different Server and Client, so when the Server receives a request, it applies the validations and uses the client to call the tool, but because everything was started at startup, the request sent to the destination MCP will lack the necessary headers. Only the parameters are propagated, but I can’t pass the headers.
I’m trying something like this, but I’ve already tried using middleware and other approaches.
client := mcp.NewClient(&mcp.Implementation{Name: "A"}, &mcp.ClientOptions{})
clientSession, err := client.Connect(ctx, &mcp.StreamableClientTransport{....}, nil)
server := mcp.NewServer(&mcp.Implementation{...}, nil)
tools := clientSession.Tools(ctx, nil)
for tool, _ := range tools {
server.AddTool(tool, func(ctx context.Context, req *mcp.CallToolRequest) (*.mcp.CallToolResult, error) {
// GET HEADERS
return clientSession.CallTool(ctx, req.Params)
))
}
...
Is there a way to do this?