Class: SmilyCli::Commands::McpCommand
- Inherits:
-
BaseCommand
- Object
- Thor
- BaseCommand
- SmilyCli::Commands::McpCommand
- 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
- #call(tool) ⇒ Object
- #get(resource, id) ⇒ Object
- #info ⇒ Object
- #list(resource) ⇒ Object
- #login(token = nil) ⇒ Object
- #resources ⇒ Object
- #schema(resource) ⇒ Object
- #tools ⇒ Object
Methods inherited from BaseCommand
Instance Method Details
#call(tool) ⇒ Object
47 48 49 50 |
# File 'lib/smily_cli/commands/mcp_command.rb', line 47 def call(tool) args = ["args"] ? parse_data(["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!(account_arg) render_tool_result(mcp_client.call_tool(tool_name("get"), args), single: true) end |
#info ⇒ Object
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(["filter"]) if ["filter"] args["fields"] = context.fields if context.fields args["limit"] = ["limit"] if ["limit"] args["offset"] = ["offset"] if ["offset"] args["ids"] = ["ids"] if ["ids"] args["updated_since"] = ["updated_since"] if ["updated_since"] args.merge!(account_arg) 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 login(token = nil) mcp_token = token || ["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", ["url"] || ["mcp_url"]) if ["url"] || ["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 |
#resources ⇒ Object
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 |
#tools ⇒ Object
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 |