跳到主要内容

mcp

共 12 个函数

可变参数函数索引​

函数参数返回值说明
mcp.AddServername string, transport string, endpoint string, opts ...Option*ServerInfo, errorpersists a new server in Yakit's profile registry. It does not
mcp.Connectname string, opts ...Option*Client, erroropens an enabled server from the same profile registry used by Yakit.
mcp.DeleteServername string, opts ...Optionerrordeletes exactly one named server and its tool/bridge caches via
mcp.ListServerskeyword string, opts ...Option*ServerPage, errorincludes enabled and disabled servers, ordered by name then ID.
mcp.NewClienttransport string, endpoint string, opts ...Option*Client, errorconnects to stdio, sse or streamable_http and performs initialize.

可变参数函数详情​

AddServer​

AddServer(name string, transport string, endpoint string, opts ...Option) (*ServerInfo, error)

persists a new server in Yakit's profile registry. It does not

overwrite an existing name or start a subprocess/network connection.

必填参数

参数名类型说明
namestring
transportstring
endpointstring

可选参数

可作为可变参数 opts ...Option 传入选项;共 7 个可用选项,详见 Option 选项列表。

返回值

序号类型说明
r1*ServerInfo
r2error

示例

mcp.AddServer("local", "stdio", `python3 "/tmp/my server.py"`, mcp.env({"TOKEN": "value"}))~
page = mcp.ListServers("local")~
dump(page.Servers)
die(mcp.DeleteServer("local"))

Connect​

Connect(name string, opts ...Option) (*Client, error)

opens an enabled server from the same profile registry used by Yakit.

必填参数

参数名类型说明
namestring

可选参数

可作为可变参数 opts ...Option 传入选项;共 7 个可用选项,详见 Option 选项列表。

返回值

序号类型说明
r1*Client
r2error

DeleteServer​

DeleteServer(name string, opts ...Option) error

deletes exactly one named server and its tool/bridge caches via the existing transactional Yakit operation. A missing name is an error.

必填参数

参数名类型说明
namestring

可选参数

可作为可变参数 opts ...Option 传入选项;共 7 个可用选项,详见 Option 选项列表。

返回值

序号类型说明
r1error

ListServers​

ListServers(keyword string, opts ...Option) (*ServerPage, error)

includes enabled and disabled servers, ordered by name then ID. The keyword matches public names/types, never credential-bearing fields.

必填参数

参数名类型说明
keywordstring

可选参数

可作为可变参数 opts ...Option 传入选项;共 7 个可用选项,详见 Option 选项列表。

返回值

序号类型说明
r1*ServerPage
r2error

NewClient​

NewClient(transport string, endpoint string, opts ...Option) (*Client, error)

connects to stdio, sse or streamable_http and performs initialize.

For stdio, endpoint is a quoted command line, parsed without invoking a shell.

必填参数

参数名类型说明
transportstring
endpointstring

可选参数

可作为可变参数 opts ...Option 传入选项;共 7 个可用选项,详见 Option 选项列表。

返回值

序号类型说明
r1*Client
r2error

示例

c = mcp.NewClient("streamable_http", "http://127.0.0.1:8080/mcp", mcp.timeout(10))~
defer c.Close()
page = c.ListTools()~
dump(page.Tools)
result = c.CallTool("echo", {"message": "hello"})~
dump(result.Content)

可变参数选项列表​

以下按选项类型汇总全部可变参数选项(原先重复在各主函数下的选项表已收拢到此处):

1. 类型:Option​

涉及到的函数有:mcp.AddServer、mcp.Connect、mcp.DeleteServer、mcp.ListServers、mcp.NewClient

选项函数参数返回值说明
mcp.contextctx context.ContextOption
mcp.enabledenabled boolOption
mcp.envenv map[string]anyOption
mcp.headersheaders map[string]anyOption
mcp.limitlimit intOption
mcp.offsetoffset intOption
mcp.timeoutseconds float64Option