openpencil/.mcp-probe.mjs

42 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2026-09-16 10:09:12 +00:00
// Temporary probe: exercise the OpenPencil MCP server against the headless canvas
// started by w4c-chatapi/scripts/openpencil-headless-canvas.mjs. Deleted after use.
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
const url = new URL('http://127.0.0.1:7600/mcp')
const client = new Client({ name: 'w4c-probe', version: '0.0.0' })
await client.connect(new StreamableHTTPClientTransport(url))
const { tools } = await client.listTools()
console.log(`tools=${tools.length}`)
const interesting = tools
.map((t) => t.name)
.filter((n) => /shape|rect|screenshot|selection|current_page|page|node|export/i.test(n))
console.log('matching:', interesting.join(', '))
const mode = process.argv[2] || 'list'
if (mode === 'draw') {
const rect = tools.find((t) => /create.*(rectangle|shape|rect)/i.test(t.name))
console.log('drawTool:', rect?.name)
console.log('schema:', JSON.stringify(rect?.inputSchema).slice(0, 1200))
} else if (mode === 'call') {
const name = process.argv[3]
const args = JSON.parse(process.argv[4] || '{}')
const res = await client.callTool({ name, arguments: args })
console.log(
`RESULT ${name}:`,
JSON.stringify(res.content).slice(0, 1500),
res.isError ? '(isError)' : ''
)
} else {
// read-back: current page + selection
for (const name of ['get_current_page', 'get_selection']) {
if (!tools.some((t) => t.name === name)) continue
const res = await client.callTool({ name, arguments: {} })
console.log(`${name}:`, JSON.stringify(res.content).slice(0, 700), res.isError ? '(isError)' : '')
}
}
await client.close()