Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
номера версий по [семантике](https://semver.org/lang/ru/), то есть до `1.0.0` интерфейс команд
ещё может меняться.

## Не выпущено

### Исправлено

- **Инструменты `max bot mcp` учитывают окружение сервера.** Раньше вызов шёл мимо переменных, с которыми
запущен сервер: например, при `MAX_READ_ONLY=1` бот всё равно отправлял сообщение. Теперь вызов через MCP
ведёт себя так же, как та же команда в терминале.

## 0.58.0 — 17.10.2026

### Безопасность
Expand Down
13 changes: 11 additions & 2 deletions src/bot-mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ const owner = async (profile: string, argv: string[]) => {
type Options = Partial<Record<"confirmSend" | "allowDangerous" | "yes", boolean>> & {
permissions?: Record<string, "deny" | "readonly" | "ask" | "allow">
readOtherBots?: boolean | string[]
env?: NodeJS.ProcessEnv
}

const connect = async (
{ permissions = {}, readOtherBots = false, ...options }: Options = {},
{ permissions = {}, readOtherBots = false, env = process.env, ...options }: Options = {},
{ form }: { form?: (message: string) => ElicitResult } = {},
) => {
const profile = `bm-${++profiles}`
Expand All @@ -97,7 +98,7 @@ const connect = async (
bot: { ...maxBot, mcp },
commandAt: commandLookup(group),
settings: { profile, permissions, readOtherBots },
env: process.env,
env,
run: botMcpRun(run, testEnvironment()),
tools: mcp.tools ?? [],
...(mcp.skill ? { skill: mcp.skill } : {}),
Expand Down Expand Up @@ -230,6 +231,14 @@ describe("max bot mcp", () => {
expect(deletes().at(-1)?.url).toBe("/chats/-100/members?user_id=42&block=true")
})

it("**runs each call under the server's environment**: MAX_READ_ONLY refuses a send there too", async () => {
const { client } = await connect({ env: { ...process.env, MAX_READ_ONLY: "1" } })
const { isError, error } = await call(client, "messages send", { chat: "-100", text: "hi" })
expect(isError).toBe(true)
expect(error.message).toContain("MAX_READ_ONLY")
expect(posts()).toHaveLength(0)
})

it("meets the bot's recipient list, and the refusal is the command's", async () => {
const { client, profile } = await connect()
await owner(profile, ["recipients", "add", "-200"])
Expand Down
4 changes: 2 additions & 2 deletions src/commands/bot-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { environmentOf } from "./context.js"
*/
export const botMcpRun =
(program: typeof run, extra: Parameters<typeof run>[1] = {}): RunBotCommand =>
(argv, { streams, tty, answer }) =>
program(argv, { ...extra, streams, tty, ...(answer ? { answer } : {}) })
(argv, environment) =>
program(argv, { ...extra, ...environment })

/** `bot mcp`. The program hands in its own `run`: importing it here would close a loop through the program. */
export const maxBotMcp = (program: typeof run): BotMcp => ({
Expand Down
Loading