适用于 FiveM 和 RedM 的 Lavender MCP 服务器

Lavender MCP Server 是一个适用于 FiveM、FiveM for GTAV Enhanced 和 RedM 的开发资源。它会在你本地的 FXServer 或 Cfx Server 实例中运行一个小型 MCP(模型上下文协议)服务器,以便像 Claude Code、Codex 或 Cursor 这样的 AI 编程代理能够与其进行交互。

代理可以列出并重启资源、读取服务器控制台、运行控制台命令,以及在服务器或已连接的客户端上运行 JavaScript 或 Lua。

你的其他资源也可以通过 exports 注册自己的工具。如果你的框架中有一些你希望代理能够执行的操作(例如查找玩家、编辑某些数据等),你可以通过资源 exports 从你自己的资源中添加这些功能,而无需修改本资源。

如何使用?

本资源旨在提升与 AI 代理协作时的效率。它允许代理从你正在运行的开发服务器和本地游戏客户端获取直接上下文,以进行实时研究、开发和调试,从而更容易实现完全自主的工作。

一些示例:

  • “重启 my_resource 并检查控制台是否有错误”
  • “我的玩家现在在哪里”(它会在你的客户端上运行 GetEntityCoords(PlayerPedId()))
  • “在我旁边生成一辆 adder”
  • “运行 status 并告诉我谁连接了”
  • “X 坏了,找出原因并修复它”,然后它会读取日志、编辑文件、重启资源并再次检查日志

安全性

这仅用于本地开发,请勿在正式服务器上运行。

作为额外的安全防护,该资源仅监听 127.0.0.1,会检查 Host 和 Origin 标头,并且如果 token 短于 32 个字符或是示例配置中的占位符,则不会打开端口。

工具

工具 功能说明 所需 ACE 权限
get_server_info 服务器、游戏、运行时、运行时间和玩家数量 无
list_clients 已连接的玩家及其标识符 无
get_client_info 特定服务器 ID 的详细信息 无
execute_code 在服务器或选定客户端上运行 JavaScript 或 Lua 无
get_console_logs 服务器控制台的最后几行日志(最多 1000 行) 无
list_resources 资源及其状态 无
start_resource / stop_resource 启动或停止某个资源 无
restart_resource 重启某个资源 command.restart
refresh_resources 重新扫描 resources 文件夹 command.refresh
execute_command 运行服务器控制台命令 command.
get_convar / set_convar 读取或设置 convar 无

它不会启动、停止或重启自身。

有关注册自定义工具的信息,请参阅 EXTENDING.md。每个注册工具的资源都需要在 server.cfg 中配置自己的 ACE 权限行。

安装

从 releases 页面下载 zip 压缩包,将 lavender-mcp-server 文件夹放入你的 resources 目录中,生成一个随机 token,并将以下内容添加到你的 server.cfg 中:

# Token configuration
set lavender_mcp_token "PASTE_YOUR_TOKEN_HERE"

# Needed for the restart and refresh tools.
add_ace resource.lavender-mcp-server command.restart allow
add_ace resource.lavender-mcp-server command.refresh allow

ensure lavender-mcp-server

默认端口为 3414,你可以使用 set lavender_mcp_port 1234 进行更改。启动时它会在控制台打印出 URL。

然后使用 URL http://127.0.0.1:3414/mcp 和 Authorization: Bearer 标头将其添加到你的 MCP 客户端中。

对于 Claude Code:

export LAVENDER_MCP_TOKEN="<same token as in server.cfg>"

claude mcp add --transport http --scope user \
  --header "Authorization: Bearer $LAVENDER_MCP_TOKEN" \
  lavender_mcp http://127.0.0.1:3414/mcp

README 中包含 Codex 和 .mcp.json 的版本。只要其他客户端支持 Streamable HTTP,应该也能正常工作。

前置需求

  • FXServer artifact 25943 或更高版本(需要 node 22),或者 Cfx Server
  • 支持 Streamable HTTP 的 MCP 客户端

已知限制

  • 它无法读取客户端日志,因为服务器无法访问这些日志。相反,它会告诉代理 FiveM 和 RedM 在你的电脑上保存日志文件的位置,但这只有在代理与游戏运行在同一台机器上时才有效。
  • 代码在资源自身的运行时中执行,因此无法看到其他资源的局部变量。请使用该资源的 exports 或为其注册一个工具。
  • Lua 代码同步运行(你仍然可以在其中创建线程)。

