Skip to content

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

fix(shared): keep a generated MCP name from ending in a hyphen

lhy-dcf37f52545c250
diff --git a/shared/mcp-name.test.ts b/shared/mcp-name.test.ts
new file mode 100644
index 0000000000..f694392534
--- /dev/null
+++ b/shared/mcp-name.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from "vitest";
+
+import { slugMcpName } from "./mcp-name.ts";
+
+describe("slugMcpName", () => {
+ it("keeps the existing contract for ordinary names", () => {
+ expect(slugMcpName("My Files")).toBe("my-files");
+ expect(slugMcpName("123 repo")).toBe("mcp-123-repo");
+ expect(slugMcpName(" ")).toBe("");
+ expect(slugMcpName("a".repeat(40))).toHaveLength(32);
+ });
+
+ it("never ends in a hyphen after the length cap", () => {
+ const got = slugMcpName("a".repeat(31) + "-bx");
+ expect(got.endsWith("-")).toBe(false);
+ expect(got.length).toBeLessThanOrEqual(32);
+ });
+
+ it("keeps the mcp- prefix branch free of a trailing hyphen too", () => {
+ const got = slugMcpName("9" + "a".repeat(30) + "-bx");
+ expect(got.endsWith("-")).toBe(false);
+ expect(got.length).toBeLessThanOrEqual(32);
+ });
+});
diff --git a/shared/mcp-name.ts b/shared/mcp-name.ts
index b591cd6815..d97eb82a26 100644
--- a/shared/mcp-name.ts
+++ b/shared/mcp-name.ts
@@ -16,8 +16,8 @@ export const RESERVED_MCP_NAMES: ReadonlySet<string> = new Set([
/** A server name from any text: lowercase letters, numbers, `_` and `-`, starting with a letter, at most 32. */
export function slugMcpName(raw: string): string {
- const slug = raw.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32);
- return /^[a-z]/.test(slug) ? slug : slug ? `mcp-${slug}`.slice(0, 32) : "";
+ const slug = raw.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32).replace(/-+$/, "");
+ return /^[a-z]/.test(slug) ? slug : slug ? `mcp-${slug}`.slice(0, 32).replace(/-+$/, "") : "";
}
/** What OpenMausBot names a server another tool calls `raw`; a name OpenMausBot keeps for itself gets an mcp- prefix. */