MCPToolProviding
Adopt to offer typed tools to AI apps through Droppy's MCP server (DroppyKit 1.21.0).
@MainActor protocol MCPToolProviding : Droplet
Return your tools from mcpTools and run one call in performMCPTool(named:argumentsJSON:). Arguments arrive as a JSON object in text, exactly as the AI app sent them: treat them as untrusted input, check every field, and never run anything an argument names. Return plain text or JSON text; Droppy hands JSON to the app as structured content. Throw an error with a readable localizedDescription to fail a call.
var mcpTools: [DropletMCPTool] {
[DropletMCPTool(name: "list_cities", title: "List cities",
summary: "Returns the cities World Clock shows, as a JSON array of names.")]
}
func performMCPTool(named name: String, argumentsJSON: String) async throws -> String {
switch name {
case "list_cities": return try String(decoding: JSONEncoder().encode(model.cities), as: UTF8.self)
default: throw ToolError.unknown(name)
}
}Droppy reads mcpTools when your droplet starts and whenever droplets change, so keep it cheap and stable. A tool with an invalid name, an empty title or summary, or a schema that is not a JSON object is left out, and at most 32 tools are listed. A call that runs longer than 60 seconds is answered with a timeout and your task is cancelled.
Actions you register through DropletShortcutsService are offered to AI apps too, without arguments, so a droplet that only needs "do the thing its shortcut does" needs nothing from this protocol. See Tools for AI apps.
- Note: Maturity: Supported. Host support: listed since DroppyKit 1.21.0. Droppy lists your tools only after the user allows "Browse and manage droplets" in Settings, MCP, and asks the user before every call to a tool marked
isDestructive. A host older than 1.21.0 never asks for them, so declareminAPI1.21.0.
Properties
mcpTools
@MainActor var mcpTools: [DropletMCPTool] { get }
The tools this droplet offers right now.
Methods
performMCPTool(named:argumentsJSON:)
@MainActor func performMCPTool(named name: String, argumentsJSON: String) async throws -> String
Runs one tool. argumentsJSON is a JSON object as text; return plain text or JSON text for the AI app.