Documentation
¶
Index ¶
- Constants
- func RegisterHealthRoutes(routerAPI huma.API, monitor contracts.MCPHealthMonitor, apiPathPrefix string)
- func RegisterPromptRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
- func RegisterResourceRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
- func RegisterRoutes(router huma.API, healthTracker contracts.MCPHealthMonitor, ...) (string, error)
- func RegisterServerRoutes(routerAPI huma.API, accessor contracts.MCPClientAccessor, apiPathPrefix string)
- func RegisterToolRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
- func Transformers() []huma.Transformer
- type Convertible
- type DomainMeta
- type DomainPrompt
- type DomainPromptArgument
- type DomainPromptMessage
- type DomainResource
- type DomainResourceTemplate
- type DomainServerHealth
- type ErrorType
- type GeneratePromptResponse
- type HealthStatus
- type JSONSchema
- type Meta
- type Prompt
- type PromptArgument
- type PromptGenerateArguments
- type PromptMessage
- type Prompts
- type PromptsListResponse
- type Resource
- type ResourceContent
- type ResourceContentResponse
- type ResourceTemplate
- type ResourceTemplates
- type ResourceTemplatesResponse
- type Resources
- type ResourcesResponse
- type ServerHealth
- type ServerHealthRequest
- type ServerHealthResponse
- type ServerPromptGenerateRequest
- type ServerPromptsListRequest
- type ServerResourceContentRequest
- type ServerResourceTemplatesRequest
- type ServerResourcesRequest
- type ServerToolCallRequest
- type ServerToolsRequest
- type ServersHealth
- type ServersHealthResponse
- type ServersResponse
- type Tool
- type ToolAnnotations
- type ToolCallResponse
- type ToolMinimal
- type ToolSummary
- type ToolView
- type ToolsResponse
- type ToolsResponseBody
Constants ¶
const APIVersion = "v1"
APIVersion is the version used in the OpenAPI spec and URL paths.
const HeaderErrorType = "Mcpd-Error-Type"
HeaderErrorType is the HTTP header key which should be used to convey API error types.
Variables ¶
This section is empty.
Functions ¶
func RegisterHealthRoutes ¶
func RegisterHealthRoutes(routerAPI huma.API, monitor contracts.MCPHealthMonitor, apiPathPrefix string)
RegisterHealthRoutes sets up health-related API endpoint routes.
func RegisterPromptRoutes ¶
func RegisterPromptRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
RegisterPromptRoutes registers prompt-related routes under the servers API.
func RegisterResourceRoutes ¶
func RegisterResourceRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
RegisterResourceRoutes registers resource-related routes under the servers API.
func RegisterRoutes ¶
func RegisterRoutes( router huma.API, healthTracker contracts.MCPHealthMonitor, clientManager contracts.MCPClientAccessor, ) (string, error)
RegisterRoutes registers all API routes on the provided Huma router. This is the single source of truth for the API route structure. Returns the API path prefix (e.g., "/api/v1") under which the routes are created.
func RegisterServerRoutes ¶
func RegisterServerRoutes(routerAPI huma.API, accessor contracts.MCPClientAccessor, apiPathPrefix string)
RegisterServerRoutes sets up health-related API endpoints
func RegisterToolRoutes ¶
func RegisterToolRoutes(parentAPI huma.API, accessor contracts.MCPClientAccessor)
func Transformers ¶
func Transformers() []huma.Transformer
Transformers returns all response transformers used by the API. Transformers modify responses after handlers execute but before serialization. They are registered globally in the Huma config and run on all API responses.
IMPORTANT: Order matters. Transformers execute sequentially, with each transformer's output becoming the next transformer's input. If you need to compose transformations, ensure they are ordered correctly in the returned slice.
Each transformer should be defensive and check response types before operating, passing through responses it doesn't handle.
Current transformers:
- toolFieldSelectTransformer: Filters tool responses based on ?detail= query parameter.
Types ¶
type Convertible ¶
type DomainMeta ¶
DomainMeta wraps mcp.Meta for API conversion.
func (DomainMeta) ToAPIType ¶
func (d DomainMeta) ToAPIType() (Meta, error)
ToAPIType converts a domain meta to an API meta type. This creates a flat _meta object structure as defined by the MCP specification. Returns empty Meta{} if domain type is nil. See: https://modelcontextprotocol.io/specification/2025-06-18/basic/index#meta
type DomainPrompt ¶
DomainPrompt wraps mcp.Prompt for API conversion.
func (DomainPrompt) ToAPIType ¶
func (d DomainPrompt) ToAPIType() (Prompt, error)
ToAPIType converts a domain prompt to an API prompt.
type DomainPromptArgument ¶
type DomainPromptArgument mcp.PromptArgument
DomainPromptArgument wraps mcp.PromptArgument for API conversion.
func (DomainPromptArgument) ToAPIType ¶
func (d DomainPromptArgument) ToAPIType() (PromptArgument, error)
ToAPIType converts a domain prompt argument to an API prompt argument.
type DomainPromptMessage ¶
type DomainPromptMessage mcp.PromptMessage
DomainPromptMessage wraps mcp.PromptMessage for API conversion.
func (DomainPromptMessage) ToAPIType ¶
func (d DomainPromptMessage) ToAPIType() (PromptMessage, error)
ToAPIType converts a domain prompt message to an API prompt message.
type DomainResource ¶
DomainResource wraps mcp.Resource for API conversion.
func (DomainResource) ToAPIType ¶
func (d DomainResource) ToAPIType() (Resource, error)
ToAPIType converts a domain resource to an API resource.
type DomainResourceTemplate ¶
type DomainResourceTemplate mcp.ResourceTemplate
DomainResourceTemplate wraps mcp.ResourceTemplate for API conversion.
func (DomainResourceTemplate) ToAPIType ¶
func (d DomainResourceTemplate) ToAPIType() (ResourceTemplate, error)
ToAPIType converts a domain resource template to an API resource template.
type DomainServerHealth ¶
type DomainServerHealth domain.ServerHealth
DomainServerHealth is a wrapper that allows receivers to be declared in the API package that deal with domain types.
func (DomainServerHealth) ToAPIType ¶
func (d DomainServerHealth) ToAPIType() (ServerHealth, error)
ToAPIType can be used to convert a wrapped domain type to an API-safe type.
type ErrorType ¶
type ErrorType string
ErrorType represents the classification of errors returned via HTTP headers.
const ( // PipelineRequestFailure indicates a required plugin or processing step failed during request handling. PipelineRequestFailure ErrorType = "request-pipeline-failure" // PipelineResponseFailure indicates a required plugin or processing step failed during response handling. PipelineResponseFailure ErrorType = "response-pipeline-failure" )
type GeneratePromptResponse ¶
type GeneratePromptResponse struct {
Body struct {
// Description for the prompt.
Description string `json:"description,omitempty"`
// Messages that make up the prompt.
Messages []PromptMessage `json:"messages"`
}
}
GeneratePromptResponse represents the API response for generating a prompt from a template.
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the current status of a particular MCP server when establishing its health.
const ( HealthStatusOK HealthStatus = "ok" HealthStatusTimeout HealthStatus = "timeout" HealthStatusUnreachable HealthStatus = "unreachable" HealthStatusUnknown HealthStatus = "unknown" )
type JSONSchema ¶
type JSONSchema struct {
// Type defines the type for this schema, e.g. "object".
Type string `json:"type"`
// Properties represents a property name and associated object definition.
Properties map[string]any `json:"properties,omitempty"`
// Required lists the (keys of) Properties that are required.
Required []string `json:"required,omitempty"`
}
JSONSchema defines the structure for a JSON schema object.
type Prompt ¶
type Prompt struct {
// Name of the prompt or prompt template.
Name string `json:"name"`
// Description of what this prompt provides.
Description string `json:"description,omitempty"`
// Arguments for templating the prompt.
Arguments []PromptArgument `json:"arguments,omitempty"`
// Meta is reserved by MCP to allow clients and servers to attach additional metadata.
Meta Meta `json:"_meta,omitempty"` //nolint:tagliatelle
}
Prompt represents a prompt or prompt template that the server offers.
type PromptArgument ¶
type PromptArgument struct {
// Name of the argument.
Name string `json:"name"`
// Description of the argument.
Description string `json:"description,omitempty"`
// Whether this argument must be provided.
Required bool `json:"required,omitempty"`
}
PromptArgument describes an argument that a prompt template can accept.
type PromptGenerateArguments ¶
type PromptGenerateArguments struct {
Arguments map[string]string `doc:"Arguments for templating the prompt" json:"arguments,omitempty"`
}
PromptGenerateArguments contains arguments for generating a prompt from a template.
type PromptMessage ¶
type PromptMessage struct {
// Role of the message sender.
Role string `json:"role"`
// Content can be text, image, audio, or embedded resource.
Content interface{} `json:"content"`
}
PromptMessage describes a message returned as part of a prompt.
type Prompts ¶
type Prompts struct {
Prompts []Prompt `json:"prompts"`
NextCursor string `json:"nextCursor,omitempty"`
}
Prompts represents a collection of Prompt types.
type PromptsListResponse ¶
type PromptsListResponse struct {
Body Prompts
}
PromptsListResponse represents the wrapped API response for listing Prompts.
type Resource ¶
type Resource struct {
// URI of this resource.
URI string `json:"uri"`
// Name is a human-readable name for this resource.
Name string `json:"name"`
// Description of what this resource represents.
Description string `json:"description,omitempty"`
// MIMEType of this resource, if known.
MIMEType string `json:"mimeType,omitempty"`
// Meta is reserved by MCP to allow clients and servers to attach additional metadata.
Meta Meta `json:"_meta,omitempty"` //nolint:tagliatelle
}
Resource represents a known resource.
type ResourceContent ¶
type ResourceContent struct {
// URI of this resource.
URI string `json:"uri"`
// MIMEType of this resource, if known.
MIMEType string `json:"mimeType,omitempty"`
// Text content (for text resources).
Text string `json:"text,omitempty"`
// Blob content (base64 encoded binary data).
Blob string `json:"blob,omitempty"`
// Meta is reserved by MCP to allow clients and servers to attach additional metadata.
Meta Meta `json:"_meta,omitempty"` //nolint:tagliatelle
}
ResourceContent represents the content of a resource.
type ResourceContentResponse ¶
type ResourceContentResponse struct {
Body []ResourceContent
}
ResourceContentResponse represents the wrapped API response for getting resource content.
type ResourceTemplate ¶
type ResourceTemplate struct {
// URITemplate is a URI template (RFC 6570) for constructing resource URIs.
URITemplate string `json:"uriTemplate"`
// Name is a human-readable name for the type of resource this template refers to.
Name string `json:"name"`
// Description of what this template is for.
Description string `json:"description,omitempty"`
// MIMEType for all resources that match this template.
MIMEType string `json:"mimeType,omitempty"`
// Meta is reserved by MCP to allow clients and servers to attach additional metadata.
Meta Meta `json:"_meta,omitempty"` //nolint:tagliatelle
}
ResourceTemplate represents a resource template.
type ResourceTemplates ¶
type ResourceTemplates struct {
Templates []ResourceTemplate `json:"templates"`
NextCursor string `json:"nextCursor,omitempty"`
}
ResourceTemplates represents a collection of ResourceTemplate types.
type ResourceTemplatesResponse ¶
type ResourceTemplatesResponse struct {
Body ResourceTemplates
}
ResourceTemplatesResponse represents the wrapped API response for ResourceTemplates.
type Resources ¶
type Resources struct {
Resources []Resource `json:"resources"`
NextCursor string `json:"nextCursor,omitempty"`
}
Resources represents a collection of Resource types.
type ResourcesResponse ¶
type ResourcesResponse struct {
Body Resources
}
ResourcesResponse represents the wrapped API response for Resources.
type ServerHealth ¶
type ServerHealth struct {
Name string `json:"name"`
Status HealthStatus `json:"status"`
Latency *string `json:"latency,omitempty"`
LastChecked *time.Time `json:"lastChecked,omitempty"`
LastSuccessful *time.Time `json:"lastSuccessful,omitempty"`
}
ServerHealth is used to provide information about ongoing health checks that are performed on running MCP servers.
type ServerHealthRequest ¶
type ServerHealthRequest struct {
Name string `doc:"Name of the server to check" example:"time" path:"name"`
}
ServerHealthRequest represents the incoming request for obtaining ServerHealth.
type ServerHealthResponse ¶
type ServerHealthResponse struct {
Body ServerHealth
}
ServerHealthResponse represents the wrapped API response for a ServerHealth.
type ServerPromptGenerateRequest ¶
type ServerPromptGenerateRequest struct {
ServerName string `doc:"Name of the server" path:"name"`
PromptName string `doc:"Name of the prompt" path:"promptName"`
Body PromptGenerateArguments `doc:"Prompt arguments"`
}
ServerPromptGenerateRequest represents the incoming API request for generating a prompt.
type ServerPromptsListRequest ¶
type ServerPromptsListRequest struct {
Name string `doc:"Name of the server" path:"name"`
Cursor string `doc:"Pagination cursor" query:"cursor"`
}
ServerPromptsListRequest represents the incoming API request for listing prompts.
type ServerResourceContentRequest ¶
type ServerResourceContentRequest struct {
Name string `doc:"Name of the server" path:"name"`
URI string `doc:"URI of the resource" query:"uri"`
}
ServerResourceContentRequest represents the incoming API request for getting resource content.
type ServerResourceTemplatesRequest ¶
type ServerResourceTemplatesRequest struct {
Name string `doc:"Name of the server" path:"name"`
Cursor string `doc:"Pagination cursor" query:"cursor"`
}
ServerResourceTemplatesRequest represents the incoming API request for listing resource templates.
type ServerResourcesRequest ¶
type ServerResourcesRequest struct {
Name string `doc:"Name of the server" path:"name"`
Cursor string `doc:"Pagination cursor" query:"cursor"`
}
ServerResourcesRequest represents the incoming API request for listing resources.
type ServerToolCallRequest ¶
type ServerToolCallRequest struct {
Server string `doc:"Name of the server" example:"time" path:"server"`
Tool string `doc:"Name of the tool to call" example:"get_current_time" path:"tool"`
Body map[string]any `doc:"Body of the tool to call" path:"body"`
}
ServerToolCallRequest represents the incoming API request to call a tool on a particular server.
type ServerToolsRequest ¶
type ServerToolsRequest struct {
Name string `doc:"Name of the server to lookup tools for" example:"time" path:"name"`
// Detail specifies the level of detail to return (minimal, summary, or full).
// NOTE: This field is not used by the handler itself; it exists solely for OpenAPI documentation.
// The actual filtering is performed by toolFieldSelectTransformer, which reads the query parameter directly.
Detail toolDetailLevel `default:"full" doc:"Level of detail to return" enum:"minimal,summary,full" query:"detail"`
}
ServerToolsRequest represents the incoming API request for giving the configured tools schemas for a server.
type ServersHealth ¶
type ServersHealth struct {
Servers []ServerHealth `json:"servers"`
}
ServersHealth represents a collection of ServerHealth.
type ServersHealthResponse ¶
type ServersHealthResponse struct {
Body struct {
Servers []ServerHealth `doc:"Tracked MCP server health statuses" json:"servers"`
}
}
ServersHealthResponse is the response for GET /health
type ServersResponse ¶
type ServersResponse struct {
Body []string
}
ServersResponse represents the wrapped API response for a list of servers.
type Tool ¶
type Tool struct {
ToolSummary
// InputSchema is JSONSchema defining the expected parameters for the tool.
InputSchema *JSONSchema `doc:"Input parameters schema" json:"inputSchema,omitempty"`
// OutputSchema is an optional JSONSchema defining the structure of the tool's
// output returned in the structured content field of a tool call result.
OutputSchema *JSONSchema `doc:"Output structure schema" json:"outputSchema,omitempty"`
// Annotations provide optional additional tool information.
// Display name precedence order is: title, annotations.title when present, then tool name.
Annotations *ToolAnnotations `doc:"Additional hints about the tool" json:"annotations,omitempty"`
// Meta is reserved by MCP to allow clients and servers to attach additional metadata to their interactions.
// See https://modelcontextprotocol.io/specification/2025-06-18/basic#general-fields for notes on _meta usage.
Meta map[string]any `doc:"Additional metadata" json:"_meta,omitempty"` //nolint:tagliatelle
}
Tool represents complete tool information including all schemas and annotations. This embeds ToolSummary (which embeds ToolMinimal) providing a full tool definition.
type ToolAnnotations ¶
type ToolAnnotations struct {
// Title is a human-readable title for the tool.
Title *string `json:"title,omitempty"`
// ReadOnlyHint if true, the tool should not modify its environment.
ReadOnlyHint *bool `json:"readOnlyHint,omitempty"`
// DestructiveHint if true, the tool may perform destructive updates to its environment.
// If false, the tool performs only additive updates.
// (This property is meaningful only when ReadOnlyHint is false)
DestructiveHint *bool `json:"destructiveHint,omitempty"`
// IdempotentHint if true, calling the tool repeatedly with the same arguments
// will have no additional effect on its environment.
// (This property is meaningful only when ReadOnlyHint is false)
IdempotentHint *bool `json:"idempotentHint,omitempty"`
// OpenWorldHint if true, this tool may interact with an "open world" of external
// entities. If false, the tool's domain of interaction is closed.
// For example, the world of a web search tool is open, whereas that
// of a memory tool is not.
OpenWorldHint *bool `json:"openWorldHint,omitempty"`
}
ToolAnnotations provides additional properties describing a Tool to clients. NOTE: all properties in ToolAnnotations are **hints**. They are not guaranteed to provide a faithful description of tool behavior (including descriptive properties like `title`). Clients should never make tool use decisions based on ToolAnnotations received from untrusted servers.
func (*ToolAnnotations) IsZero ¶
func (a *ToolAnnotations) IsZero() bool
IsZero reports whether the ToolAnnotations struct has no meaningful values set. This is useful to avoid emitting empty "annotations" objects in JSON output.
type ToolCallResponse ¶
type ToolCallResponse struct {
Body string
}
ToolCallResponse represents the wrapped API response for calling a tool.
type ToolMinimal ¶
type ToolMinimal struct {
// Name of the tool.
Name string `doc:"Name of the tool" json:"name"`
// Title is a human-readable and easily understood title for the tool.
Title string `doc:"Human-readable title" json:"title,omitempty"`
}
ToolMinimal represents minimal tool information with name and title only.
type ToolSummary ¶
type ToolSummary struct {
ToolMinimal
// Description is a human-readable description of the tool.
// This can be used by clients to improve the LLM's understanding of available tools.
// It can be thought of like a "hint" to the model.
Description string `doc:"Description of what the tool does" json:"description"`
}
ToolSummary represents summary tool information including name, title, and description.
type ToolView ¶
type ToolView interface {
ToolMinimal | ToolSummary | Tool
}
ToolView is a union constraint for all tool view types. This ensures type safety when using generic ToolsResponse.
type ToolsResponse ¶
type ToolsResponse[T ToolView] struct { Body ToolsResponseBody[T] }
ToolsResponse represents a generic wrapped API response for tool collections. The type parameter T must be one of the ToolView types (ToolMinimal, ToolSummary, or Tool).
type ToolsResponseBody ¶
type ToolsResponseBody[T ToolView] struct { Tools []T `json:"tools"` }
ToolsResponseBody represents the body of a tools response.