Class: SmilyCli::Commands::McpCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/smily_cli/commands/mcp_command.rb

Overview

smily mcp — talk to a BookingSync MCP server (Model Context Protocol) instead of the REST API. This is a separate mode with its own credential (mcp_token) and endpoint (mcp_url, defaulting to <base-url>/mcp).

Two layers:

* low-level — `tools` (discover) and `call` (invoke) work against any
MCP server, whatever tools it exposes;
* convenience — `list` / `get` / `schema` / `resources` mirror the REST
resource commands, routed through the server's generic dispatcher
tools, so the mental model carries over.

Instance Method Summary collapse

Methods inherited from BaseCommand

exit_on_failure?

Instance Method Details

#call(tool) ⇒ Object



47
48
49
50
# File 'lib/smily_cli/commands/mcp_command.rb', line 47

def call(tool)
  args = options["args"] ? parse_data(options["args"]) : {}
  render_tool_result(mcp_client.call_tool(tool, args))
end

#get(resource, id) ⇒ Object



92
93
94
95
96
97
# File 'lib/smily_cli/commands/mcp_command.rb', line 92

def get(resource, id)
  args = { "resource" => resource, "id" => coerce_id(id) }
  args["fields"] = context.fields if context.fields
  args.merge!()
  render_tool_result(mcp_client.call_tool(tool_name("get"), args), single: true)
end

#infoObject



22
23
24
# File 'lib/smily_cli/commands/mcp_command.rb', line 22

def info
  render_payload(mcp_client.connect)
end

#list(resource) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/smily_cli/commands/mcp_command.rb', line 78

def list(resource)
  args = { "resource" => resource }
  args["filter"] = QueryOptions.parse_filter(options["filter"]) if options["filter"]
  args["fields"] = context.fields if context.fields
  args["limit"] = options["limit"] if options["limit"]
  args["offset"] = options["offset"] if options["offset"]
  args["ids"] = options["ids"] if options["ids"]
  args["updated_since"] = options["updated_since"] if options["updated_since"]
  args.merge!()
  render_tool_result(mcp_client.call_tool(tool_name("list"), args))
end

#login(token = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/smily_cli/commands/mcp_command.rb', line 106

def (token = nil)
  mcp_token = token || options["mcp_token"]
  if mcp_token.to_s.empty?
    raise UsageError, "Provide the MCP token: smily mcp login <TOKEN> (or --mcp-token TOKEN)."
  end

  cfg = context.config
  cfg.set("mcp_token", mcp_token)
  cfg.set("mcp_url", options["url"] || options["mcp_url"]) if options["url"] || options["mcp_url"]
  cfg.save
  success("Saved MCP credentials to profile #{cfg.current_profile_name.inspect} (#{cfg.path}).")
  info_line("Try it with: smily mcp info")
end

#resourcesObject



53
54
55
# File 'lib/smily_cli/commands/mcp_command.rb', line 53

def resources
  render_tool_result(mcp_client.call_tool(tool_name("resources"), {}))
end

#schema(resource) ⇒ Object



100
101
102
# File 'lib/smily_cli/commands/mcp_command.rb', line 100

def schema(resource)
  render_tool_result(mcp_client.call_tool(tool_name("resource_schema"), { "resource" => resource }), single: true)
end

#toolsObject



27
28
29
30
31
32
33
34
35
# File 'lib/smily_cli/commands/mcp_command.rb', line 27

def tools
  list = mcp_client.list_tools
  if context.output_format == "table"
    rows = list.map { |t| { "name" => t["name"], "description" => t["description"] } }
    render_result(Result.new(records: rows, single: false))
  else
    render_payload(list)
  end
end