链接

代码基于 MIT 许可协议提供。

如果你发现 bug,请在 GitHub 上提交 issue。欢迎贡献代码。

代码可访问 是
基于订阅 否
代码行数(约) 约 2000 行(不包括测试)
需求与依赖 FXServer 版本 25943+,兼容的 MCP 客户端
支持 GitHub issues
查看英文原文 (Original)

Lavender MCP Server is a development resource for FiveM, FiveM for GTAV Enhanced and RedM. It runs a small MCP (Model Context Protocol) server inside your local FXServer or Cfx Server instance so an AI coding agent like Claude Code, Codex or Cursor can interact with it.

The agent can list and restart resources, read the server console, run console commands and run JavaScript or Lua on the server or on a connected client.

Your other resources can also register their own tools through exports. If your framework has stuff you’d want the agent to be able to do (look up a player, edit some data etc) you can add it from your own resource without touching this resource via resource exports.

How can you use it?

This resource is made to speed things up when working with agents. It allows it to retrieve direct context from your running dev server and local game client(s) to perform live research, development and debugging, making it easier to accomplish work in full autonomy.

Some examples:

  • “restart my_resource and check the console for errors”
  • “where is my player right now” (it runs GetEntityCoords(PlayerPedId()) on your client)
  • “spawn an adder next to me”
  • “run status and tell me who’s connected”
  • “X is broken, find out why and fix it”, then it reads the logs, edits the file, restarts the resource and checks the logs again

Security

This is for local development only, do NOT run it on a live server.

The resource only listens on 127.0.0.1, checks the Host and Origin headers, and won’t open the port if the token is shorter than 32 characters or is one of the placeholders from the example config as additional safeguards.

Tools

Tool What it does ACE needed
get_server_info Server, game, runtime, uptime, player count None
list_clients Connected players and identifiers None
get_client_info Details for one server ID None
execute_code Run JavaScript or Lua on the server or on selected clients None
get_console_logs Last lines of the server console (up to 1000) None
list_resources Resources and their states None
start_resource / stop_resource Start or stop a resource None
restart_resource Restart a resource command.restart
refresh_resources Rescan the resources folder command.refresh
execute_command Run a server console command command.<name>
get_convar / set_convar Read or set a convar None

It won’t start, stop or restart itself.

For registering your own tools see EXTENDING.md. Each resource that registers tools needs its own ACE line in server.cfg.

Installation

Download the zip from the releases page, put the lavender-mcp-server folder in your resources, generate a random token and add this to your server.cfg:

# Token configuration
set lavender_mcp_token "PASTE_YOUR_TOKEN_HERE"

# Needed for the restart and refresh tools.
add_ace resource.lavender-mcp-server command.restart allow
add_ace resource.lavender-mcp-server command.refresh allow

ensure lavender-mcp-server

Default port is 3414, you can change it with set lavender_mcp_port 1234. When it starts it prints the URL in the console.

Then add it to your MCP client with the URL http://127.0.0.1:3414/mcp and an Authorization: Bearer <token> header.

For Claude Code:

export LAVENDER_MCP_TOKEN="<same token as in server.cfg>"

claude mcp add --transport http --scope user \
  --header "Authorization: Bearer $LAVENDER_MCP_TOKEN" \
  lavender_mcp http://127.0.0.1:3414/mcp

The README has the Codex and .mcp.json versions. Other clients should work too as long as they support Streamable HTTP.

Requirements

  • FXServer artifact 25943 or newer (it needs node 22), or Cfx Server
  • An MCP client that supports Streamable HTTP

Known limitations

  • It can’t read client logs because the server has no access to them. Instead it tells the agent where FiveM and RedM keep their log files on your PC, which only helps if the agent runs on the same machine as the game.
  • Code runs inside the resource own runtime, so it can’t see another resource’s local variables. Use that resource’s exports or register a tool for it.
  • Lua code runs synchronously (you can still create threads inside it).

Links

Code is available under a MIT License.

If you find a bug please open an issue on GitHub. Contributions are welcomed.

Code is accessible Yes
Subscription-based No
Lines (approximately) ~2000 (not counting tests)
Requirements & dependencies FXServer version 25943+, compatible MCP client
Support GitHub issues

本文资源搬运自 CFX.re FiveM 官方论坛,原作者:Nimoa。原帖地址:https://forum.cfx.re/t/lavender-mcp-server-for-fivem-and-redm/5429583

原帖标签:script, free

THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容