# Dedicated Raxol MCP server exposing only the first-party Web3 tools. # Keep Raxol's local data inside this disposable project. Set inside the VM, never # exported by the launcher, so no version manager shim sees a redirected XDG. project = Path.dirname(__ENV__.file) System.put_env(%{ "XDG_DATA_HOME" => Path.join(project, ".data"), "XDG_CONFIG_HOME" => Path.join(project, ".config") }) # stdout is the MCP protocol stream, so every log line goes to stderr. A handler's # output device cannot be changed in place, so re-add the default handler, keeping # its formatter and filters, with stderr as the device. {:ok, handler} = :logger.get_handler_config(:default) :ok = :logger.remove_handler(:default) :ok = :logger.add_handler(:default, :logger_std_h, %{handler | config: %{type: :standard_error}}) {:ok, _} = Application.ensure_all_started(:raxol_web3) alias Raxol.MCP.{Registry, Server, Transport.Stdio} alias Raxol.Web3.{Backend.Blockscout, Backend.JSONRPC, MCP.Tools, Router} # Public reads for both ends of the starter's route, Base to Ethereum. No keys. # Each chain asks its explorer first and then two keyless public nodes, in this # order: an explorer can refuse (base.blockscout.com answers API paths with a # Cloudflare challenge), and the router fails over to a node for the reads a # node can answer. providers = [ {"eip155:1", ["https://ethereum-rpc.publicnode.com", "https://eth.drpc.org"]}, {"eip155:8453", ["https://mainnet.base.org", "https://base-rpc.publicnode.com"]} ] backends = Enum.flat_map(providers, fn {chain, nodes} -> {:ok, explorer} = Blockscout.new(chain) nodes = Enum.map(nodes, fn url -> {:ok, node} = JSONRPC.new(chain, url: url) node end) [explorer | nodes] end) {:ok, registry} = Registry.start_link(name: :contributor_web3_registry, server: :contributor_web3_server) :ok = Tools.register(registry, Router.new(backends)) {:ok, server} = Server.start_link( name: :contributor_web3_server, registry: registry, transport: :stdio, authorizer_source: :configured, authorizer: fn name, _, _ -> if name in Tools.names(), do: :allow, else: {:deny, "Web3 tools only"} end ) {:ok, stdio} = Stdio.start_link(server: server) ref = Process.monitor(stdio) receive do {:DOWN, ^ref, :process, ^stdio, :normal} -> :ok {:DOWN, ^ref, :process, ^stdio, reason} -> exit(reason) end