MCPcopy
hub / github.com/codeaashu/claude-code / call

Function call

src/tools/ReadMcpResourceTool/ReadMcpResourceTool.ts:75–144  ·  view source on GitHub ↗
(input, { options: { mcpClients } })

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 5

ensureConnectedClientFunction · 0.85
persistBinaryContentFunction · 0.85
toStringMethod · 0.65
requestMethod · 0.45

Tested by

no test coverage detected