Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge #7716 into train E2

milind-soni2629f8d23785
diff --cc server/mcp-gate.ts
index c69020cf92,6f167e6a84..3217ad3a1a
--- a/server/mcp-gate.ts
+++ b/server/mcp-gate.ts
@@@ -16,7 -16,7 +16,8 @@@ import { killCliTree } from "./procs.ts
import { readStdioLines } from "./stdio-lines.ts";
import { toolSchemaProfileFromEnv } from "./tool-schema-profile.ts";
import { capToolListResult, toolLimitFromEnv } from "./tool-count-limit.ts";
+import { TOOL_LIST_RECORD_ENV, TOOL_LIST_SHARE_ENV, toolsListResultForSessionShare } from "./tool-list-share.ts";
+ import { textOnlyToolsFromEnv, withoutResultImages } from "./mcp-text-only.ts";
type Json = Record<string, unknown>;
@@@ -414,10 -413,10 +417,13 @@@ readStdioLines(child.stdout, (line) =>
if (TOOL_LIMIT !== undefined && request?.kind === "list" && message.error === undefined && isRecord(result)) {
message.result = capToolListResult(result, TOOL_LIMIT, (note) => process.stderr.write(`mcp-gate(${NAME}): ${note}\n`));
}
+ if (request?.kind === "list" && message.error === undefined) {
+ message.result = toolsListResultForSessionShare(message.result, process.env, (note) => process.stderr.write(`mcp-gate(${NAME}): ${note}\n`));
+ }
if (request?.kind === "call" && observer && message.error === undefined) observer.returned(request.params, result);
+ if (TEXT_ONLY_TOOLS && request?.kind === "call" && message.error === undefined && isRecord(result) && withoutResultImages(result)) {
+ process.stderr.write(`mcp-gate(${NAME}): replaced an image in ${request.tool}'s result with a note: this model reads text only\n`);
+ }
if (request?.kind === "call" && request.trim && isRecord(result)) {
try {
if (trimCallResult(result, request.tool)) {
diff --cc server/mcp-remote-proxy.ts
index 4e7bd5743c,ce11ff4e26..f5e7804fb2
--- a/server/mcp-remote-proxy.ts
+++ b/server/mcp-remote-proxy.ts
@@@ -29,9 -29,9 +29,10 @@@ import { APP_ONLY_REFUSAL, AppObserver
import { lenientToolValidator, schemaProblems } from "./mcp-schema-validator.ts";
import { fitToolListResult } from "./mcp-tool-schema.ts";
import { toolSchemaProfileFromEnv } from "./tool-schema-profile.ts";
+import { toolsListResultForSessionShare } from "./tool-list-share.ts";
import { capToolListResult, toolLimitFromEnv } from "./tool-count-limit.ts";
import { readStdioLines } from "./stdio-lines.ts";
+ import { textOnlyToolsFromEnv, withoutResultImages } from "./mcp-text-only.ts";
import { APP_EXTENSION_KEY } from "../shared/app.ts";
type Json = Record<string, unknown>;
@@@ -342,7 -343,10 +344,10 @@@ async function handle(message: Json): P
try {
const result = directory ? await directed(message, signal) : await upstream(message.method, message.params, signal);
if (message.method === "initialize") initialized = true;
+ if (message.method === "tools/call" && TEXT_ONLY_TOOLS && withoutResultImages(result)) {
+ logFit("replaced an image in the tool's result with a note: this model reads text only");
+ }
- send({ jsonrpc: "2.0", id: message.id, result: message.method === "tools/list" ? capToolListResult(fitToolListResult(result, SCHEMA_PROFILE, logFit), TOOL_LIMIT, logFit) : result });
+ send({ jsonrpc: "2.0", id: message.id, result: message.method === "tools/list" ? toolsListResultForSessionShare(capToolListResult(fitToolListResult(result, SCHEMA_PROFILE, logFit), TOOL_LIMIT, logFit), process.env, logFit) : result });
} catch (failure) {
// Transport failures may carry URLs or header values: never relayed.
let code = -32603;