import {
McpClientRuntimeCapability,
type McpClientScope,
type McpClientToolCall,
type RuntimeCapabilityRegistry
} from '@xpert-ai/plugin-sdk'
export async function callApprovedTool(
capabilities: RuntimeCapabilityRegistry,
scope: McpClientScope,
request: McpClientToolCall
) {
const client = capabilities.require(McpClientRuntimeCapability)
const tools = await client.tools.list(scope)
const selected = tools.find((tool) => tool.name === request.toolName)
if (!selected || selected.contractHash !== request.contractHash) {
throw new Error('Rediscover and approve the changed tool contract')
}
return client.tools.call(scope, request)
}