Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.0

- Add `list-tools` non-interactive command to list tools from a configured MCP server

# 2.0.0

- **Breaking**: require Node.js 20 or newer
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ npx @wong2/mcp-cli --sse http://localhost:8000/sse

### Non-interactive mode

Run a specific tool, resource, or prompt without interactive prompts:
Run a specific tool, resource, or prompt without interactive prompts, or list tools from a configured server:

```bash
npx @wong2/mcp-cli [--config config.json] <command> <server-name>:<target> [--args '{}']
Expand All @@ -71,6 +71,9 @@ Examples:
# Call a tool without arguments
npx @wong2/mcp-cli -c config.json call-tool filesystem:list_files

# List tools exposed by a configured server
npx @wong2/mcp-cli -c config.json list-tools filesystem

# Call a tool with arguments
npx @wong2/mcp-cli -c config.json call-tool filesystem:read_file --args '{"path": "package.json"}'

Expand Down
4 changes: 4 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const cli = meow(
$ mcp-cli --url http://localhost:8000/mcp
$ mcp-cli --sse http://localhost:8000/sse
$ mcp-cli purge
$ mcp-cli [--config config.json] list-tools <server_name>
$ mcp-cli [--config config.json] call-tool <server_name>:<tool_name> [--args '{"key":"value"}']
$ mcp-cli [--config config.json] read-resource <server_name>:<resource_uri>
$ mcp-cli [--config config.json] get-prompt <server_name>:<prompt_name> [--args '{"key":"value"}']
Expand Down Expand Up @@ -53,6 +54,9 @@ const options = { compact: cli.flags.compact }

if (cli.input[0] === 'purge') {
purge()
} else if (cli.input.length >= 2 && cli.input[0] === 'list-tools') {
const [, serverName] = cli.input
await runWithConfigNonInteractive(cli.flags.config, serverName, 'list-tools')
} else if (
cli.input.length >= 2 &&
(cli.input[0] === 'call-tool' || cli.input[0] === 'read-resource' || cli.input[0] === 'get-prompt')
Expand Down
4 changes: 3 additions & 1 deletion src/mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ export async function runWithConfigNonInteractive(configPath, serverName, comman
}
}

if (command === 'call-tool') {
if (command === 'list-tools') {
result = await client.listTools()
} else if (command === 'call-tool') {
result = await client.callTool({ name: target, arguments: args })
} else if (command === 'read-resource') {
result = await client.readResource({ uri: target })
Expand Down