Help us shape the future of Go! Take the 2026 Go Developer Survey

mcp

package
v0.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 1 Imported by: 21

Documentation

Overview

Package mcp is a drop-in compatibility shim for github.com/mark3labs/mcp-go/mcp.

It exists so that ToolHive and its sibling projects can migrate off mcp-go and onto the official Model Context Protocol Go SDK (github.com/modelcontextprotocol/go-sdk) by swapping imports rather than rewriting call sites: replace

github.com/mark3labs/mcp-go/mcp

with

github.com/stacklok/toolhive-core/mcpcompat/mcp

while keeping the existing import alias. The companion packages mcpcompat/server, mcpcompat/client and mcpcompat/client/transport reimplement mcp-go's protocol machinery on top of the official SDK; this package supplies the data types those APIs exchange.

Migration strategy

The types and helpers below are currently re-exported from mcp-go via type aliases and value assignments. This guarantees byte-for-byte wire and source compatibility during the transition: the aliased symbols ARE mcp-go's, so existing struct-literal construction, field access and custom JSON marshaling behave identically.

This file is the single chokepoint that still references mcp-go. The end goal is to remove the mcp-go dependency from the tree entirely. To get there, each alias here is replaced by a standalone definition (copied from the mcp-go source, same JSON tags and marshaling). Because consumers only ever see the symbols in this package, that swap is transparent to them. The wire-format golden tests in this package pin the exact JSON shape of every re-exported type and are what make the alias-to-standalone conversion safe.

Scope

Only the subset of mcp-go's mcp package that ToolHive actually uses is re-exported. Unused surface (sampling, roots, completion, tasks, logging-level control, the fluent schema builder beyond WithDescription/WithString/Required, etc.) is intentionally omitted and can be added on demand.

Stability: Alpha.

Index

Constants

View Source
const (
	MethodInitialize             = mcpgo.MethodInitialize
	MethodToolsList              = mcpgo.MethodToolsList
	MethodToolsCall              = mcpgo.MethodToolsCall
	MethodResourcesList          = mcpgo.MethodResourcesList
	MethodResourcesTemplatesList = mcpgo.MethodResourcesTemplatesList
	MethodResourcesRead          = mcpgo.MethodResourcesRead
	MethodPromptsList            = mcpgo.MethodPromptsList
	MethodPromptsGet             = mcpgo.MethodPromptsGet
	MethodListRoots              = mcpgo.MethodListRoots
	MethodSetLogLevel            = mcpgo.MethodSetLogLevel
	MethodPing                   = mcpgo.MethodPing
	MethodElicitationCreate      = mcpgo.MethodElicitationCreate

	// MethodNotificationInitialized indicates the client finished initialization.
	MethodNotificationInitialized = mcpgo.MethodNotificationInitialized
)

MCP method names.

View Source
const (
	PARSE_ERROR        = mcpgo.PARSE_ERROR
	INVALID_REQUEST    = mcpgo.INVALID_REQUEST
	METHOD_NOT_FOUND   = mcpgo.METHOD_NOT_FOUND
	INVALID_PARAMS     = mcpgo.INVALID_PARAMS
	INTERNAL_ERROR     = mcpgo.INTERNAL_ERROR
	RESOURCE_NOT_FOUND = mcpgo.RESOURCE_NOT_FOUND
)

JSON-RPC / MCP error codes.

View Source
const (
	RoleUser      = mcpgo.RoleUser
	RoleAssistant = mcpgo.RoleAssistant
)

Message roles.

View Source
const (
	ElicitationResponseActionAccept  = mcpgo.ElicitationResponseActionAccept
	ElicitationResponseActionDecline = mcpgo.ElicitationResponseActionDecline
	ElicitationResponseActionCancel  = mcpgo.ElicitationResponseActionCancel
)

Elicitation response actions.

View Source
const JSONRPC_VERSION = mcpgo.JSONRPC_VERSION

JSONRPC_VERSION is the JSON-RPC version used by MCP ("2.0").

View Source
const LATEST_PROTOCOL_VERSION = mcpgo.LATEST_PROTOCOL_VERSION

LATEST_PROTOCOL_VERSION mirrors mcp-go's latest supported protocol version.

Variables

View Source
var (
	// NewRequestId wraps a raw id value in a RequestId.
	NewRequestId = mcpgo.NewRequestId //nolint:revive // name intentionally matches mcp-go for drop-in compatibility.
	// NewJSONRPCErrorDetails builds a JSONRPCErrorDetails value.
	NewJSONRPCErrorDetails = mcpgo.NewJSONRPCErrorDetails
	// NewJSONRPCResultResponse builds a successful JSONRPCResponse.
	NewJSONRPCResultResponse = mcpgo.NewJSONRPCResultResponse
)

JSON-RPC message constructors.

View Source
var (
	NewTextContent      = mcpgo.NewTextContent
	NewImageContent     = mcpgo.NewImageContent
	NewAudioContent     = mcpgo.NewAudioContent
	NewEmbeddedResource = mcpgo.NewEmbeddedResource
	NewResourceLink     = mcpgo.NewResourceLink
)

Content constructors.

