跳转到内容

接入 AI 智能体

Ferris IDEA 通过 Model Context Protocol(MCP)把自己的操作作为工具提供给 AI 智能体,也就是说它本身就是一个 MCP 服务器。 你在智能体的配置中添加一项,智能体就能立即读取、搜索项目并预览修改。它做出的每一次修改都要检查你按项目授予的权限。

接入方式 状态
通过标准输入输出的 MCP(ferris-idea mcp),不需要窗口 Works
从运行中的窗口通过 HTTP 提供 MCP,可读取你尚未保存的编辑器内容 Experimental
Claude Code 把窗口作为它的 IDE 连接,在窗口中显示 diff Experimental(macOS 和 Linux)

项目使用 Claude Code 开发并手动测试。其他客户端使用同样的服务器配置项,预期可以使用,但项目尚未测试。

  1. 添加服务器客户端中的一个配置项:ferris-idea 程序、单词 mcp,以及项目的绝对路径。
  2. 智能体读取一开始提供九个核心工具:workspace_info、list_files、read_file、search_in_files 等。读取不需要权限。
  3. 智能体请求修改这次调用需要一项权限,例如 write。If not: 被拒绝:回答写明缺少的权限和需要添加的配置项。没有任何修改。
  4. 你授予权限在设置目录的 agent-permissions.toml 中添加一个 [[workspace]] 配置项。
  5. 调用通过并被记录.ferris-idea/agent-log.jsonl 中的一行记录了工具、检查的权限和结果。
权限保存在你的设置目录中。项目内的文件永远不会给智能体授予任何权限。
  • 已经安装 Ferris IDEA(安装)。MCP 客户端启动服务器时的 PATH 很短,所以下面每个配置项都使用程序的绝对路径: macOS 上是 /Applications/FerrisIDEA.app/Contents/MacOS/ferris-idea,Debian 包是 /usr/bin/ferris-idea,AppImage 则是你放置它的位置。
  • 项目目录已经存在。使用它的绝对路径。
  • 不需要 API 密钥、账号或环境变量。服务器运行在你的机器上,只与启动它的客户端通信。

在项目目录中运行:

Terminal window
claude mcp add ferris-idea -- /Applications/FerrisIDEA.app/Contents/MacOS/ferris-idea mcp "$PWD"

Tested with v1.6.0 on 2026-12-04.

加上 --scope project 时,Claude Code 会把配置项写入该目录的 .mcp.json,与项目一起共享。之后它会询问一次是否使用这个服务器; 下次在那里启动 claude 时回答即可。claude mcp list 显示服务器及其状态。

重启客户端或重新加载它的服务器。向智能体提一个问题,例如 “What is this project? Use the ferris-idea tools.”(这是什么项目?请使用 ferris-idea 工具。)它会根据 workspace_info 和 list_files 回答。

一开始,智能体只看到九个核心工具和 find_tools;find_tools 会搜索程序的全部工具,并打开智能体需要的那些。要从一开始就提供更多工具, 在参数中加上 --tools 和工具组:["mcp", "/path/to/project", "--tools", "vcs,run"],或者 all。

工具组有 core、files、navigation、editing、inspections、run、debug、vcs、database、web、containers、remote 和 ide。提供工具并不等于授权:会修改内容的工具仍然需要相应的权限。

第一次被拒绝的调用,以及授权

Section titled “第一次被拒绝的调用,以及授权”

让智能体修改一个文件。调用会被拒绝,回答会说明该怎么做(以下为程序的英文原始输出):

not granted: this workspace does not grant agents the `write` right (create, change, move or
delete files of the workspace); nobody was asked. Only the user can grant it: answer "Always for
This Workspace" when the Ferris IDEA window asks a client of its MCP server over HTTP, or add to
~/.config/ferris-idea/agent-permissions.toml:
[[workspace]]
path = "/Users/you/Projects/demo-shop"
allow = ["write"]
Use dry_run to see what would happen.
  1. 打开设置目录中的 agent-permissions.toml:macOS 和 Linux 上是 ~/.config/ferris-idea/(或 $XDG_CONFIG_HOME/ferris-idea/, 或 FERRIS_IDEA_CONFIG_DIR 指定的目录)。如果文件不存在,就创建它。

  2. 添加信息中给出的配置项。只授予任务需要的权限。

    [[workspace]]
    path = "/Users/you/Projects/demo-shop"
    allow = ["write"]
  3. 再让智能体试一次。每次会话和每次调用都会重新读取这个文件,不需要重启。

智能体可以用工具 agent_permissions 查看自己被授予了什么:它返回权限、读取的文件以及文件中的任何 problem。有错误的文件不授予任何权限, 项目内的授权文件会被忽略。

会运行代码的权限 run、debug 和 trust 还需要项目已被信任。在安全模式(safe mode)下,无论有什么权限,调用都会以 Safe mode: … is not trusted 被拒绝。

每次调用会修改内容的工具,都会在项目的 .ferris-idea/agent-log.jsonl 中留下一行,包括被拒绝的调用和 dry run:

{"time":1796345464,"tool":"copy_file","caller":"mcp:claude-code","call":true,"changes":["files"],"dry_run":false,"rights":[{"right":"write","given":false}],"database":[],"targets":{"path":"src/main.rs","new_name":"copy.rs","dry_run":false},"lengths":{"target_dir":3},"result":"refused"}
{"time":1796345470,"tool":"copy_file","caller":"mcp:claude-code","call":true,"changes":["files"],"dry_run":false,"rights":[{"right":"write","given":true}],"database":[],"targets":{"path":"src/main.rs","new_name":"copy.rs","dry_run":false},"lengths":{"target_dir":3},"result":"ok"}

