Documentation
¶
Index ¶
- Constants
- Variables
- type CallToolRequest
- type Capabilities
- type ComponentType
- type Content
- type ContentGetter
- type ContentType
- type Descriptor
- type Encoder
- type Error
- type HandleFunc
- type HandlerSetter
- type IContent
- type IPrompt
- type IResource
- type IResourceContent
- type IServer
- type ITool
- type InputSchema
- type LoggingCapability
- type MCPServerInitResult
- type Message
- type Notification
- type Params
- type Prompt
- func (p *Prompt) Argument(name string, required bool) IPrompt
- func (p *Prompt) Content(typ ContentType) IPrompt
- func (p *Prompt) Describe(description string) IPrompt
- func (p *Prompt) Handler(handler HandleFunc) IPrompt
- func (p *Prompt) Role(role string) IPrompt
- func (p *Prompt) SetDescribe(description string)
- func (p *Prompt) SetHandler(handler HandleFunc)
- type PromptArgument
- type PromptCapability
- type PromptRole
- type Property
- type Request
- type Resource
- func (r *Resource) Content(typ ResourceType) IResource
- func (r *Resource) Describe(description string) IResource
- func (r *Resource) Handler(handler ResourceReader) IResource
- func (r *Resource) Mime(mime string) IResource
- func (r *Resource) Read() (string, error)
- func (r *Resource) SetDescribe(description string)
- func (r *Resource) SetHandler(handler ResourceReader)
- func (r *Resource) URI(uri string) IResource
- type ResourceCapability
- type ResourceContent
- type ResourceReader
- type ResourceTemplate
- type ResourceType
- type Response
- type Server
- func (s *Server) AddContentTypes(typ ContentType, name string)
- func (s *Server) AddHandler(method string, hd handler)
- func (s *Server) AddPrompt(prompt IPrompt)
- func (s *Server) AddPrompts(prompts ...IPrompt)
- func (s *Server) AddResource(resource IResource)
- func (s *Server) AddResources(resources ...IResource)
- func (s *Server) AddTool(tool ITool)
- func (s *Server) AddTools(tools ...ITool)
- func (s *Server) Capabilities(listChangedTools, listChangedPrompts, listChangedSources bool, ...)
- func (s *Server) FetchPrompt(req Request) *Response
- func (s *Server) FetchPrompts(req Request) *Response
- func (s *Server) FetchResource(req Request) *Response
- func (s *Server) FetchResources(req Request) *Response
- func (s *Server) FetchTools(req Request) *Response
- func (s *Server) GetPrompt(name string) (IPrompt, error)
- func (s *Server) GetPrompts() ([]IPrompt, error)
- func (s *Server) GetResource(uri string) (IResource, error)
- func (s *Server) GetResources() ([]IResource, error)
- func (s *Server) GetTool(name string) (ITool, error)
- func (s *Server) GetTools() ([]ITool, error)
- func (s *Server) Initialize(req Request) *Response
- func (s *Server) InvokeHandler(req Request) *Response
- func (s *Server) InvokeTool(req Request) *Response
- func (s *Server) ProcessRequest(req Request) *Response
- func (s *Server) Prompt(name string) IPrompt
- func (s *Server) RemoveHandler(method string)
- func (s *Server) RemoveTool(name string) error
- func (s *Server) Resource(name string) IResource
- func (s *Server) SetHandler(method string, hd handler)
- func (s *Server) Tool(name string) ITool
- type ServerInfo
- type Tool
- func (t *Tool) Content(typ ContentType) ITool
- func (t *Tool) Describe(description string) ITool
- func (t *Tool) Handler(handler HandleFunc) ITool
- func (t *Tool) Properties(ps ...Property) ITool
- func (t *Tool) Property(property Property) ITool
- func (t *Tool) SetDescribe(description string)
- func (t *Tool) SetHandler(handler HandleFunc)
- type ToolsCapability
- type Writer
Constants ¶
View Source
const ( ServerInit = "initialize" ListPrompts = "prompts/list" GetPrompt = "prompts/get" ListTools = "tools/list" InvokeTool = "tools/call" ToolsChanged = "notifications/tools/list_changed" ListResources = "resources/list" GetResource = "resources/read" )
View Source
const ( PARSE_ERROR = -32700 INVALID_REQUEST = -32600 METHOD_NOT_FOUND = -32601 INVALID_PARAMS = -32602 INTERNAL_ERROR = -32603 )
Variables ¶
View Source
var ContentTypes = &contentTypes{ ts: map[ContentType]string{ Text: "text", Image: "image", Audio: "audio", }, }
View Source
var PromptRoles = map[PromptRole]string{ User: "user", System: "system", }
Functions ¶
This section is empty.
Types ¶
type CallToolRequest ¶
type CallToolRequest struct {
//BasicMessage
Params *Params `json:"params"`
}
type Capabilities ¶
type Capabilities struct {
*LoggingCapability `json:"logging"`
*PromptCapability `json:"prompts"`
*ToolsCapability `json:"tools"`
*ResourceCapability `json:"resources"`
}
type ComponentType ¶
type ComponentType uint
const ( CmpTool ComponentType = iota CmpPrompt CmpResource )
type Content ¶
type Content struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Resource *Resource `json:"resource,omitempty"`
}
func (*Content) SetResource ¶
type ContentGetter ¶
type ContentGetter interface {
// contains filtered or unexported methods
}
type ContentType ¶
type ContentType uint
const ( Text ContentType = iota Image Audio )
for Tool and Prompt invoke result
type Descriptor ¶
type Descriptor interface {
SetDescribe(description string)
}
type Error ¶
type HandleFunc ¶
HandleFunc provide external function calls for Tool and Prompt only
type HandlerSetter ¶
type HandlerSetter interface {
SetHandler(handler HandleFunc)
}
type IContent ¶
type IContent interface {
SetType(typ string)
// SetData set data or text field
SetData(data string)
SetMime(mime string)
SetResource(resource *Resource)
}
IContent interface for Tool and Prompt content
func NewContent ¶
func NewContent(typ ContentType) IContent
type IPrompt ¶
type IPrompt interface {
Descriptor
HandlerSetter
ContentGetter
Describe(description string) IPrompt
Handler(handler HandleFunc) IPrompt
Role(role string) IPrompt
Content(typ ContentType) IPrompt
Argument(name string, required bool) IPrompt
// contains filtered or unexported methods
}
type IResource ¶
type IResource interface {
Descriptor
Describe(description string) IResource
URI(uri string) IResource
Handler(handler ResourceReader) IResource
Mime(mime string) IResource
SetHandler(handler ResourceReader)
Content(typ ResourceType) IResource
Read() (string, error)
// contains filtered or unexported methods
}
type IResourceContent ¶
type IResourceContent interface {
// SetData set text or blog field
SetData(resType ResourceType, data string)
SetMime(mime string)
SetUri(uri string)
}
IResourceContent interface for Resource content
type IServer ¶
type IServer interface {
AddHandler(method string, hd handler)
SetHandler(method string, hd handler)
RemoveHandler(method string)
Tool(name string) ITool
AddTools(tools ...ITool)
Prompt(name string) IPrompt
AddPrompts(prompts ...IPrompt)
Resource(name string) IResource
AddResources(resources ...IResource)
GetTool(name string) (ITool, error)
GetTools() ([]ITool, error)
GetPrompt(name string) (IPrompt, error)
GetResource(name string) (IResource, error)
InvokeHandler(req Request) *Response
}
type ITool ¶
type ITool interface {
Descriptor
HandlerSetter
ContentGetter
Describe(description string) ITool
Handler(handler HandleFunc) ITool
Property(property Property) ITool
Properties(ps ...Property) ITool
Content(typ ContentType) ITool
// contains filtered or unexported methods
}
type InputSchema ¶
type LoggingCapability ¶
type MCPServerInitResult ¶
type MCPServerInitResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities *Capabilities `json:"capabilities"`
ServerInfo *ServerInfo `json:"serverInfo"`
}
type Notification ¶
type Notification struct {
JsonRPC string `json:"jsonrpc"`
Method string `json:"method"`
Meta map[string]any `json:"_meta,omitempty"`
Params map[string]any `json:"params,omitempty"`
}
func NewNotification ¶
func NewNotification(method string) *Notification
func (*Notification) MarshalJson ¶
func (n *Notification) MarshalJson() ([]byte, error)
func (*Notification) String ¶
func (n *Notification) String() string
func (*Notification) Write ¶
func (n *Notification) Write(key string, value any)
type Prompt ¶
type Prompt struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Args []*PromptArgument `json:"arguments,omitempty"`
// contains filtered or unexported fields
}
func (*Prompt) Content ¶
func (p *Prompt) Content(typ ContentType) IPrompt
Content mark content type of handler result
func (*Prompt) Handler ¶
func (p *Prompt) Handler(handler HandleFunc) IPrompt
func (*Prompt) SetDescribe ¶
func (*Prompt) SetHandler ¶
func (p *Prompt) SetHandler(handler HandleFunc)
type PromptArgument ¶
type PromptCapability ¶
type PromptCapability struct {
ListChanged bool `json:"listChanged"`
}
type Property ¶
type Property struct {
Name string
Type string `json:"type"`
Description string `json:"description,omitempty"`
}
func NewToolProperty ¶
type Request ¶
type Resource ¶
type Resource struct {
Uri string `json:"uri"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
MimeType string `json:"mimeType,omitempty"`
// contains filtered or unexported fields
}
func (*Resource) Content ¶
func (r *Resource) Content(typ ResourceType) IResource
func (*Resource) Handler ¶
func (r *Resource) Handler(handler ResourceReader) IResource
func (*Resource) SetDescribe ¶
func (*Resource) SetHandler ¶
func (r *Resource) SetHandler(handler ResourceReader)
type ResourceCapability ¶
type ResourceContent ¶
type ResourceContent struct {
Uri string `json:"uri"`
Text string `json:"text,omitempty"`
Blob string `json:"blob,omitempty"`
MimeType string `json:"mimeType,omitempty"`
}
func (*ResourceContent) SetData ¶
func (r *ResourceContent) SetData(resType ResourceType, data string)
func (*ResourceContent) SetMime ¶
func (r *ResourceContent) SetMime(mime string)
func (*ResourceContent) SetUri ¶
func (r *ResourceContent) SetUri(uri string)
type ResourceReader ¶
type ResourceTemplate ¶
type Response ¶
type Response struct {
JsonRPC string `json:"jsonrpc"`
ID any `json:"id"`
Result map[string]any `json:"result"`
Error *Error `json:"error,omitempty"`
}
func NewResponse ¶
func (*Response) MarshalJson ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddContentTypes ¶
func (s *Server) AddContentTypes(typ ContentType, name string)
AddContentTypes add customized content type for Tool and Prompt invoke
func (*Server) AddHandler ¶
func (*Server) AddPrompts ¶
func (*Server) AddResource ¶
func (*Server) AddResources ¶
func (*Server) Capabilities ¶
func (*Server) FetchPrompt ¶
func (*Server) FetchPrompts ¶
func (*Server) FetchResource ¶
func (*Server) FetchResources ¶
func (*Server) FetchTools ¶
func (*Server) GetPrompts ¶
func (*Server) GetResources ¶
func (*Server) Initialize ¶
func (*Server) InvokeHandler ¶
func (*Server) InvokeTool ¶
func (*Server) ProcessRequest ¶
func (*Server) RemoveHandler ¶
func (*Server) RemoveTool ¶
func (*Server) SetHandler ¶
type ServerInfo ¶
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema *InputSchema `json:"inputSchema,omitempty"`
// contains filtered or unexported fields
}
func (*Tool) Content ¶
func (t *Tool) Content(typ ContentType) ITool
Content mark type of handler result
func (*Tool) Handler ¶
func (t *Tool) Handler(handler HandleFunc) ITool
func (*Tool) Properties ¶
func (*Tool) SetDescribe ¶
func (*Tool) SetHandler ¶
func (t *Tool) SetHandler(handler HandleFunc)
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged"`
}
Click to show internal directories.
Click to hide internal directories.