神经MCP
用于与Nerves设备交互的MCP(模型上下文协议)服务器。使AI助手能够在通过UART或SSH连接的嵌入式设备上评估Elixir代码。
安装
添加到您的依赖关系中:
def deps do
[
{:nerves_mcp, "~> 0.1.0"}
]
end用法
NervesMCP既可以作为Mix任务运行,也可以作为独立的escript运行。第一个参数是串行设备路径或SSH主机——NervesMCP会根据路径自动检测哪个。
混合任务
# Serial — auto-detected from /dev/tty* path
mix nerves_mcp /dev/ttyUSB0
mix nerves_mcp /dev/ttyUSB0 --speed 9600
# SSH — anything that isn't a serial path is treated as a host
mix nerves_mcp nerves.local
mix nerves_mcp nerves.local --user root --ssh-port 2222已写入
构建escript并直接运行它:
mix escript.build
./nerves_mcp /dev/ttyUSB0
./nerves_mcp nerves.local --user exnvr --port 4000选项
| 标志 | 描述 | 默认值 |
|---|---|---|
--port | MCP服务器HTTP端口 | 13000 |
--speed | 串行波特率 | 115200 |
--user | SSH用户名 | root |
--ssh-port | SSH端口 | 22 |
--serial | 强制串行模式(传递装置) | |
--ssh | 强制SSH模式(通过主机) |
短别名: -p (端口), -s (速度), -u (用户)。
配置文件
连接设置也可以在中定义 config/config.exs.CLI参数会覆盖配置值。
# Serial
config :nerves_mcp, :port, 13000
config :nerves_mcp, :connection,
type: :uart,
port: "/dev/ttyUSB0",
speed: 115_200
# Or SSH
config :nerves_mcp, :connection,
type: :ssh,
host: "nerves.local",
user: "root",
port: 22配置就绪后,您可以在没有任何参数的情况下开始:
mix nerves_mcp或覆盖特定值:
mix nerves_mcp --speed 9600 # use config but change baud rate
mix nerves_mcp other.local # switch to a different host entirely自动检测
如果第一个论点以 /dev/tty, /dev/cu.,或 /dev/serial,它被视为串行设备。否则,它将被视为SSH主机。使用 --serial 或 --ssh 明确地说:
mix nerves_mcp --serial /dev/ttyACM0
mix nerves_mcp --ssh 192.168.1.100连接到MCP服务器
运行后,MCP服务器可在以下位置使用:
http://localhost:13000/mcp或者您指定的任何端口 --port.
MCP工具
设备_值
计算设备上的Elixir代码并返回表达式的返回值。
设备值输出
评估Elixir代码并捕获IO输出(代码通过以下方式打印的内容 IO.puts, IO.write等等)。
grep_ring_logger
过滤设备的 RingLogger 通过子字符串或正则表达式模式进行缓冲。可选的 tail 仅返回最后N个匹配项。
grep_dmesg
过滤设备的 dmesg (内核环缓冲区)通过子字符串或正则表达式模式。可选的 tail 仅返回最后N个匹配项。
交互式控制台
从IEx,您可以打开设备的交互式控制台:
iex> console()
Connected to device console. Commands: #quit, #history
---这使您可以直接与设备的IEx shell进行交互。命令:
#quit-退出控制台并返回本地IEx#history-显示缓冲输出历史记录
输出历史记录
即使没有连接控制台,设备输出也会存储在循环缓冲区中。这包括MCP工具调用的输出。
iex> history()或使用 #history 而在控制台中。
许可证
阿帕奇-2.0
