MCPcopy Index your code
hub / github.com/Noumena-Network/code / parseSlashCommand

Function parseSlashCommand

src/utils/slashCommandParsing.ts:25–60  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

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

Callers 3

processSlashCommandFunction · 0.85
processUserInputBaseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected