( clients: MCPServerConnection[], query: string, )
| 27 | } |
| 28 | |
| 29 | async function fetchChannels( |
| 30 | clients: MCPServerConnection[], |
| 31 | query: string, |
| 32 | ): Promise<string[]> { |
| 33 | const slackClient = findSlackClient(clients) |
| 34 | if (!slackClient || slackClient.type !== 'connected') { |
| 35 | return [] |
| 36 | } |
| 37 | |
| 38 | try { |
| 39 | const result = await slackClient.client.callTool( |
| 40 | { |
| 41 | name: SLACK_SEARCH_TOOL, |
| 42 | arguments: { |
| 43 | query, |
| 44 | limit: 20, |
| 45 | channel_types: 'public_channel,private_channel', |
| 46 | }, |
| 47 | }, |
| 48 | undefined, |
| 49 | { timeout: 5000 }, |
| 50 | ) |
| 51 | |
| 52 | const content = result.content |
| 53 | if (!Array.isArray(content)) return [] |
| 54 | |
| 55 | const rawText = content |
| 56 | .filter((c): c is { type: 'text'; text: string } => c.type === 'text') |
| 57 | .map(c => c.text) |
| 58 | .join('\n') |
| 59 | |
| 60 | return parseChannels(unwrapResults(rawText)) |
| 61 | } catch (error) { |
| 62 | logForDebugging(`Failed to fetch Slack channels: ${error}`) |
| 63 | return [] |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // The Slack MCP server wraps its markdown in a JSON envelope: |
| 68 | // {"results":"# Search Results...\nName: #chan\n..."} |
no test coverage detected