Core types used throughout the MCP protocol for tools, prompts, resources, and content.
Content represents data exchanged in MCP messages. Multiple content types support different media.
Base interface for all content types.
import "github.com/modelcontextprotocol/go-sdk/mcp"
type Content interface {
MarshalJSON() ([]byte, error)
}All content types implement this interface: TextContent, ImageContent, AudioContent, ResourceLink, and EmbeddedResource.
Represents textual content.
type TextContent struct {
Text string
Meta Meta
Annotations *Annotations
}Example:
content := &mcp.TextContent{
Text: "Hello, world!",
Annotations: &mcp.Annotations{
Priority: 0.8,
},
}Contains base64-encoded image data.
type ImageContent struct {
Meta Meta
Annotations *Annotations
Data []byte
MIMEType string
}Example:
content := &mcp.ImageContent{
Data: imageBytes, // base64-encoded
MIMEType: "image/png",
}Contains base64-encoded audio data.
type AudioContent struct {
Data []byte
MIMEType string
Meta Meta
Annotations *Annotations
}Example:
content := &mcp.AudioContent{
Data: audioBytes, // base64-encoded
MIMEType: "audio/mpeg",
}A link to a resource.
type ResourceLink struct {
URI string
Name string
Title string
Description string
MIMEType string
Size *int64
Meta Meta
Annotations *Annotations
}Example:
size := int64(1024)
content := &mcp.ResourceLink{
URI: "file:///path/to/file.txt",
Name: "file",
Description: "A text file",
MIMEType: "text/plain",
Size: &size,
}Contains embedded resource data.
type EmbeddedResource struct {
Resource *ResourceContents
Meta Meta
Annotations *Annotations
}The contents of a specific resource or sub-resource.
type ResourceContents struct {
URI string `json:"uri"`
MIMEType string `json:"mimeType,omitempty"`
Text string `json:"text,omitempty"`
Blob []byte `json:"blob,omitempty"`
Meta Meta `json:"_meta,omitempty"`
}Fields:
URI: Resource URI (required)MIMEType: MIME type of the contentText: Text content (mutually exclusive with Blob)Blob: Binary content (mutually exclusive with Text)Meta: Reserved metadataExample:
contents := &mcp.ResourceContents{
URI: "file:///data/users.json",
MIMEType: "application/json",
Text: `{"users": []}`,
}Optional annotations for content and resources.
type Annotations struct {
Audience []Role `json:"audience,omitempty"`
LastModified string `json:"lastModified,omitempty"`
Priority float64 `json:"priority,omitempty"`
}Fields:
Audience: Intended audience (e.g., "user", "assistant")LastModified: ISO 8601 timestamp of last modificationPriority: Importance from 0 (least) to 1 (most important)The sender or recipient in a conversation.
type Role stringCommon values: "user", "assistant"
Additional metadata for requests, responses, and other types.
type Meta map[string]anyMethods:
func (m Meta) GetMeta() map[string]any
func (m Meta) SetMeta(x map[string]any)Definition for a tool that clients can call.
type Tool struct {
Meta `json:"_meta,omitempty"`
Annotations *ToolAnnotations `json:"annotations,omitempty"`
Description string `json:"description,omitempty"`
InputSchema any `json:"inputSchema"`
Name string `json:"name"`
OutputSchema any `json:"outputSchema,omitempty"`
Title string `json:"title,omitempty"`
}Fields:
Meta: Reserved metadata fieldAnnotations: Additional tool information and hintsDescription: Human-readable descriptionInputSchema: JSON Schema object defining expected parametersName: Programmatic identifierOutputSchema: Optional JSON Schema for tool outputTitle: Human-readable title for UI contextsExample:
tool := &mcp.Tool{
Name: "calculate",
Description: "Performs basic arithmetic",
Title: "Calculator",
InputSchema: map[string]any{
"type": "object",
"properties": map[string]any{
"operation": map[string]any{"type": "string"},
"x": map[string]any{"type": "number"},
"y": map[string]any{"type": "number"},
},
"required": []string{"operation", "x", "y"},
},
}Additional properties describing a tool to clients (all are hints).
type ToolAnnotations struct {
DestructiveHint *bool `json:"destructiveHint,omitempty"`
IdempotentHint bool `json:"idempotentHint,omitempty"`
OpenWorldHint *bool `json:"openWorldHint,omitempty"`
ReadOnlyHint bool `json:"readOnlyHint,omitempty"`
Title string `json:"title,omitempty"`
}Fields:
DestructiveHint: If true, tool may perform destructive updates (default: true)IdempotentHint: If true, repeated calls with same args have no additional effect (default: false)OpenWorldHint: If true, tool may interact with external entities (default: true)ReadOnlyHint: If true, tool does not modify its environment (default: false)Title: Human-readable titleA prompt or prompt template that the server offers.
type Prompt struct {
Meta `json:"_meta,omitempty"`
Arguments []*PromptArgument `json:"arguments,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
Title string `json:"title,omitempty"`
}Fields:
Meta: Reserved metadata fieldArguments: Arguments for templating the promptDescription: What this prompt providesName: Programmatic identifierTitle: Human-readable title for UI contextsExample:
prompt := &mcp.Prompt{
Name: "code-review",
Description: "Reviews code for quality and style",
Arguments: []*mcp.PromptArgument{
{Name: "language", Description: "Programming language", Required: true},
{Name: "code", Description: "Code to review", Required: true},
},
}Describes an argument that a prompt can accept.
type PromptArgument struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}Fields:
Name: Programmatic identifierTitle: Human-readable title for UI contextsDescription: Human-readable descriptionRequired: Whether this argument must be providedDescribes a message returned as part of a prompt.
type PromptMessage struct {
Content Content `json:"content"`
Role Role `json:"role"`
}Example:
message := &mcp.PromptMessage{
Role: "user",
Content: &mcp.TextContent{
Text: "Review this code for issues",
},
}A known resource that the server is capable of reading.
type Resource struct {
Meta `json:"_meta,omitempty"`
Annotations *Annotations `json:"annotations,omitempty"`
Description string `json:"description,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
Name string `json:"name"`
Size int64 `json:"size,omitempty"`
Title string `json:"title,omitempty"`
URI string `json:"uri"`
}Fields:
Meta: Reserved metadata fieldAnnotations: Optional annotations for the clientDescription: What this resource representsMIMEType: MIME type if knownName: Programmatic identifierSize: Size in bytesTitle: Human-readable title for UI contextsURI: URI of this resourceExample:
resource := &mcp.Resource{
URI: "file:///data/logs.txt",
Name: "logs",
Description: "Application logs",
MIMEType: "text/plain",
Size: 1024000,
}A template description for resources available on the server.
type ResourceTemplate struct {
Meta `json:"_meta,omitempty"`
Annotations *Annotations `json:"annotations,omitempty"`
Description string `json:"description,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
Name string `json:"name"`
Title string `json:"title,omitempty"`
URITemplate string `json:"uriTemplate"`
}Fields:
Meta: Reserved metadata fieldAnnotations: Optional annotationsDescription: What this template is forMIMEType: MIME type for matching resourcesName: Programmatic identifierTitle: Human-readable title for UI contextsURITemplate: URI template according to RFC 6570Example:
template := &mcp.ResourceTemplate{
URITemplate: "file:///data/{year}/{month}/{day}.log",
Name: "daily-logs",
Description: "Daily application logs",
MIMEType: "text/plain",
}Describes a message issued to or received from an LLM API.
type SamplingMessage struct {
Content Content `json:"content"`
Role Role `json:"role"`
}Server preferences for model selection during sampling.
type ModelPreferences struct {
CostPriority float64 `json:"costPriority,omitempty"`
Hints []*ModelHint `json:"hints,omitempty"`
IntelligencePriority float64 `json:"intelligencePriority,omitempty"`
SpeedPriority float64 `json:"speedPriority,omitempty"`
}Fields:
CostPriority: Prioritize cost (0-1)Hints: Optional model selection hintsIntelligencePriority: Prioritize intelligence (0-1)SpeedPriority: Prioritize speed (0-1)Hints to use for model selection.
type ModelHint struct {
Name string `json:"name,omitempty"`
}Base interface for parameter types.
type Params interface {
GetMeta() map[string]any
SetMeta(map[string]any)
}Interface for request parameter types.
type RequestParams interface {
GetMeta() map[string]any
SetMeta(map[string]any)
GetProgressToken() any
SetProgressToken(any)
}Base interface for result types.
type Result interface {
GetMeta() map[string]any
SetMeta(map[string]any)
}Interface implemented by ClientSession and ServerSession.
type Session interface {
ID() string
}Interface for request types.
type Request interface {
GetSession() Session
GetParams() Params
GetExtra() *RequestExtra
}Extra information included in requests from the transport layer.
type RequestExtra struct {
TokenInfo *auth.TokenInfo
Header http.Header
}Fields:
TokenInfo: Bearer token info from OAuth if anyHeader: HTTP header from request if anyGeneric request type for client requests.
type ClientRequest[P Params] struct {
Session *ClientSession
Params P
}Methods:
func (r *ClientRequest[P]) GetExtra() *RequestExtra
func (r *ClientRequest[P]) GetParams() Params
func (r *ClientRequest[P]) GetSession() SessionGeneric request type for server requests.
type ServerRequest[P Params] struct {
Session *ServerSession
Params P
Extra *RequestExtra
}Methods:
func (r *ServerRequest[P]) GetExtra() *RequestExtra
func (r *ServerRequest[P]) GetParams() Params
func (r *ServerRequest[P]) GetSession() SessionDescribes the name and version of an MCP implementation.
type Implementation struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Version string `json:"version"`
}Fields:
Name: Programmatic identifierTitle: Human-readable title for UI contextsVersion: Version stringThe severity of a log message (maps to syslog severities per RFC-5424).
type LoggingLevel stringconst (
LevelDebug = slog.LevelDebug
LevelInfo = slog.LevelInfo
LevelNotice = (slog.LevelInfo + slog.LevelWarn) / 2
LevelWarning = slog.LevelWarn
LevelError = slog.LevelError
LevelCritical = slog.LevelError + 4
LevelAlert = slog.LevelError + 8
LevelEmergency = slog.LevelError + 12
)Parameters for progress notifications.
type ProgressNotificationParams struct {
Meta `json:"_meta,omitempty"`
ProgressToken any `json:"progressToken"`
Message string `json:"message,omitempty"`
Progress float64 `json:"progress"`
Total float64 `json:"total,omitempty"`
}Fields:
Meta: Reserved metadata fieldProgressToken: Token from the initial requestMessage: Optional progress descriptionProgress: Progress thus farTotal: Total items to process (0 = unknown)Additional context for completions.
type CompleteContext struct {
Arguments map[string]string `json:"arguments,omitempty"`
}A completion reference type (ref/prompt or ref/resource).
type CompleteReference struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
URI string `json:"uri,omitempty"`
}Fields:
Type: Reference type ("ref/prompt" or "ref/resource")Name: Relevant when Type is "ref/prompt"URI: Relevant when Type is "ref/resource"Details of a completion result.
type CompletionResultDetails struct {
HasMore bool `json:"hasMore,omitempty"`
Total int `json:"total,omitempty"`
Values []string `json:"values"`
}