使用说明
NetLogo的第一个MCP(模型上下文协议)服务器——使AI助手能够通过自然对话创建、运行和分析基于代理的模型。
适用于: Claude Code、Claude Desktop、Cursor、Windsurf、VS Code(Copilot)、Cline、Continue、Roo Code、Zed、OpenCode、Codex——任何支持MCP的工具。
为什么选择NetLogo MCP?
作为一名正在学习基于代理的建模课程的人工智能学生,我搜索了一个MCP服务器来控制NetLogo——什么都没有。所以我建了一个。
你不用手动编写NetLogo代码、点击按钮和调整滑块,而是用简单的英语告诉你的AI助手你想要什么:
“用100只绵羊和20只狼创建一个捕食者-猎物模型。运行500只蜱虫,向我展示种群动态。”
人工智能编写代码,运行模拟,并通过对话向您显示结果。
默认情况下,会打开一个真正的NetLogo窗口(首次使用时),这样您就可以实时观看模拟运行。无头模式可用于CI或服务器。
特性
- 从代码创建模型 --使用真正的界面小部件:滑块、开关、按钮、监视器
- 运行模拟 并将逐笔数据收集为降价表
- 运行BehaviorSpace实验 --通过无头启动器进行并行参数扫描
- 将视图导出为PNG --聊天中可见内联
- 检查一切 --世界状态、代理样本、热图补丁网格
- CoMSES-Net集成 --从最大的同行评审ABM库中搜索并安全运行模型
- 内置参考 --NetLogo原语、编程指南和6→7 过渡指南作为MCP资源
- 懒惰的创业 --NetLogo窗口仅在您实际使用工具时打开,而不是在您的AI客户端连接时打开
看 docs/TOOLS.md 获取所有25个工具、小部件模式和提示的完整参考。
先决条件
| 要求 | 是否通过终端安装? | 如何 |
|---|---|---|
| Python 3.10+ | 是 | Windows: winget install Python.Python.3.12 ·macOS: brew install python@3.12 ·Linux: sudo apt install python3.12 |
| Java JDK 11+ | 是 | Windows: winget install EclipseAdoptium.Temurin.21.JDK ·macOS: brew install --cask temurin ·Linux: sudo apt install openjdk-21-jdk |
| Netlogo 7.0+ | 否--手动 | 下载自 ccl.northwestern.edu/netlogo |
只有NetLogo需要手动下载。 其他所有内容都可以通过终端安装,下面的Zero Config Setup提示符会自动处理这些内容。
零配置设置(推荐)
如果您正在使用AI编码工具,请将下面的提示复制到您的聊天中。AI将检测您的操作系统,查找您的NetLogo和Java安装,克隆仓库,安装依赖关系,配置MCP客户端,并告诉您如何使用它。
Click to copy the setup prompt
Please set up the NetLogo MCP server for me end-to-end. Follow these steps carefully:
1. **Detect my environment**
- Identify my OS (Windows / macOS / Linux).
- Check Python version (need 3.10+). If missing, tell me to install it first and stop.
- Check for Java JDK 11+ (not JRE). Look in common locations (JAVA_HOME env var, standard install dirs). If missing, tell me to install Adoptium Temurin JDK 11+ and stop.
- Check for NetLogo 7.0+. Look in common locations:
- Windows: `C:/Program Files/NetLogo*`
- macOS: `/Applications/NetLogo*`
- Linux: `/opt/netlogo*`, `~/netlogo*`
If NetLogo isn't installed, tell me to download it from https://ccl.northwestern.edu/netlogo/download.shtml and stop.
2. **Install**
- Run: `pip install netlogo-mcp`
- Verify the `netlogo-mcp` command is now available on my PATH.
3. **Identify my MCP client**
- Figure out which AI tool I'm using (Claude Code, Cursor, Windsurf, Cline, Continue, Roo Code, Zed, OpenCode, VS Code Copilot, Codex, or Claude Desktop).
- If you're not sure, ask me.
4. **Configure the MCP client**
- Locate (or create) the correct config file for my client (see
https://github.com/Razee4315/NetLogo-MCP/blob/main/docs/CLIENTS.md
for exact paths and schemas per client).
- Add a `netlogo` server entry with:
- `command`: `netlogo-mcp`
- `env.NETLOGO_HOME`: the NetLogo path you detected
- `env.JAVA_HOME`: the JDK path you detected
- Use the exact JSON schema for my specific client (e.g. `"type": "stdio"` for Cursor, `"servers"` key for VS Code).
- Preserve any existing config entries — merge, don't overwrite.
- IMPORTANT: configure it for THIS project only (project-scope config file), not globally, unless I say otherwise — a global entry loads the server in every session.
5. **Tell me what to do next**
- Tell me to fully restart my AI tool for the new MCP server to load.
- Tell me the NetLogo window opens on the FIRST model tool call, and that call takes 30–60 seconds while the Java Virtual Machine starts. Tell me NOT to click stop during this wait.
- Give me this exact test prompt to try after restart:
> "Create a simple predator-prey model with wolves and sheep on a green landscape. Run setup, then run 100 ticks while tracking wolf and sheep counts. Export the view before and after so I can see how the world evolved."
- Tell me where models and exports are saved (by default, the current working directory's `models/` and `exports/` folders) and that I can browse them with the `list_models` tool.
Do not skip any verification step. If something fails, stop and tell me exactly what failed and how to fix it.
手动安装
pip install netlogo-mcp
然后将服务器添加到MCP客户端。对于Claude Code,请添加到您的 项目的 .mcp.json:
{
"mcpServers": {
"netlogo": {
"command": "netlogo-mcp",
"args": [],
"env": {
"NETLOGO_HOME": "C:/Program Files/NetLogo 7.0.3",
"JAVA_HOME": "C:/Program Files/Eclipse Adoptium/jdk-25.0.2.10-hotspot"
}
}
}
}
重新启动Claude Code并用验证 /mcp.
提示: 首选项目范围配置(
.mcp.json在一个项目中)通过全局配置——全局条目在每个项目的每个会话中加载服务器。
使用游标、Windsurf、VS代码、Cline、Continue、Roo代码、Zed、OpenCode、Codex或Claude桌面? 看 docs/CLIENTS.md 用于所有11个客户端的精确配置。所有配置选项(GUI/无头模式、目录、限制)都在 docs/CONFIGURATION.md.
发展还是贡献? 克隆仓库并安装可编辑版本:
git clone https://github.com/Razee4315/NetLogo-MCP.git
cd NetLogo-MCP
pip install -e ".[dev]"
码头工人
该映像在NetLogo(无头)中与其捆绑的JRE一起烘烤,无需安装主机:
docker build -t netlogo-mcp .
docker run -i --rm netlogo-mcp
MCP客户端配置:
{
"mcpServers": {
"netlogo": {
"command": "docker",
"args": ["run", "-i", "--rm", "netlogo-mcp"]
}
}
}
Docker仅无头运行(无GUI模式)。添加 -v ./exports:/data/exports 将导出的视图和世界保留在主机上。
快速开始
连接后,在任何MCP客户端中尝试以下提示:
> Create a simple NetLogo model with 50 turtles doing a random walk.
Run setup, simulate 100 ticks, and export the view.
> Open the Wolf Sheep Predation model and run a parameter sweep
on initial-number-wolves from 10 to 100.
> Build a disease spread model with sliders for population size and
infection chance.
第一次模型工具调用需要30-60秒 JVM启动时,NetLogo窗口会在准备就绪时出现。不要点击停止。之后的每一个电话都是即时的。
故障排除
| 问题 | 解决方案 |
|---|---|
NETLOGO_HOME is not set |
将环境变量设置到NetLogo安装目录 |
JAVA_HOME is not set |
将其设置到JDK目录(而不是JRE) |
| JVM启动时崩溃 | 确保JAVA_HOME指向JDK 11+,而不是旧版本 |
No model is loaded |
呼叫 open_model 或 create_model 在使用其他工具之前 |
| 第一个模型调用挂起30-60秒 | 正常——JVM正在预热。不要点击停止。 |
| 当我的AI客户端启动时,NetLogo窗口打开 | 您有 NETLOGO_EAGER_START=true set,或旧版本——默认情况下,窗口仅在首次使用工具时打开 |
| 服务器无法连接 | 运行 netlogo-mcp 在终端中手动查看错误输出 |
文档
- docs/TOOLS.md --完整的工具参考、小部件模式、行为空间和CoMSES指南
- docs/CONFIGURATION.md --所有环境变量,GUI与headless,启动时间
- docs/SECURITY.md --安全模型和信任边界
- docs/CLIENTS.md --为所有11个MCP客户端设置
- docs/DEVELOPMENT.md --项目结构、运行测试、架构说明
- 贡献.md --如何做出贡献
- 更改日志.md --版本历史
上市
引用
如果您在研究或教学中使用NetLogo MCP,请引用它——点击 “引用此存储库” 在GitHub侧栏中,或参见 引文.cff.
作者
保存阿巴斯 电子邮件:saqlainrazee@gmail.com github: @Razee4315 领英: @saveinrazee
许可证
该项目根据 MIT许可证 --可以出于任何目的自由使用、修改和分发。