View Source
var (
	AsTextContent          = mcpgo.AsTextContent
	AsImageContent         = mcpgo.AsImageContent
	AsAudioContent         = mcpgo.AsAudioContent
	AsEmbeddedResource     = mcpgo.AsEmbeddedResource
	AsTextResourceContents = mcpgo.AsTextResourceContents
	AsBlobResourceContents = mcpgo.AsBlobResourceContents
)

Content type-assertion helpers.

View Source
var (
	NewTool              = mcpgo.NewTool
	NewToolWithRawSchema = mcpgo.NewToolWithRawSchema
	WithDescription      = mcpgo.WithDescription
	WithString           = mcpgo.WithString
	Required             = mcpgo.Required
	Description          = mcpgo.Description

	NewToolResultText           = mcpgo.NewToolResultText
	NewToolResultError          = mcpgo.NewToolResultError
	NewToolResultStructuredOnly = mcpgo.NewToolResultStructuredOnly
)

Tool builders and result constructors.

View Source
var (
	NewPrompt             = mcpgo.NewPrompt
	WithPromptDescription = mcpgo.WithPromptDescription
)

Prompt builders.

View Source
var ErrMethodNotFound = mcpgo.ErrMethodNotFound

ErrMethodNotFound indicates the requested method does not exist.

View Source
var GetTextFromContent = mcpgo.GetTextFromContent

GetTextFromContent extracts text from a content value, if any.

View Source
var NewMetaFromMap = mcpgo.NewMetaFromMap

NewMetaFromMap builds a *Meta from a raw map.

View Source
var UnmarshalContent = mcpgo.UnmarshalContent

UnmarshalContent decodes a single JSON content object into the concrete mcp.Content implementation (TextContent, ImageContent, ...). It is used by the client shim to populate the Content interface fields of PromptMessage, which mcp-go cannot unmarshal generically.

Functions

This section is empty.

Types

type Annotated

type Annotated = mcpgo.Annotated

Annotated is the base carrying optional Annotations.

type Annotations

type Annotations = mcpgo.Annotations

Annotations describe audience/priority/lastModified for content.

type AudioContent

type AudioContent = mcpgo.AudioContent

AudioContent is base64-encoded audio content.

type BlobResourceContents

type BlobResourceContents = mcpgo.BlobResourceContents

BlobResourceContents is base64 blob resource contents.

type CallToolParams

type CallToolParams = mcpgo.CallToolParams

CallToolParams are the params of a tool call.

type CallToolRequest

type CallToolRequest = mcpgo.CallToolRequest

CallToolRequest is a request to invoke a tool.

type CallToolResult

type CallToolResult = mcpgo.CallToolResult

CallToolResult is the result of a tool call.

type ClientCapabilities

type ClientCapabilities = mcpgo.ClientCapabilities

ClientCapabilities represents capabilities a client may support.

type Content

type Content = mcpgo.Content

Content is a polymorphic content element (text/image/audio/resource/...).

type ElicitationParams

type ElicitationParams = mcpgo.ElicitationParams

ElicitationParams are the params of an elicitation.

type ElicitationRequest

type ElicitationRequest = mcpgo.ElicitationRequest

ElicitationRequest is a server->client elicitation request.

type ElicitationResponse

type ElicitationResponse = mcpgo.ElicitationResponse

ElicitationResponse is the user's response payload.

type ElicitationResponseAction

type ElicitationResponseAction = mcpgo.ElicitationResponseAction

ElicitationResponseAction indicates accept/decline/cancel.

type ElicitationResult

type ElicitationResult = mcpgo.ElicitationResult

ElicitationResult is the result of an elicitation.

type EmbeddedResource

type EmbeddedResource = mcpgo.EmbeddedResource

EmbeddedResource embeds a resource in content.

type EmptyResult

type EmptyResult = mcpgo.EmptyResult

EmptyResult is an empty MCP result (e.g. the response to ping).

type GetPromptParams

type GetPromptParams = mcpgo.GetPromptParams

GetPromptParams are the params of a get.

type GetPromptRequest

type GetPromptRequest = mcpgo.GetPromptRequest

GetPromptRequest gets a prompt.

type GetPromptResult

type GetPromptResult = mcpgo.GetPromptResult

GetPromptResult is the get response.

type ImageContent

type ImageContent = mcpgo.ImageContent

ImageContent is base64-encoded image content.

type Implementation

type Implementation = mcpgo.Implementation

Implementation describes the name and version of an MCP implementation.

type InitializeParams

type InitializeParams = mcpgo.InitializeParams

InitializeParams are the params of an initialize request.

type InitializeRequest

type InitializeRequest = mcpgo.InitializeRequest

InitializeRequest is sent by the client to begin initialization.

type InitializeResult

type InitializeResult = mcpgo.InitializeResult

InitializeResult is the server's response to initialize.

type JSONRPCError

type JSONRPCError = mcpgo.JSONRPCError

JSONRPCError is a JSON-RPC error response.

type JSONRPCErrorDetails

type JSONRPCErrorDetails = mcpgo.JSONRPCErrorDetails

