Discover Packages
github.com/fzxbl/mcp-toolify
example
greeter
package
Version:
v0.9.0
Opens a new window with list of versions in this module.
Published: Nov 24, 2026
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 1 module, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
Documentation
Documentation
¶
Package greeter 是用 mcp-toolify 暴露工具的最小示例。
在函数 godoc 上加 `// mcp:tool` 再跑 `go generate`,它就成了一个 MCP 工具。
labels 的 key 语义由部署方的配置解释(基座不解释):本示例沿用
capability / risk 两个 key,与 example/conf/mcp.toml 里的 token 准入、
配额规则、二次确认规则一致。
AddNumbers 返回两个整数之和(演示多返回值按变量名打包)。
param: a — 第一个加数
param: b — 第二个加数
mcp:tool
mcp:labels=capability=read,risk=none
Greet 生成一句问候语。
param: name — 要问候的名字
param: excited — 是否在结尾加感叹号
mcp:tool
mcp:labels=capability=read,risk=none
Shout 把一句话改成全大写(示例里的「高危写操作」)。
它本身当然是无害的,标成 capability=write,risk=high 只是为了让示例真的走一遍准入判定:
example/conf/mcp.toml 里只读通道看不见它、运维通道才能执行。按 label 管辖的插件
(配额、审批一类)也用同一组 label,把它换成你自己那个真会改线上状态的函数即可。
param: text — 要改写的文本
mcp:tool
mcp:labels=capability=write,risk=high
type Desk struct {
Greeting string
}
Desk 演示「方法工具」:工具绑在一个由使用方注入的实例上(比如带着数据库连接、
配置的服务对象)。生成器不会替你构造它,而是在 tools.Impls 里留一个字段,
装配时(见 example/cmd/server)把实例交给 tools.NewRegistrar。
Welcome 迎接来访者,并带上调用主体(演示首参 context.Context 与注入实例)。
首个参数 ctx 不会出现在工具的入参 schema 里,传进来的就是本次请求的 ctx,
因此能取到鉴权中间件写入的调用主体。
param: name — 来访者的名字
mcp:tool
mcp:labels=capability=read,risk=none
type Profile struct {
Name string `json:"name" jsonschema:"来访者名字"`
Length int `json:"length" jsonschema:"名字的字符数"`
}
Profile 是 Describe 的返回值;字段上的 jsonschema tag 会作为返回字段说明追加到工具描述。
Describe 返回名字的基本信息(演示返回字段说明会追加到工具描述)。
param: name — 来访者名字
mcp:tool
mcp:labels=capability=read,risk=none
Source Files
¶
Click to show internal directories.
Click to hide internal directories.