MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseSlashCommand

Function parseSlashCommand

source code/utils/slashCommandParsing.ts:27–62  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

25 * // => { commandName: 'mcp:tool (MCP)', args: 'arg1 arg2', isMcp: true }
26 */
27export function parseSlashCommand(input: string): ParsedSlashCommand | null {
28 const trimmedInput = input.trim()
29
30 // Check if input starts with '/'
31 if (!trimmedInput.startsWith('/')) {
32 return null
33 }
34
35 // Remove the leading '/' and split by spaces
36 const withoutSlash = trimmedInput.slice(1)
37 const words = withoutSlash.split(' ')
38
39 if (!words[0]) {
40 return null
41 }
42
43 let commandName = words[0]
44 let isMcp = false
45 let argsStartIndex = 1
46
47 // Check for MCP commands (second word is '(MCP)')
48 if (words.length > 1 && words[1] === '(MCP)') {
49 commandName = commandName + ' (MCP)'
50 isMcp = true
51 argsStartIndex = 2
52 }
53
54 // Extract arguments (everything after command name)
55 const args = words.slice(argsStartIndex).join(' ')
56
57 return {
58 commandName,
59 args,
60 isMcp,
61 }
62}

Callers 2

processSlashCommandFunction · 0.85
processUserInputBaseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected