mcp_golang

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 13 Imported by: 77

README

Statusphere logo

GitHub stars GitHub forks GitHub issues GitHub pull requests GitHub license GitHub contributors GitHub last commit GoDoc Go Report Card Tests

mcp-golang

mcp-golang is an unofficial implementation of the Model Context Protocol in Go.

Write MCP servers and clients in golang with a few lines of code.

Docs at https://mcpgolang.com

Highlights

  • 🛡️Type safety - Define your tool arguments as native go structs, have mcp-golang handle the rest. Automatic schema generation, deserialization, error handling etc.
  • 🚛 Custom transports - Use the built-in transports (stdio for full feature support, HTTP for stateless communication) or write your own.
  • Low boilerplate - mcp-golang generates all the MCP endpoints for you apart from your tools, prompts and resources.
  • 🧩 Modular - The library is split into three components: transport, protocol and server/client. Use them all or take what you need.
  • 🔄 Bi-directional - Full support for both server and client implementations through stdio transport.

Example Usage

Install with go get github.com/metoro-io/mcp-golang

Server Example
package main

import (
	"fmt"
	"github.com/metoro-io/mcp-golang"
	"github.com/metoro-io/mcp-golang/transport/stdio"
)

// Tool arguments are just structs, annotated with jsonschema tags
// More at https://mcpgolang.com/tools#schema-generation
type Content struct {
	Title       string  `json:"title" jsonschema:"required,description=The title to submit"`
	Description *string `json:"description" jsonschema:"description=The description to submit"`
}
type MyFunctionsArguments struct {
	Submitter string  `json:"submitter" jsonschema:"required,description=The name of the thing calling this tool (openai, google, claude, etc)"`
	Content   Content `json:"content" jsonschema:"required,description=The content of the message"`
}

func main() {
	done := make(chan struct{})

	server := mcp_golang.NewServer(stdio.NewStdioServerTransport())
	err := server.RegisterTool("hello", "Say hello to a person", func(arguments MyFunctionsArguments) (*mcp_golang.ToolResponse, error) {
		return mcp_golang.NewToolResponse(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Submitter))), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterPrompt("promt_test", "This is a test prompt", func(arguments Content) (*mcp_golang.PromptResponse, error) {
		return mcp_golang.NewPromptResponse("description", mcp_golang.NewPromptMessage(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %server!", arguments.Title)), mcp_golang.RoleUser)), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterResource("test://resource", "resource_test", "This is a test resource", "application/json", func() (*mcp_golang.ResourceResponse, error) {
		return mcp_golang.NewResourceResponse(mcp_golang.NewTextEmbeddedResource("test://resource", "This is a test resource", "application/json")), nil
	})

	err = server.Serve()
	if err != nil {
		panic(err)
	}

	<-done
}
HTTP Server Example

You can also create an HTTP-based server using either the standard HTTP transport or Gin framework:

// Standard HTTP
transport := http.NewHTTPTransport("/mcp")
transport.WithAddr(":8080")
server := mcp_golang.NewServer(transport)

// Or with Gin framework
transport := http.NewGinTransport()
router := gin.Default()
router.POST("/mcp", transport.Handler())
server := mcp_golang.NewServer(transport)

Note: HTTP transports are stateless and don't support bidirectional features like notifications. Use stdio transport if you need those features.

Client Example

Checkout the examples/client directory for a more complete example.

package main

import (
    "context"
    "log"
    mcp "github.com/metoro-io/mcp-golang"
    "github.com/metoro-io/mcp-golang/transport/stdio"
)

// Define type-safe arguments
type CalculateArgs struct {
    Operation string `json:"operation"`
    A         int    `json:"a"`
    B         int    `json:"b"`
}

func main() {
   cmd := exec.Command("go", "run", "./server/main.go")
   stdin, err := cmd.StdinPipe()
   if err != nil {
    log.Fatalf("Failed to get stdin pipe: %v", err)
   }
   stdout, err := cmd.StdoutPipe()
   if err != nil {
    log.Fatalf("Failed to get stdout pipe: %v", err)
   }

   if err := cmd.Start(); err != nil {
    log.Fatalf("Failed to start server: %v", err)
   }
   defer cmd.Process.Kill()
    // Create and initialize client
    transport := stdio.NewStdioServerTransportWithIO(stdout, stdin)
    client := mcp.NewClient(transport)
    
    if _, err := client.Initialize(context.Background()); err != nil {
        log.Fatalf("Failed to initialize: %v", err)
    }

    // Call a tool with typed arguments
    args := CalculateArgs{
        Operation: "add",
        A:         10,
        B:         5,
    }
    
    response, err := client.CallTool(context.Background(), "calculate", args)
    if err != nil {
        log.Fatalf("Failed to call tool: %v", err)
    }
    
    if response != nil && len(response.Content) > 0 {
        log.Printf("Result: %s", response.Content[0].TextContent.Text)
    }
}
Using with Claude Desktop

Create a file in ~/Library/Application Support/Claude/claude_desktop_config.json with the following contents:

{
"mcpServers": {
  "golang-mcp-server": {
      "command": "<your path to golang MCP server go executable>",
      "args": [],
      "env": {}
    }
  }
}

Contributions

Contributions are more than welcome! Please check out our contribution guidelines.

Discord

Got any suggestions, have a question on the api or usage? Ask on the discord server. A maintainer will be happy to help you out.

Examples

Some more extensive examples using the library found here:

  • Metoro - Query and interact with kubernetes environments monitored by Metoro

Open a PR to add your own projects!

Server Feature Implementation

Tools
  • Tool Calls
  • Native go structs as arguments
  • Programatically generated tool list endpoint
  • Change notifications
  • Pagination
Prompts
  • Prompt Calls
  • Programatically generated prompt list endpoint
  • Change notifications
  • Pagination
Resources
  • Resource Calls
  • Programatically generated resource list endpoint
  • Change notifications
  • Pagination
Transports
  • Stdio - Full support for all features including bidirectional communication
  • HTTP - Stateless transport for simple request-response scenarios (no notifications support)
  • Gin - HTTP transport with Gin framework integration (stateless, no notifications support)
  • SSE
  • Custom transport support
  • HTTPS with custom auth support - in progress. Not currently part of the spec but we'll be adding experimental support for it.
Client
  • Call tools
  • Call prompts
  • Call resources
  • List tools
  • List prompts
  • List resources

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotations

type Annotations struct {
	// Describes who the intended customer of this object or data is.
	//
	// It can include multiple entries to indicate ToolResponse useful for multiple
	// audiences (e.g., `["user", "assistant"]`).
	Audience []Role `json:"audience,omitempty" yaml:"audience,omitempty" mapstructure:"audience,omitempty"`

	// Describes how important this data is for operating the server.
	//
	// A value of 1 means "most important," and indicates that the data is
	// effectively required, while 0 means "least important," and indicates that
	// the data is entirely optional.
	Priority *float64 `json:"priority,omitempty" yaml:"priority,omitempty" mapstructure:"priority,omitempty"`
}

type BlobResourceContents

type BlobResourceContents struct {
	// A base64-encoded string representing the binary data of the item.
	Blob string `json:"blob" yaml:"blob" mapstructure:"blob"`

	// The MIME type of this resource, if known.
	MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"`

	// The URI of this resource.
	Uri string `json:"uri" yaml:"uri" mapstructure:"uri"`
}

type Client added in v0.5.0

type Client struct {
	// contains filtered or unexported fields
}

Client represents an MCP client that can connect to and interact with MCP servers

func NewClient added in v0.5.0

func NewClient(transport transport.Transport) *Client

NewClient creates a new MCP client with the specified transport

func NewClientWithInfo added in v0.9.0

func NewClientWithInfo(transport transport.Transport, info ClientInfo) *Client

NewClientWithInfo create a new client with info. This is required by anthorpic mcp tools

func (*Client) CallTool added in v0.5.0

func (c *Client) CallTool(ctx context.Context, name string, arguments any) (*ToolResponse, error)

CallTool calls a specific tool on the server with the provided arguments

func (*Client) GetCapabilities added in v0.5.0

func (c *Client) GetCapabilities() *ServerCapabilities

GetCapabilities returns the server capabilities obtained during initialization

func (*Client) GetPrompt added in v0.5.0

func (c *Client) GetPrompt(ctx context.Context, name string, arguments any) (*PromptResponse, error)

GetPrompt retrieves a specific prompt from the server

func (*Client) Initialize added in v0.5.0

func (c *Client) Initialize(ctx context.Context) (*InitializeResponse, error)

Initialize connects to the server and retrieves its capabilities

func (*Client) ListPrompts added in v0.5.0

func (c *Client) ListPrompts(ctx context.Context, cursor *string) (*ListPromptsResponse, error)

ListPrompts retrieves the list of available prompts from the server

func (*Client) ListResources added in v0.5.0

func (c *Client) ListResources(ctx context.Context, cursor *string) (*ListResourcesResponse, error)

ListResources retrieves the list of available resources from the server

func (*Client) ListTools added in v0.5.0

func (c *Client) ListTools(ctx context.Context, cursor *string) (*ToolsResponse, error)

ListTools retrieves the list of available tools from the server

func (*Client) Ping added in v0.5.0

func (c *Client) Ping(ctx context.Context) error

Ping sends a ping request to the server to check connectivity

func (*Client) ReadResource added in v0.5.0

func (c *Client) ReadResource(ctx context.Context, uri string) (*ResourceResponse, error)

ReadResource reads a specific resource from the server

type ClientInfo added in v0.9.0

type ClientInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type Content

type Content struct {
	Type             ContentType
	TextContent      *TextContent
	ImageContent     *ImageContent
	EmbeddedResource *EmbeddedResource
	Annotations      *Annotations
}

func NewBlobResourceContent

func NewBlobResourceContent(uri string, base64EncodedData string, mimeType string) *Content

NewBlobResourceContent creates a new ToolResponse that is a blob of binary data. The given data is base64-encoded; the client will decode it. The client will render this as a blob; it will not be human-readable.

func NewImageContent

func NewImageContent(base64EncodedStringData string, mimeType string) *Content

NewImageContent creates a new ToolResponse that is an image. The given data is base64-encoded

func NewTextContent

func NewTextContent(content string) *Content

NewTextContent creates a new ToolResponse that is a simple text string. The client will render this as a single string.

func NewTextResourceContent

func NewTextResourceContent(uri string, text string, mimeType string) *Content

NewTextResourceContent creates a new ToolResponse that is an embedded resource of type "text". The given text is embedded in the response as a TextResourceContents, which contains the given MIME type and URI. The text is not base64-encoded.

func (Content) MarshalJSON

func (c Content) MarshalJSON() ([]byte, error)

Custom JSON marshaling for ToolResponse Content

func (*Content) UnmarshalJSON added in v0.5.0

func (c *Content) UnmarshalJSON(b []byte) error

func (*Content) WithAnnotations

func (c *Content) WithAnnotations(annotations Annotations) *Content

type ContentType

type ContentType string
const (
	// The value is the value of the "type" field in the Content so do not change
	ContentTypeText             ContentType = "text"
	ContentTypeImage            ContentType = "image"
	ContentTypeEmbeddedResource ContentType = "resource"
)

type EmbeddedResource

type EmbeddedResource struct {
	EmbeddedResourceType embeddedResourceType
	TextResourceContents *TextResourceContents
	BlobResourceContents *BlobResourceContents
}

The contents of a resource, embedded into a prompt or tool call result.

It is up to the client how best to render embedded resources for the benefit of the LLM and/or the user.

func NewBlobEmbeddedResource

func NewBlobEmbeddedResource(uri string, base64EncodedData string, mimeType string) *EmbeddedResource

func NewTextEmbeddedResource

func NewTextEmbeddedResource(uri string, text string, mimeType string) *EmbeddedResource

func (EmbeddedResource) MarshalJSON

func (c EmbeddedResource) MarshalJSON() ([]byte, error)

Custom JSON marshaling for EmbeddedResource

func (*EmbeddedResource) UnmarshalJSON added in v0.13.0

func (c *EmbeddedResource) UnmarshalJSON(data []byte) error

Custom JSON unmarshaling for EmbeddedResource

type ImageContent

type ImageContent struct {
	// The base64-encoded image data.
	Data string `json:"data" yaml:"data" mapstructure:"data"`

	// The MIME type of the image. Different providers may support different image
	// types.
	MimeType string `json:"mimeType" yaml:"mimeType" mapstructure:"mimeType"`
}

An image provided to or from an LLM.

type InitializeResponse added in v0.5.0

type InitializeResponse struct {
	// This result property is reserved by the protocol to allow clients and servers
	// to attach additional metadata to their responses.
	Meta initializeResultMeta `json:"_meta,omitempty" yaml:"_meta,omitempty" mapstructure:"_meta,omitempty"`

	// Capabilities corresponds to the JSON schema field "capabilities".
	Capabilities ServerCapabilities `json:"capabilities" yaml:"capabilities" mapstructure:"capabilities"`

	// Instructions describing how to use the server and its features.
	//
	// This can be used by clients to improve the LLM's understanding of available
	// tools, resources, etc. It can be thought of like a "hint" to the model. For
	// example, this information MAY be added to the system prompt.
	Instructions *string `json:"instructions,omitempty" yaml:"instructions,omitempty" mapstructure:"instructions,omitempty"`

	// The version of the Model Context Protocol that the server wants to use. This
	// may not match the version that the client requested. If the client cannot
	// support this version, it MUST disconnect.
	ProtocolVersion string `json:"protocolVersion" yaml:"protocolVersion" mapstructure:"protocolVersion"`

	// ServerInfo corresponds to the JSON schema field "serverInfo".
	ServerInfo implementation `json:"serverInfo" yaml:"serverInfo" mapstructure:"serverInfo"`
}

After receiving an initialize request from the client, the server sends this response.

func (*InitializeResponse) UnmarshalJSON added in v0.5.0

func (j *InitializeResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ListPromptsResponse added in v0.5.0

type ListPromptsResponse struct {
	// Prompts corresponds to the JSON schema field "prompts".
	Prompts []*PromptSchema `json:"prompts" yaml:"prompts" mapstructure:"prompts"`
	// NextCursor is a cursor for pagination. If not nil, there are more prompts available.
	NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}

The server's response to a prompts/list request from the client.

type ListResourceTemplatesResponse added in v0.10.0

type ListResourceTemplatesResponse struct {
	// Templates corresponds to the JSON schema field "templates".
	Templates []*ResourceTemplateSchema `json:"resourceTemplates" yaml:"resourceTemplates" mapstructure:"resourceTemplates"`
	// NextCursor is a cursor for pagination. If not nil, there are more templates available.
	NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}

The server's response to a resources/templates/list request from the client.

type ListResourcesResponse added in v0.5.0

type ListResourcesResponse struct {
	// Resources corresponds to the JSON schema field "resources".
	Resources []*ResourceSchema `json:"resources" yaml:"resources" mapstructure:"resources"`
	// NextCursor is a cursor for pagination. If not nil, there are more resources available.
	NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}

The server's response to a resources/list request from the client.

type PromptMessage

type PromptMessage struct {
	Content *Content `json:"content" yaml:"content" mapstructure:"content"`
	Role    Role     `json:"role" yaml:"role" mapstructure:"role"`
}

func NewPromptMessage

func NewPromptMessage(content *Content, role Role) *PromptMessage

type PromptResponse

type PromptResponse struct {
	// An optional description for the prompt.
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// Messages corresponds to the JSON schema field "messages".
	Messages []*PromptMessage `json:"messages" yaml:"messages" mapstructure:"messages"`
}

The server's response to a prompts/get request from the client.

func NewPromptResponse

func NewPromptResponse(description string, messages ...*PromptMessage) *PromptResponse

type PromptSchema added in v0.5.0

type PromptSchema struct {
	// A list of arguments to use for templating the prompt.
	Arguments []PromptSchemaArgument `json:"arguments,omitempty" yaml:"arguments,omitempty" mapstructure:"arguments,omitempty"`

	// An optional description of what this prompt provides
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// The name of the prompt or prompt template.
	Name string `json:"name" yaml:"name" mapstructure:"name"`
}

A PromptSchema or prompt template that the server offers.

type PromptSchemaArgument added in v0.5.0

type PromptSchemaArgument struct {
	// A human-readable description of the argument.
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// The name of the argument.
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// Whether this argument must be provided.
	Required *bool `json:"required,omitempty" yaml:"required,omitempty" mapstructure:"required,omitempty"`
}

type ResourceResponse

type ResourceResponse struct {
	Contents []*EmbeddedResource `json:"contents"`
}

func NewResourceResponse

func NewResourceResponse(contents ...*EmbeddedResource) *ResourceResponse

type ResourceSchema added in v0.5.0

type ResourceSchema struct {
	// Annotations corresponds to the JSON schema field "annotations".
	Annotations *Annotations `json:"annotations,omitempty" yaml:"annotations,omitempty" mapstructure:"annotations,omitempty"`

	// A description of what this resource represents.
	//
	// This can be used by clients to improve the LLM's understanding of available
	// resources. It can be thought of like a "hint" to the model.
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// The MIME type of this resource, if known.
	MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"`

	// A human-readable name for this resource.
	//
	// This can be used by clients to populate UI elements.
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// The URI of this resource.
	Uri string `json:"uri" yaml:"uri" mapstructure:"uri"`
}

A known resource that the server is capable of reading.

type ResourceTemplateSchema added in v0.10.0

type ResourceTemplateSchema struct {
	// Annotations corresponds to the JSON schema field "annotations".
	Annotations *Annotations `json:"annotations,omitempty" yaml:"annotations,omitempty" mapstructure:"annotations,omitempty"`

	// A description of what resources matching this template represent.
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// The MIME type of resources matching this template, if known.
	MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"`

	// A human-readable name for this template.
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// The URI template following RFC 6570.
	UriTemplate string `json:"uriTemplate" yaml:"uriTemplate" mapstructure:"uriTemplate"`
}

A resource template that defines a pattern for dynamic resources.

type Role

type Role string
const RoleAssistant Role = "assistant"
const RoleUser Role = "user"

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(transport transport.Transport, options ...ServerOptions) *Server

func (*Server) CheckPromptRegistered added in v0.2.0

func (s *Server) CheckPromptRegistered(name string) bool

func (*Server) CheckResourceRegistered added in v0.2.0

func (s *Server) CheckResourceRegistered(uri string) bool

func (*Server) CheckResourceTemplateRegistered added in v0.10.0

func (s *Server) CheckResourceTemplateRegistered(uriTemplate string) bool

func (*Server) CheckToolRegistered added in v0.2.0

func (s *Server) CheckToolRegistered(name string) bool

func (*Server) DeregisterPrompt added in v0.2.0

func (s *Server) DeregisterPrompt(name string) error

func (*Server) DeregisterResource added in v0.2.0

func (s *Server) DeregisterResource(uri string) error

func (*Server) DeregisterResourceTemplate added in v0.10.0

func (s *Server) DeregisterResourceTemplate(uriTemplate string) error

func (*Server) DeregisterTool added in v0.2.0

func (s *Server) DeregisterTool(name string) error

func (*Server) RegisterPrompt

func (s *Server) RegisterPrompt(name string, description string, handler any) error

func (*Server) RegisterResource

func (s *Server) RegisterResource(uri string, name string, description string, mimeType string, handler any) error

func (*Server) RegisterResourceTemplate added in v0.10.0

func (s *Server) RegisterResourceTemplate(uriTemplate string, name string, description string, mimeType string) error

func (*Server) RegisterTool

func (s *Server) RegisterTool(name string, description string, handler any) error

RegisterTool registers a new tool with the server

func (*Server) Serve

func (s *Server) Serve() error

type ServerCapabilities added in v0.5.0

type ServerCapabilities struct {
	// Experimental, non-standard capabilities that the server supports.
	Experimental ServerCapabilitiesExperimental `json:"experimental,omitempty" yaml:"experimental,omitempty" mapstructure:"experimental,omitempty"`

	// Present if the server supports sending log messages to the client.
	Logging ServerCapabilitiesLogging `json:"logging,omitempty" yaml:"logging,omitempty" mapstructure:"logging,omitempty"`

	// Present if the server offers any prompt templates.
	Prompts *ServerCapabilitiesPrompts `json:"prompts,omitempty" yaml:"prompts,omitempty" mapstructure:"prompts,omitempty"`

	// Present if the server offers any resources to read.
	Resources *ServerCapabilitiesResources `json:"resources,omitempty" yaml:"resources,omitempty" mapstructure:"resources,omitempty"`

	// Present if the server offers any tools to call.
	Tools *ServerCapabilitiesTools `json:"tools,omitempty" yaml:"tools,omitempty" mapstructure:"tools,omitempty"`
}

Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.

type ServerCapabilitiesExperimental added in v0.5.0

type ServerCapabilitiesExperimental map[string]map[string]interface{}

Experimental, non-standard capabilities that the server supports.

type ServerCapabilitiesLogging added in v0.5.0

type ServerCapabilitiesLogging map[string]interface{}

Present if the server supports sending log messages to the client.

type ServerCapabilitiesPrompts added in v0.5.0

type ServerCapabilitiesPrompts struct {
	// Whether this server supports notifications for changes to the prompt list.
	ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`
}

Present if the server offers any prompt templates.

type ServerCapabilitiesResources added in v0.5.0

type ServerCapabilitiesResources struct {
	// Whether this server supports notifications for changes to the resource list.
	ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`

	// Whether this server supports subscribing to resource updates.
	Subscribe *bool `json:"subscribe,omitempty" yaml:"subscribe,omitempty" mapstructure:"subscribe,omitempty"`
}

Present if the server offers any resources to read.

type ServerCapabilitiesTools added in v0.5.0

type ServerCapabilitiesTools struct {
	// Whether this server supports notifications for changes to the tool list.
	ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`
}

Present if the server offers any tools to call.

type ServerOptions added in v0.3.0

type ServerOptions func(*Server)

func WithInstructions added in v0.12.0

func WithInstructions(instructions string) ServerOptions

func WithName added in v0.6.0

func WithName(name string) ServerOptions

func WithPaginationLimit added in v0.3.0

func WithPaginationLimit(limit int) ServerOptions

Beware: As of 2024-12-13, it looks like Claude does not support pagination yet

func WithProtocol added in v0.3.0

func WithProtocol(protocol *protocol.Protocol) ServerOptions

func WithVersion added in v0.6.0

func WithVersion(version string) ServerOptions

type TextContent

type TextContent struct {
	// The text ToolResponse of the message.
	Text string `json:"text" yaml:"text" mapstructure:"text"`
}

Text provided to or from an LLM.

type TextResourceContents

type TextResourceContents struct {
	// The MIME type of this resource, if known.
	MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"`

	// The text of the item. This must only be set if the item can actually be
	// represented as text (not binary data).
	Text string `json:"text" yaml:"text" mapstructure:"text"`

	// The URI of this resource.
	Uri string `json:"uri" yaml:"uri" mapstructure:"uri"`
}

type ToolResponse

type ToolResponse struct {
	Content []*Content `json:"content" yaml:"content" mapstructure:"content"`
}

This is a union type of all the different ToolResponse that can be sent back to the client. We allow creation through constructors only to make sure that the ToolResponse is valid.

func NewToolResponse added in v0.2.0

func NewToolResponse(content ...*Content) *ToolResponse

type ToolRetType added in v0.8.0

type ToolRetType struct {
	// A human-readable description of the tool.
	Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`

	// A JSON Schema object defining the expected parameters for the tool.
	InputSchema interface{} `json:"inputSchema" yaml:"inputSchema" mapstructure:"inputSchema"`

	// The name of the tool.
	Name string `json:"name" yaml:"name" mapstructure:"name"`
}

Definition for a tool the client can call.

type ToolsResponse added in v0.8.0

type ToolsResponse struct {
	Tools      []ToolRetType `json:"tools" yaml:"tools" mapstructure:"tools"`
	NextCursor *string       `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}

Directories

Path Synopsis
examples
internal
protocol
This file implements the core protocol layer for JSON-RPC communication in the MCP SDK.
This file implements the core protocol layer for JSON-RPC communication in the MCP SDK.
sse
sse/internal/sse
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication.
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication.
stdio/internal/stdio
This file implements the stdio transport layer for JSON-RPC communication.
This file implements the stdio transport layer for JSON-RPC communication.

Jump to

Keyboard shortcuts

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