toolrun

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 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.

Documentation

Overview

Package toolrun 提供两个产品共用的 MCP 调用支持:一次调用内的诊断 scope、工具注册 包装,以及输入校验失败的统一结果。

包的组成:Scope 与 NewScope 分配调用 ID 并持有日志入口,AddTool 注册工具并 记录失败,ProtectInput 把 SDK 参数的原始诊断换成工具声明的安全结果。逻辑分页的 输入解析与输出字段在 paging.go。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTool

func AddTool[In, Out any](scope *Scope, server *mcp.Server, tool *mcp.Tool, handler mcp.ToolHandlerFor[In, Out])

AddTool 注册工具,并为每次调用附上调用上下文与不含凭据的诊断。SDK 参数拒绝时保留 固定文案的结果布局;handler 的结果与错误原样交给 MCP SDK。

func ParseListPlan

func ParseListPlan(input ListIn) (pagination.PagePlan, error)

ParseListPlan 在开始 SDK 工作前校验外部输入;分页语义由 internal/pagination 拥有。

func ProtectInput

func ProtectInput(server *mcp.Server, name string, failure func() *mcp.CallToolResult)

ProtectInput 在 typed handler 执行前拦截 SDK 的参数校验诊断,换成 failure 给出的安全 结果;handler 已经执行时不动其结果。

Types

type ListIn

type ListIn struct {
	Page  *int `json:"page,omitempty" jsonschema:"1-based logical page; requires a positive limit"`
	Limit *int `json:"limit,omitempty" jsonschema:"maximum items; 0 returns all items"`
}

ListIn 区分省略 limit(读取一个默认批次)与 limit=0(返回全部结果)。

type Scope

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

Scope 在一个产品运行时内分配递增的调用 ID,并保存执行日志入口。

func NewScope

func NewScope(logger *slog.Logger) *Scope

NewScope 保留执行日志;logger 为 nil 时工具保持静默。

Jump to

Keyboard shortcuts

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