Add stateless http transport #59
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Context Support and Gin Transport
This PR adds support for passing context through the MCP transport layer and introduces a new Gin transport implementation. The changes enable better integration with web frameworks and middleware.
These new transports are stateless. Meaning that they dont support any functionality around sending notifications etc but can very easily be added to existing http servers.
Key Changes
Added context support throughout the transport layer:
Transport
interface to include context inSend
andSetMessageHandler
Added Gin transport implementation:
GinTransport
type that works with Gin's routerRefactored HTTP transports:
baseTransport
to share common functionality between HTTP and Gin transportsFixed client initialization:
Initialize
method to use empty map instead of nil for paramsExample Usage
Breaking Changes
Tool handler signature now supports context:
func(args Args) (*ToolResponse, error)
func(ctx context.Context, args Args) (*ToolResponse, error)
Transport interface changes:
Send
now takes a context parameterSetMessageHandler
callback now includes contextTesting