MCPcopy Create free account
hub / github.com/deepnote/deepnote / testTool

Function testTool

packages/mcp/src/test-tool.ts:36–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36async function testTool(): Promise<void> {
37 const args = process.argv.slice(2)
38
39 if (args.length < 2) {
40 console.log(`
41Deepnote MCP Tool Tester
42
43Usage: pnpm test:tool <tool-name> '<json-arguments>'
44
45Examples:
46 pnpm test:tool deepnote_read '{"path": "example.deepnote"}'
47 pnpm test:tool deepnote_create '{"outputPath": "/tmp/test.deepnote", "projectName": "Demo", "notebooks": [{"name":"Notebook","blocks":[{"type":"code","content":"print(1)"}]}]}'
48 pnpm test:tool deepnote_convert_to '{"inputPath": "notebook.ipynb"}'
49 pnpm test:tool deepnote_run '{"path": "notebook.deepnote", "dryRun": true}'
50 pnpm test:tool deepnote_snapshot_list '{"path": "notebook.deepnote"}'
51
52Available tools:
53${formatAvailableTools()}
54`)
55 process.exit(1)
56 }
57
58 const toolName = args[0]
59 const toolArgsString = args[1]
60
61 if (!toolArgsString) {
62 console.error('Error: Missing JSON arguments')
63 process.exit(1)
64 }
65
66 let toolArgs: Record<string, unknown>
67
68 try {
69 toolArgs = JSON.parse(toolArgsString)
70 } catch (error) {
71 console.error('Error: Invalid JSON arguments')
72 console.error(error instanceof Error ? error.message : String(error))
73 process.exit(1)
74 }
75
76 // Create MCP request for calling a tool
77 const request = {
78 jsonrpc: '2.0',
79 id: 1,
80 method: 'tools/call',
81 params: {
82 name: toolName,
83 arguments: toolArgs,
84 },
85 }
86
87 return new Promise((resolve, reject) => {
88 // Resolve bin.js relative to this script's location (process.argv[1])
89 const scriptDir = path.dirname(process.argv[1] || '')
90 const serverPath = path.join(scriptDir, 'bin.js')
91 const child = spawn('node', [serverPath], {
92 stdio: ['pipe', 'pipe', 'pipe'],
93 })

Callers 1

test-tool.tsFile · 0.85

Calls 1

formatAvailableToolsFunction · 0.85

Tested by

no test coverage detected