Documentation
¶
Overview ¶
Package surface renders a snapshot's declared MCP capability surface - instructions, tools, prompts, resources, resource templates - as text for something that judges it (a model, a third-party classifier), stopping once a caller-supplied character budget is used. Keeping every capability kind here prevents callers from counting declarations they forgot to render.
Index ¶
- func Build(snap *model.Snapshot, budget int, f Formatters) (text string, included, skipped int)
- func CompactJSON(v map[string]any) string
- func Locator(capKind, capability, field string) string
- func PromptArguments(args []model.PromptArgument) string
- func ResourceIdentity(r model.ResourceInfo) string
- func ToolExtras(t model.ToolInfo) string
- type Formatters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build renders snap's declared surface, adding entries first-fit until budget characters have been used: an entry that does not fit is skipped, but a later, shorter entry can still fit, so included/skipped is not "the first N" or "the last N" - just a count of what did and did not make it in
func CompactJSON ¶
CompactJSON renders v as single-line JSON for embedding in a surface entry, or "{}" for an empty or unmarshalable value. Every formatter that puts a schema, annotations or _meta block into an entry goes through this, so the two do not drift into rendering the same map differently.
func Locator ¶
Locator is the pointer a finding on declared text carries instead of a file path: the capability kind, the capability's name unless it is the server itself, and the field
func PromptArguments ¶
func PromptArguments(args []model.PromptArgument) string
PromptArguments renders one line per declared prompt argument (name, whether it is required, and its description). An argument description is as much attacker-writable declared text as the prompt's own description or rendered body, so it belongs in the same surface.
func ResourceIdentity ¶
func ResourceIdentity(r model.ResourceInfo) string
ResourceIdentity renders a resource or template's URI (or URI template) and declared MIME type. The URI is often the most security-relevant field and must not disappear behind a friendly name or title.
func ToolExtras ¶
ToolExtras renders the parts of a tool declaration beyond name, description and input schema: output schema, annotations and _meta. These maps are as attacker-controlled as the description, so omitting them would judge less content than coverage claims was analyzed.
Types ¶
type Formatters ¶
type Formatters struct {
Instructions func(text string) string
Tool func(t model.ToolInfo) string
Prompt func(p model.PromptInfo) string
Resource func(r model.ResourceInfo) string
Template func(t model.ResourceInfo) string
}
Formatters renders one capability of each kind as a surface entry. Every field must be set: Build calls whichever formatter a declared item needs, so a nil formatter panics on the first snapshot that declares that kind rather than silently skipping it.