Documentation
¶
Index ¶
- Constants
- func HTTPClientFromContext(ctx context.Context) *http.Client
- func IsValidHttpMethod(method string) bool
- func WithHTTPClient(ctx context.Context, client *http.Client) context.Context
- func WithHTTPClientMiddleware(client *http.Client) mcp.Middleware
- type HttpInvocationConfig
- type HttpInvoker
- func (hi *HttpInvoker) Invoke(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (hi *HttpInvoker) InvokePrompt(ctx context.Context, req *mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (hi *HttpInvoker) InvokeResource(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- func (hi *HttpInvoker) InvokeResourceTemplate(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
- type InvokerFactory
Constants ¶
View Source
const (
InvocationType = "http"
)
Variables ¶
This section is empty.
Functions ¶
func HTTPClientFromContext ¶ added in v0.2.3
HTTPClientFromContext retrieves the HTTP client from the context. If no client is found, it returns http.DefaultClient.
func IsValidHttpMethod ¶
func WithHTTPClient ¶ added in v0.2.3
WithHTTPClient stores an HTTP client in the context. This client will be used by HTTP invokers for outbound requests.
func WithHTTPClientMiddleware ¶ added in v0.2.3
func WithHTTPClientMiddleware(client *http.Client) mcp.Middleware
WithHTTPClientMiddleware creates an MCP middleware that injects a configured HTTP client into the request context. This client is used by HTTP invokers for outbound requests and can be configured with custom CA certificates. If client is nil, http.DefaultClient will be used.
Types ¶
type HttpInvocationConfig ¶
type HttpInvocationConfig struct {
// The URL for the HTTP request.
//
// It can contain placeholders in the form of {paramName} which correspond to parameters from the input schema.
// It can contain placeholders in the form of {headers.paramName} which correspond to headers from the incoming
// http request (won't work in stdio).
// It can contain placeholders in the form of ${ENV_VAR_NAME} or {env.ENV_VAR_NAME} which correspond to env vars
URL string `json:"url,omitempty" jsonschema:"required"` // even though this is required for the type, we don't require it on every nested extends instance of this struct, so we have omitempty
// The headers for the HTTP request.
//
// Values can contain placeholders in the form of {paramName} which correspond to parameters from the input schema.
// Values can contain placeholders in the form of {headers.paramName} which correspond to headers from the incoming
// http request (won't work in stdio).
// Values can contain placeholders in the form of ${ENV_VAR_NAME} or {env.ENV_VAR_NAME} which correspond to env vars
Headers map[string]string `json:"headers,omitempty" jsonschema:"optional"`
// The HTTP method to be used for the request (e.g., "GET", "POST").
Method string `json:"method,omitempty" jsonschema:"required,enum=GET,enum=POST,enum=PUT,enum=PATCH,enum=DELETE,enum=HEAD"`
// BodyRoot specifies a dot-separated path to a property whose value should be used as the HTTP request body.
// This allows sending non-object request bodies, despite MCP requiring all tool call params to be rooted in
// a top-level object.
// Mutually exclusive with BodyAsArray
BodyRoot string `json:"bodyRoot,omitempty" jsonschema:"optional"`
// BodyAsArray wraps the entire request body into a JSON array.
// For example, if the arguments are {"name": "foo"}, the HTTP body will be [{"name": "foo"}].
// This is useful for APIs that expect array inputs but you want to expose a simpler single-item interface.
// Mutually exclusive with BodyRoot.
BodyAsArray bool `json:"bodyAsArray,omitempty" jsonschema:"optional"`
}
HttpInvocationConfig is the configuration for making an HTTP request. This is a pure data structure with no parsing logic - all struct tags only.
func (*HttpInvocationConfig) DeepCopy ¶ added in v0.1.1
func (hic *HttpInvocationConfig) DeepCopy() invocation.InvocationConfig
func (*HttpInvocationConfig) Validate ¶
func (hic *HttpInvocationConfig) Validate() error
type HttpInvoker ¶
type HttpInvoker struct {
ParsedTemplate *template.ParsedTemplate // Parsed template for the URL path
HeaderTemplates map[string]*template.ParsedTemplate // Parsed templates for the headers
Method string // Http request method
InputSchema *jsonschema.Resolved // InputSchema for the tool
URITemplate string // MCP URI template (for resource templates only)
BodyRoot string // Dot-separated path to extract as the request body
BodyAsArray bool // Wrap the entire body in a JSON array
}
func (*HttpInvoker) Invoke ¶
func (hi *HttpInvoker) Invoke(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)
func (*HttpInvoker) InvokePrompt ¶
func (hi *HttpInvoker) InvokePrompt(ctx context.Context, req *mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
func (*HttpInvoker) InvokeResource ¶
func (hi *HttpInvoker) InvokeResource(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
func (*HttpInvoker) InvokeResourceTemplate ¶
func (hi *HttpInvoker) InvokeResourceTemplate(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error)
type InvokerFactory ¶
type InvokerFactory struct{}
func (*InvokerFactory) CreateInvoker ¶
func (f *InvokerFactory) CreateInvoker(config invocation.InvocationConfig, primitive invocation.Primitive) (invocation.Invoker, error)
func (*InvokerFactory) NewConfig ¶ added in v0.1.1
func (f *InvokerFactory) NewConfig() invocation.InvocationConfig
Click to show internal directories.
Click to hide internal directories.