Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/commands/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { computeChildProcess } from '../utils/spawn.js'
// Define the expected shape for parsed arguments.

export default class Tool extends Command {
// Use array syntax for positional args.
// Oclif will use the 'name' field to build an object in the parsed output.
// Arguments must be declared in the order they are expected on the
// command line. Required arguments cannot come after optional ones,
// otherwise oclif will throw an "Invalid argument spec" error.
/* eslint-disable perfectionist/sort-objects */
static args = {
properties: Args.string({ description: 'Tool properties as key=value pairs', multiple: true }),
server: Args.string({ description: 'the MCP server', required: true }),
tool: Args.string({ description: 'the tool to call', required: true })
tool: Args.string({ description: 'the tool to call', required: true }),
properties: Args.string({ description: 'Tool properties as key=value pairs', multiple: true }),
}
/* eslint-enable perfectionist/sort-objects */
static description = 'Call a tool on a server'
static flags = {
json: Flags.boolean({ char: 'j', description: 'Output result in JSON format' })
Expand Down Expand Up @@ -82,5 +85,7 @@ static strict = false
console.log('Tool call result:', result)
}

await client.close()

}
}
2 changes: 2 additions & 0 deletions src/commands/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ static strict = false
for (const tool of toolsArray) {
printTool(tool)
}

await client.close()
}
}
32 changes: 32 additions & 0 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {expect} from 'chai'
import {spawnSync} from 'node:child_process'

function runCli(args: string[]) {
return spawnSync(process.execPath, ['--loader','ts-node/esm','--disable-warning=ExperimentalWarning', './bin/dev.js', ...args], {encoding: 'utf8', timeout: 15_000})
}

describe('integration', () => {
it('lists tools for python server', () => {
const res = runCli(['tools', './mcp-server.py'])
expect(res.status).to.equal(0)
expect(res.stdout).to.contain('echo')
})

it('calls tool on python server', () => {
const res = runCli(['tool', './mcp-server.py', 'echo', 'message=hi'])
expect(res.status).to.equal(0)
expect(res.stdout).to.contain('hi')
})

it('lists tools for node server', () => {
const res = runCli(['tools', './mcp-server-node.mjs'])
expect(res.status).to.equal(0)
expect(res.stdout).to.contain('echo')
})

it('calls tool on node server', () => {
const res = runCli(['tool', './mcp-server-node.mjs', 'echo', 'message=hi'])
expect(res.status).to.equal(0)
expect(res.stdout).to.contain('hi')
})
})