Files
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2bd709db63 build(deps): bump github.com/mark3labs/mcp-go from 0.37.0 to 0.43.0 (#5844)
Bumps [github.com/mark3labs/mcp-go](https://github.com/mark3labs/mcp-go) from 0.37.0 to 0.43.0.
- [Release notes](https://github.com/mark3labs/mcp-go/releases)
- [Commits](https://github.com/mark3labs/mcp-go/compare/v0.37.0...v0.43.0)

---
updated-dependencies:
- dependency-name: github.com/mark3labs/mcp-go
  dependency-version: 0.43.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-05 08:17:30 +00:00

75 lines
2.6 KiB
Go

package transport
import (
"context"
"encoding/json"
"net/http"
"github.com/mark3labs/mcp-go/mcp"
)
// HTTPHeaderFunc is a function that extracts header entries from the given context
// and returns them as key-value pairs. This is typically used to add context values
// as HTTP headers in outgoing requests.
type HTTPHeaderFunc func(context.Context) map[string]string
// Interface for the transport layer.
type Interface interface {
// Start the connection. Start should only be called once.
Start(ctx context.Context) error
// SendRequest sends a json RPC request and returns the response synchronously.
SendRequest(ctx context.Context, request JSONRPCRequest) (*JSONRPCResponse, error)
// SendNotification sends a json RPC Notification to the server.
SendNotification(ctx context.Context, notification mcp.JSONRPCNotification) error
// SetNotificationHandler sets the handler for notifications.
// Any notification before the handler is set will be discarded.
SetNotificationHandler(handler func(notification mcp.JSONRPCNotification))
// Close the connection.
Close() error
// GetSessionId returns the session ID of the transport.
GetSessionId() string
}
// RequestHandler defines a function that handles incoming requests from the server.
type RequestHandler func(ctx context.Context, request JSONRPCRequest) (*JSONRPCResponse, error)
// BidirectionalInterface extends Interface to support incoming requests from the server.
// This is used for features like sampling where the server can send requests to the client.
type BidirectionalInterface interface {
Interface
// SetRequestHandler sets the handler for incoming requests from the server.
// The handler should process the request and return a response.
SetRequestHandler(handler RequestHandler)
}
// HTTPConnection is a Transport that runs over HTTP and supports
// protocol version headers.
type HTTPConnection interface {
Interface
SetProtocolVersion(version string)
}
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID mcp.RequestId `json:"id"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
Header http.Header `json:"-"`
}
// JSONRPCResponse represents a JSON-RPC 2.0 response message.
// Use NewJSONRPCResultResponse to create a JSONRPCResponse with a result.
// Use NewJSONRPCErrorResponse to create a JSONRPCResponse with an error.
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID mcp.RequestId `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *mcp.JSONRPCErrorDetails `json:"error,omitempty"`
}