MCPcopy Index your code
hub / github.com/deepnote/deepnote / handleConvertFrom

Function handleConvertFrom

packages/mcp/src/tools/conversion.ts:255–306  ·  view source on GitHub ↗
(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

253}
254
255async function handleConvertFrom(args: Record<string, unknown>) {
256 const parsedArgs = convertFromArgsSchema.safeParse(args)
257 if (!parsedArgs.success) {
258 return toError(`Invalid arguments for deepnote_convert_from: ${formatFirstIssue(parsedArgs.error)}`)
259 }
260 const { inputPath, outputDir } = parsedArgs.data
261 const format = parsedArgs.data.format ?? 'jupyter'
262
263 const absoluteInput = path.resolve(inputPath)
264
265 let inputStat: Awaited<ReturnType<typeof fs.stat>>
266 try {
267 inputStat = await fs.stat(absoluteInput)
268 } catch (error) {
269 const message = error instanceof Error ? error.message : String(error)
270 return toError(`Invalid inputPath: ${message}`)
271 }
272
273 if (!inputStat.isFile()) {
274 return toError('inputPath for deepnote_convert_from must point to a file')
275 }
276
277 const finalOutputDir = outputDir ? path.resolve(outputDir) : path.dirname(absoluteInput)
278
279 try {
280 await runFromDeepnoteConversion(format, absoluteInput, { outputDir: finalOutputDir })
281
282 return {
283 content: [
284 {
285 type: 'text',
286 text: JSON.stringify(
287 {
288 success: true,
289 inputPath: absoluteInput,
290 outputFormat: format,
291 outputDir: finalOutputDir,
292 },
293 null,
294 2
295 ),
296 },
297 ],
298 }
299 } catch (error) {
300 const message = error instanceof Error ? error.message : String(error)
301 return {
302 content: [{ type: 'text', text: `Conversion failed: ${message}` }],
303 isError: true,
304 }
305 }
306}
307
308export async function handleConversionTool(name: string, args: Record<string, unknown> | undefined) {
309 const safeArgs = args || {}

Callers 1

handleConversionToolFunction · 0.85

Calls 3

toErrorFunction · 0.85
formatFirstIssueFunction · 0.70

Tested by

no test coverage detected