mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-01 17:54:11 +00:00
mcp: reject inherited names as commands
This commit is contained in:
1 parent
37a4ef492f
commit
4cf98ddec3
2 files changed
+10
-10
No files matched your search
@@ -22,17 +22,17 @@ Environment:
|
||||
|
||||
export type Command = "session" | "daemon" | "hook session-start" | "link" | "reset-owners" | "help"
|
||||
|
||||
const commands: {[args: string]: Command} = {
|
||||
"session": "session",
|
||||
"daemon": "daemon",
|
||||
"hook session-start": "hook session-start",
|
||||
"link": "link",
|
||||
"reset-owners": "reset-owners",
|
||||
"--help": "help",
|
||||
}
|
||||
const commands = new Map<string, Command>([
|
||||
["session", "session"],
|
||||
["daemon", "daemon"],
|
||||
["hook session-start", "hook session-start"],
|
||||
["link", "link"],
|
||||
["reset-owners", "reset-owners"],
|
||||
["--help", "help"],
|
||||
])
|
||||
|
||||
export function parseCommand(args: string[]): Command {
|
||||
const command = commands[args.join(" ")]
|
||||
const command = commands.get(args.join(" "))
|
||||
if (command === undefined) throw new ExitError("Unknown command. Run simplex-mcp --help.", 2)
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("commands", () => {
|
||||
|
||||
it("refuses other commands and extra arguments", () => {
|
||||
const unknown = new ExitError("Unknown command. Run simplex-mcp --help.", 2)
|
||||
for (const args of [[], ["serve", "agent"], ["register", "agent"], ["hook"], ["link", "x"], ["session", "--port", "1"]]) expect(() => parseCommand(args)).toThrow(unknown)
|
||||
for (const args of [[], ["serve", "agent"], ["register", "agent"], ["hook"], ["link", "x"], ["session", "--port", "1"], ["constructor"], ["__proto__"], ["toString"]]) expect(() => parseCommand(args)).toThrow(unknown)
|
||||
})
|
||||
|
||||
it("documents the commands, the install and the data folder", () => {
|
||||
|
||||
Reference in new issue
Block a user