caller 是 mcp: 加上客户端给出的名称,result 是 ok、refused 或 error。日志只记录名称和长度,从不记录文件内容、命令或值。 这些检查如何配合:智能体的调用如何被检查(英文)。

Experimental 通过标准输入输出时,智能体处理的是磁盘上的文件。要让它看到窗口中打开的内容(包括你尚未保存的文本), 请通过 HTTP 把它连接到窗口:

  1. 在 Ferris IDEA 中打开 Settings › Tools › AI Assistant,打开 Serve MCP to local agents over HTTP。它会立即启动。

  2. 窗口只监听 127.0.0.1,端口由系统选择,每次启动都会生成新的 token。两者都写入设置目录中的 mcp-http/<pid>.json:url、token、 现成的 header 行,以及每个打开项目各自的 url。

  3. 把 URL 和请求头交给客户端。以 Claude Code 为例:

    终端窗口
    claude mcp add --transport http ferris-idea "http://127.0.0.1:<port>/mcp?tools=all" \
    --header "Authorization: Bearer <token>"

    ?tools= 部分选择工具组;通过 HTTP 时,Claude Code 在 find_tools 之后不会重新加载工具列表。

通过 HTTP 时,缺少权限不会立即被拒绝:窗口会询问你 Allow “<client>” the right “write” in workspace “demo-shop”?, 选项为 Deny(默认)、Allow Once 和 Always for This Workspace;最后一项会替你把配置项写入授权文件。2 分钟内无人回答视为拒绝。

不要把 token 贴到 issue 或聊天中。端口和 token 每次启动都会变化,重启 Ferris IDEA 后请更新客户端的配置项。

在 Ferris IDEA 终端中使用 Claude Code

Section titled “在 Ferris IDEA 终端中使用 Claude Code”

在 Ferris IDEA 的终端标签页中启动 claude(View › Tool Windows › Terminal,macOS 上是 ⌥F12, Linux 上是 AltF12)。它会自动连接到窗口,状态栏显示 Claude Code connected。之后:

  • Claude Code 提出的修改会以 diff 形式打开,标题为 Claude Code proposes a change to …,带有 Accept 和 Reject;只有在 Accept 之后 Claude Code 才会写入文件。
  • 编辑器右键菜单中的 Send to Claude Code(以及 Tools › AI Assistant 中的同名项)会发送选中的行。

在 Ferris IDEA 之外启动时,Claude Code 会在 /ide 下列出这个窗口。这个连接与 MCP 是分开的:要使用工具,请按上文添加 MCP 服务器。 它在 Windows 上不会启动。

  • 客户端显示服务器启动失败。 在终端中运行配置项里的命令。它应该静默等待;如果在没有客户端的情况下启动,它会以 error: connection closed: initialize request 结束,这说明程序和目录都是正确的。常见原因是相对路径,或者客户端在它的 PATH 中找不到程序。
  • … is a file, not a project folder。 配置项指向的是文件。请给出项目目录。
  • unknown tool group "…"。 信息中列出了已知的工具组。
  • not granted: …。 按上文添加信息中给出的配置项。
  • withheld: '.env' is on the list of files whose names commonly hold secrets。 读取这类文件需要 secret-read 权限。
  • Safe mode: … is not trusted。 请信任项目;仅有权限不足以运行它的代码。
  • no window: this MCP server runs without the Ferris IDEA window。 这个工具作用于窗口(编辑器标签页、关闭项目),需要通过 HTTP 连接。
  • HTTP 返回 401。 token 已过期:Ferris IDEA 重启过。请从 mcp-http/<pid>.json 读取新的 token。连接被拒绝则说明设置未打开、窗口已关闭, 或端口已变化。

核心工具集、读取和修改你的授权的工具,以及窗口连接(工具说明为英文):

  • agent_permissionsreadsWhat agents may do in this workspace beyond reading: the rights granted by the user in their own settings folder (never in the workspace), e.g.
  • claude_code_linkreadsState of the Claude Code link of this project: when Anthropic's claude CLI runs in a Ferris IDEA terminal it connects to the window as its IDE (selection, open files, diagnostics, diffs the user accepts or rejects).
  • claude_code_mentionreadsSend lines of a project file to Claude Code connected to this window (at_mentioned, SPEC-0358 v2 behaviour 24): path, line_start, optional line_end (1-based).
  • file_diagnosticsreadsErrors and warnings of workspace files from their language server (clangd, rust-analyzer, pyright, typescript-language-server, gopls), followed by Ferris IDEA's own findings (source Ferris IDEA).
  • find_symbol_locationsreadsDefinition, all references (including the declaration), the declaration of its type (type_definition) or its implementations and overrides (implementation) for the symbol at a position of a workspace file, from its language server.
  • find_toolsreadsFinds IDE tools beyond the small core set this session starts with; every tool belongs to a group.
  • list_filesreadsList project files (relative paths, sorted).
  • project_trustreadsWhether the workspace (or path) is trusted to run its code, and through what (a remembered project or folder, FERRIS_IDEA_TRUST_PROJECTS, --trust); whether safe mode is enforced in this process; what in the project would run code (build files, run configurations); what safe mode blocks; the remembered trusted locations and the trust file.
  • read_filereadsRead a text file of the workspace, optionally a 1-based inclusive line range.
  • replace_text_in_filechangesdry run by defaultwriteReplace text in a workspace text file as the window shows it, saved or not.
  • search_in_filesreadsFind text or a regular expression in the project's own source files (match case, whole words, file mask such as *.rs, *.toml).
  • workspace_inforeadsName, root directory and file counts per language of the open workspace.

所有工具,可搜索:MCP 工具(英文)。