JSONRPCErrorDetails carries the code/message/data of a JSON-RPC error.

type JSONRPCMessage

type JSONRPCMessage = mcpgo.JSONRPCMessage

JSONRPCMessage is any JSON-RPC request/response/notification/error.

type JSONRPCNotification

type JSONRPCNotification = mcpgo.JSONRPCNotification

JSONRPCNotification is a JSON-RPC notification (no response expected).

type JSONRPCResponse

type JSONRPCResponse = mcpgo.JSONRPCResponse

JSONRPCResponse is a successful JSON-RPC response.

type ListPromptsRequest

type ListPromptsRequest = mcpgo.ListPromptsRequest

ListPromptsRequest requests the prompt list.

type ListPromptsResult

type ListPromptsResult = mcpgo.ListPromptsResult

ListPromptsResult is the prompt list response.

type ListResourceTemplatesRequest

type ListResourceTemplatesRequest = mcpgo.ListResourceTemplatesRequest

ListResourceTemplatesRequest requests the resource-template list.

type ListResourceTemplatesResult

type ListResourceTemplatesResult = mcpgo.ListResourceTemplatesResult

ListResourceTemplatesResult is the resource-template list response.

type ListResourcesRequest

type ListResourcesRequest = mcpgo.ListResourcesRequest

ListResourcesRequest requests the resource list.

type ListResourcesResult

type ListResourcesResult = mcpgo.ListResourcesResult

ListResourcesResult is the resource list response.

type ListToolsRequest

type ListToolsRequest = mcpgo.ListToolsRequest

ListToolsRequest requests the tool list.

type ListToolsResult

type ListToolsResult = mcpgo.ListToolsResult

ListToolsResult is the tool list response.

type MCPMethod

type MCPMethod = mcpgo.MCPMethod

MCPMethod is the type of MCP method-name constants.

type Meta

type Meta = mcpgo.Meta

Meta is metadata attached to a request's parameters or a result.

type Notification

type Notification = mcpgo.Notification

Notification is the base of a JSON-RPC notification (method + params).

type NotificationParams

type NotificationParams = mcpgo.NotificationParams

NotificationParams carries a notification's params.

type PingRequest

type PingRequest = mcpgo.PingRequest

PingRequest is a ping request.

type Prompt

type Prompt = mcpgo.Prompt

Prompt describes a prompt template.

type PromptArgument

type PromptArgument = mcpgo.PromptArgument

PromptArgument is a prompt template argument.

type PromptMessage

type PromptMessage = mcpgo.PromptMessage

PromptMessage is a message within a prompt result.

type PromptOption

type PromptOption = mcpgo.PromptOption

PromptOption configures a Prompt built via NewPrompt.

type PropertyOption

type PropertyOption = mcpgo.PropertyOption

PropertyOption configures a schema property.

type ReadResourceParams

type ReadResourceParams = mcpgo.ReadResourceParams

ReadResourceParams are the params of a read.

type ReadResourceRequest

type ReadResourceRequest = mcpgo.ReadResourceRequest

ReadResourceRequest reads a resource by URI.

type ReadResourceResult

type ReadResourceResult = mcpgo.ReadResourceResult

ReadResourceResult is the read response.

type Request

type Request = mcpgo.Request

Request is the base type embedded in protocol request messages.

type RequestId

type RequestId = mcpgo.RequestId //nolint:revive // name intentionally matches mcp-go for drop-in compatibility.

RequestId is a JSON-RPC request identifier.

type RequestParams

type RequestParams = mcpgo.RequestParams

RequestParams is the base params type carrying _meta.

type Resource

type Resource = mcpgo.Resource

Resource is a readable resource.

type ResourceContents

type ResourceContents = mcpgo.ResourceContents

ResourceContents is the contents of a resource (text or blob).

type ResourceLink = mcpgo.ResourceLink

ResourceLink links to a resource.

type ResourceTemplate

type ResourceTemplate = mcpgo.ResourceTemplate

ResourceTemplate is a URI-templated resource description.

type Result

type Result = mcpgo.Result

Result is the base type embedded in protocol result messages.

type Role

type Role = mcpgo.Role

Role is the role of a sampling/prompt message ("user"/"assistant").

type ServerCapabilities

type ServerCapabilities = mcpgo.ServerCapabilities

ServerCapabilities represents capabilities a server may support.

type TextContent

type TextContent = mcpgo.TextContent

TextContent is text content.

type TextResourceContents

type TextResourceContents = mcpgo.TextResourceContents

TextResourceContents is text resource contents.

type Tool

type Tool = mcpgo.Tool

Tool describes a callable tool.

type ToolAnnotation

type ToolAnnotation = mcpgo.ToolAnnotation

ToolAnnotation carries tool behavior hints.

type ToolInputSchema

type ToolInputSchema = mcpgo.ToolInputSchema

ToolInputSchema is a tool's input JSON schema.

type ToolOption

type ToolOption = mcpgo.ToolOption

ToolOption configures a Tool built via NewTool.

type ToolOutputSchema

type ToolOutputSchema = mcpgo.ToolOutputSchema

ToolOutputSchema is a tool's output JSON schema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL