(input, { options: { mcpClients } })
| 73 | return outputSchema() |
| 74 | }, |
| 75 | async call(input, { options: { mcpClients } }) { |
| 76 | const { server: serverName, uri } = input |
| 77 | |
| 78 | const client = mcpClients.find(client => client.name === serverName) |
| 79 | |
| 80 | if (!client) { |
| 81 | throw new Error( |
| 82 | `Server "${serverName}" not found. Available servers: ${mcpClients.map(c => c.name).join(', ')}`, |
| 83 | ) |
| 84 | } |
| 85 | |
| 86 | if (client.type !== 'connected') { |
| 87 | throw new Error(`Server "${serverName}" is not connected`) |
| 88 | } |
| 89 | |
| 90 | if (!client.capabilities?.resources) { |
| 91 | throw new Error(`Server "${serverName}" does not support resources`) |
| 92 | } |
| 93 | |
| 94 | const connectedClient = await ensureConnectedClient(client) |
| 95 | const result = (await connectedClient.client.request( |
| 96 | { |
| 97 | method: 'resources/read', |
| 98 | params: { uri }, |
| 99 | }, |
| 100 | ReadResourceResultSchema, |
| 101 | )) as ReadResourceResult |
| 102 | |
| 103 | // Intercept any blob fields: decode, write raw bytes to disk with a |
| 104 | // mime-derived extension, and replace with a path. Otherwise the base64 |
| 105 | // would be stringified straight into the context. |
| 106 | const contents = await Promise.all( |
| 107 | result.contents.map(async (c, i) => { |
| 108 | if ('text' in c) { |
| 109 | return { uri: c.uri, mimeType: c.mimeType, text: c.text } |
| 110 | } |
| 111 | if (!('blob' in c) || typeof c.blob !== 'string') { |
| 112 | return { uri: c.uri, mimeType: c.mimeType } |
| 113 | } |
| 114 | const persistId = `mcp-resource-${Date.now()}-${i}-${Math.random().toString(36).slice(2, 8)}` |
| 115 | const persisted = await persistBinaryContent( |
| 116 | Buffer.from(c.blob, 'base64'), |
| 117 | c.mimeType, |
| 118 | persistId, |
| 119 | ) |
| 120 | if ('error' in persisted) { |
| 121 | return { |
| 122 | uri: c.uri, |
| 123 | mimeType: c.mimeType, |
| 124 | text: `Binary content could not be saved to disk: ${persisted.error}`, |
| 125 | } |
| 126 | } |
| 127 | return { |
| 128 | uri: c.uri, |
| 129 | mimeType: c.mimeType, |
| 130 | blobSavedTo: persisted.filepath, |
| 131 | text: getBinaryBlobSavedMessage( |
| 132 | persisted.filepath, |
nothing calls this directly
no test coverage detected