( input: string, toolUseContext: ToolUseContext, )
| 1993 | } |
| 1994 | |
| 1995 | async function processMcpResourceAttachments( |
| 1996 | input: string, |
| 1997 | toolUseContext: ToolUseContext, |
| 1998 | ): Promise<Attachment[]> { |
| 1999 | const resourceMentions = extractMcpResourceMentions(input) |
| 2000 | if (resourceMentions.length === 0) return [] |
| 2001 | |
| 2002 | const mcpClients = toolUseContext.options.mcpClients || [] |
| 2003 | |
| 2004 | const results = await Promise.all( |
| 2005 | resourceMentions.map(async mention => { |
| 2006 | try { |
| 2007 | const [serverName, ...uriParts] = mention.split(':') |
| 2008 | const uri = uriParts.join(':') // Rejoin in case URI contains colons |
| 2009 | |
| 2010 | if (!serverName || !uri) { |
| 2011 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2012 | return null |
| 2013 | } |
| 2014 | |
| 2015 | // Find the MCP client |
| 2016 | const client = mcpClients.find(c => c.name === serverName) |
| 2017 | if (!client || client.type !== 'connected') { |
| 2018 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2019 | return null |
| 2020 | } |
| 2021 | |
| 2022 | // Find the resource in available resources to get its metadata |
| 2023 | const serverResources = |
| 2024 | toolUseContext.options.mcpResources?.[serverName] || [] |
| 2025 | const resourceInfo = serverResources.find(r => r.uri === uri) |
| 2026 | if (!resourceInfo) { |
| 2027 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2028 | return null |
| 2029 | } |
| 2030 | |
| 2031 | try { |
| 2032 | const result = await client.client.readResource({ |
| 2033 | uri, |
| 2034 | }) |
| 2035 | |
| 2036 | logEvent('tengu_at_mention_mcp_resource_success', {}) |
| 2037 | |
| 2038 | return { |
| 2039 | type: 'mcp_resource' as const, |
| 2040 | server: serverName, |
| 2041 | uri, |
| 2042 | name: resourceInfo.name || uri, |
| 2043 | description: resourceInfo.description, |
| 2044 | content: result, |
| 2045 | } |
| 2046 | } catch (error) { |
| 2047 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2048 | logError(error) |
| 2049 | return null |
| 2050 | } |
| 2051 | } catch { |
| 2052 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
no test coverage detected