mcps

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerTable = "mcp_server"
	ServerAlias = "ms"
	ServerLabel = "server"
	ServerTypID = "mcpsServer"
)

consts of Server 服务器

Variables

This section is empty.

Functions

func BoolArg

func BoolArg(arguments map[string]any, key string) (bool, bool, error)

BoolArg 从参数中获取布尔值

func BuildToolErrorResult

func BuildToolErrorResult(message string) map[string]any

BuildToolErrorResult 构建标准的 MCP 工具错误结果

func BuildToolSuccessResult

func BuildToolSuccessResult(structured any) map[string]any

BuildToolSuccessResult 构建标准的 MCP 工具成功结果

func ContextWithServerName added in v0.2.4

func ContextWithServerName(ctx context.Context, sn string) context.Context

func IntArg

func IntArg(arguments map[string]any, key string) (int, bool, error)

IntArg 从参数中获取整数值

func ServerNameFromContext added in v0.2.4

func ServerNameFromContext(ctx context.Context) string

func StringArg

func StringArg(arguments map[string]any, key string) string

StringArg 从参数中获取字符串值

Types

type HeaderCate added in v0.2.4

type HeaderCate int8

头类型

const (
	HeaderCateAuthorization HeaderCate = 1 << iota //   1 Authorization
	HeaderCateOwnerID                              //   2 OwnerID
	HeaderCateSessionID                            //   4 SessionID

	HeaderCateNone HeaderCate = 0 // None
)

func (*HeaderCate) Decode added in v0.2.4

func (z *HeaderCate) Decode(s string) error

func (HeaderCate) Has added in v0.2.4

func (z HeaderCate) Has(o HeaderCate) bool

func (HeaderCate) HasAuthorization added in v0.2.4

func (z HeaderCate) HasAuthorization() bool

func (HeaderCate) HasOwnerSession added in v0.2.4

func (z HeaderCate) HasOwnerSession() bool

func (HeaderCate) MarshalText added in v0.2.4

func (z HeaderCate) MarshalText() ([]byte, error)

func (HeaderCate) String added in v0.2.4

func (z HeaderCate) String() string

func (*HeaderCate) UnmarshalText added in v0.2.4

func (z *HeaderCate) UnmarshalText(b []byte) error

type HeaderFunc added in v0.2.4

type HeaderFunc func(ctx context.Context) map[string]string

type Invoker

type Invoker func(ctx context.Context, params map[string]any) (map[string]any, error)

Invoker is the tool invocation function type

type Server

type Server struct {
	comm.BaseModel `bun:"table:mcp_server,alias:ms" json:"-"`

	comm.DefaultModel

	ServerBasic

	// 定制头函数
	HeaderFunc HeaderFunc `bson:"-" bun:"-" extensions:"x-order=I" json:"-" pg:"-"`

	comm.MetaField

} // @name mcpsServer

Server 服务器

func NewServerWithBasic

func NewServerWithBasic(in ServerBasic) *Server

func NewServerWithID

func NewServerWithID(id any) *Server

func (*Server) Creating

func (z *Server) Creating() error

Creating function call to it's inner fields defined hooks

func (*Server) IdentityAlias

func (_ *Server) IdentityAlias() string

func (*Server) IdentityLabel

func (_ *Server) IdentityLabel() string

func (*Server) IdentityModel

func (_ *Server) IdentityModel() string

func (*Server) IdentityTable

func (_ *Server) IdentityTable() string

func (*Server) SetWith

func (z *Server) SetWith(o ServerSet)

type ServerBasic

type ServerBasic struct {
	// 名称
	Name string `` /* 140-byte string literal not displayed */
	// 传输类型
	//  * `stdIO` - 标准IO
	//  * `sse`
	//  * `streamable`
	//  * `inMemory` - 内部运行
	TransType TransType `` /* 189-byte string literal not displayed */
	// 指令 仅对 TransType 为 StdIO 时有效
	Command string `bson:"command" bun:",notnull" extensions:"x-order=C" form:"command" json:"command" pg:",notnull"`
	// 完整网址 仅对 TransType 为 SSE 或 HTTP 时有效
	URL string `bson:"url" bun:",notnull" extensions:"x-order=D" form:"url" json:"url" pg:",notnull"`
	// 是否激活
	IsActive bool `bson:"isActive" bun:",notnull" extensions:"x-order=E" form:"isActive" json:"isActive" pg:",notnull"`
	// 连接状态
	//  * `disconnected` - 断开
	//  * `connecting` - 连接中
	//  * `connected` - 已连接
	Status Status `` /* 184-byte string literal not displayed */
	// 备注
	Remark string `bson:"remark" bun:",notnull" extensions:"x-order=G" form:"remark" json:"remark" pg:",notnull"`
	// 头分类
	//  * `authorization`
	//  * `ownerID`
	//  * `sessionID`
	HeaderCate HeaderCate `` /* 176-byte string literal not displayed */
	// for meta update
	MetaDiff *comm.MetaDiff `bson:"-" bun:"-" json:"metaUp,omitempty" pg:"-" swaggerignore:"true"`

} // @name mcpsServerBasic

