-
Notifications
You must be signed in to change notification settings - Fork 169
Open
Labels
help wantedGood candidate for contribution. Comment first to say you're working on it.Good candidate for contribution. Comment first to say you're working on it.
Description
It would be useful to have a client example for connecting to a streamable http MCP server. A few items that would be great to include:
- TLS
- Auth / Custom Headers
- Middelware
While my basic usage may be wrong, I couldn't find a way to perform even a basic operation using StreamableClientTransport
without adding a RoundTripper to add req.Header.Set("Accept", "text/event-stream,application/json")
.
This seems like something the client should handle, so perhaps I'm using the package wrong (thus the thought that examples may help).
Here is my current (presumably incorrect) usage, which required the roundtripper to make any calls:
func (a *AIWorkerMCP) TestGitToolHandler(ctx context.Context) (*mcp.CallToolResult, error) {
client := mcp.NewClient(AIWorkerMCPImpl, &mcp.ClientOptions{})
session, err := client.Connect(ctx, &mcp.StreamableClientTransport{
Endpoint: a.getHost() + "/api/mcp/",
HTTPClient: customHTTPClient,
}, nil)
if err != nil {
return nil, err
}
defer session.Close()
return session.CallTool(ctx, &mcp.CallToolParams{
Name: "aiworkermcp-git",
Arguments: &GitToolArgs{
Repo: "git@someremote:somerepo.git",
SourceBranch: "development",
TargetBranch: "main",
},
})
}
type acceptHeaderRoundTripper struct {
delegate http.RoundTripper
}
func (rt *acceptHeaderRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("Accept", "text/event-stream,application/json")
return rt.delegate.RoundTrip(req)
}
var customHTTPClient = &http.Client{
Transport: &acceptHeaderRoundTripper{
delegate: http.DefaultTransport,
},
}
Metadata
Metadata
Assignees
Labels
help wantedGood candidate for contribution. Comment first to say you're working on it.Good candidate for contribution. Comment first to say you're working on it.