( input: string, toolUseContext: ToolUseContext, )
| 2045 | } |
| 2046 | |
| 2047 | async function processMcpResourceAttachments( |
| 2048 | input: string, |
| 2049 | toolUseContext: ToolUseContext, |
| 2050 | ): Promise<Attachment[]> { |
| 2051 | const resourceMentions = extractMcpResourceMentions(input) |
| 2052 | if (resourceMentions.length === 0) return [] |
| 2053 | |
| 2054 | const mcpClients = toolUseContext.options.mcpClients || [] |
| 2055 | |
| 2056 | const results = await Promise.all( |
| 2057 | resourceMentions.map(async mention => { |
| 2058 | try { |
| 2059 | const [serverName, ...uriParts] = mention.split(':') |
| 2060 | const uri = uriParts.join(':') // Rejoin in case URI contains colons |
| 2061 | |
| 2062 | if (!serverName || !uri) { |
| 2063 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2064 | return null |
| 2065 | } |
| 2066 | |
| 2067 | // Find the MCP client |
| 2068 | const client = mcpClients.find(c => c.name === serverName) |
| 2069 | if (!client || client.type !== 'connected') { |
| 2070 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2071 | return null |
| 2072 | } |
| 2073 | |
| 2074 | // Find the resource in available resources to get its metadata |
| 2075 | const serverResources = |
| 2076 | toolUseContext.options.mcpResources?.[serverName] || [] |
| 2077 | const resourceInfo = serverResources.find(r => r.uri === uri) |
| 2078 | if (!resourceInfo) { |
| 2079 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2080 | return null |
| 2081 | } |
| 2082 | |
| 2083 | try { |
| 2084 | const result = await client.client.readResource({ |
| 2085 | uri, |
| 2086 | }) |
| 2087 | |
| 2088 | logEvent('tengu_at_mention_mcp_resource_success', {}) |
| 2089 | |
| 2090 | return { |
| 2091 | type: 'mcp_resource' as const, |
| 2092 | server: serverName, |
| 2093 | uri, |
| 2094 | name: resourceInfo.name || uri, |
| 2095 | description: resourceInfo.description, |
| 2096 | content: result, |
| 2097 | } |
| 2098 | } catch (error) { |
| 2099 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
| 2100 | logError(error) |
| 2101 | return null |
| 2102 | } |
| 2103 | } catch { |
| 2104 | logEvent('tengu_at_mention_mcp_resource_error', {}) |
no test coverage detected