func (*ServerBasic) MetaAddKVs

func (in *ServerBasic) MetaAddKVs(args ...any) *ServerBasic

type ServerSet

type ServerSet struct {
	// 名称
	Name *string `extensions:"x-order=A" json:"name"`
	// 传输类型
	//  * `stdIO` - 标准IO
	//  * `sse`
	//  * `streamable`
	//  * `inMemory` - 内部运行
	TransType *TransType `enums:"stdIO,sse,streamable,inMemory" extensions:"x-order=B" json:"transType" swaggertype:"string"`
	// 指令 仅对 TransType 为 StdIO 时有效
	Command *string `extensions:"x-order=C" json:"command"`
	// 完整网址 仅对 TransType 为 SSE 或 HTTP 时有效
	URL *string `extensions:"x-order=D" json:"url"`
	// 是否激活
	IsActive *bool `extensions:"x-order=E" json:"isActive"`
	// 连接状态
	//  * `disconnected` - 断开
	//  * `connecting` - 连接中
	//  * `connected` - 已连接
	Status *Status `enums:"disconnected,connecting,connected" extensions:"x-order=F" json:"status" swaggertype:"string"`
	// 备注
	Remark *string `extensions:"x-order=G" json:"remark"`
	// 头分类
	//  * `authorization`
	//  * `ownerID`
	//  * `sessionID`
	HeaderCate *HeaderCate `enums:"authorization,ownerID,sessionID" extensions:"x-order=H" json:"headerCate" swaggertype:"string"`
	// for meta update
	MetaDiff *comm.MetaDiff `json:"metaUp,omitempty" swaggerignore:"true"`

} // @name mcpsServerSet

func (*ServerSet) MetaAddKVs

func (in *ServerSet) MetaAddKVs(args ...any) *ServerSet

type Servers

type Servers []Server

type Status

type Status int8

状态 用于表示连接

const (
	StatusDisconnected Status = 0 + iota //  0 断开 初始默认
	StatusConnecting                     //  1 连接中
	StatusConnected                      //  2 已连接
)

func (*Status) Decode

func (z *Status) Decode(s string) error

func (Status) MarshalText

func (z Status) MarshalText() ([]byte, error)

func (Status) String

func (z Status) String() string

func (*Status) UnmarshalText

func (z *Status) UnmarshalText(b []byte) error

type ToolCallPayload

type ToolCallPayload struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`
}

ToolCallPayload 是 MCP tools/call 的参数

type ToolDescriptor

type ToolDescriptor struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	InputSchema map[string]any `json:"inputSchema"`
}

ToolDescriptor 是工具的描述符,用于 MCP 工具列表

type ToolNames

type ToolNames []ToolDescriptor

ToolNames 是 []ToolDescriptor 的自定义类型,用于日志输出

func (ToolNames) String

func (z ToolNames) String() string

String 返回工具名称列表,用于日志记录

type TransType

type TransType int8

MCP 传输类型

const (
	TransTypeStdIO      TransType = 1 + iota //  1 标准IO
	TransTypeSSE                             //  2 SSE
	TransTypeStreamable                      //  3 Streamable
	TransTypeInMemory                        //  4 内部运行
)

func (*TransType) Decode

func (z *TransType) Decode(s string) error

func (TransType) IsRemote

func (t TransType) IsRemote() bool

IsRemote 判断是否为远程传输类型(SSE 或 Streamable)

func (TransType) MarshalText

func (z TransType) MarshalText() ([]byte, error)

func (TransType) String

func (z TransType) String() string

func (*TransType) UnmarshalText

func (z *TransType) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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