@weibaohui/mcp2cli 0.2.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,234 +1,234 @@
1
1
  # mcp2cli
2
2
 
3
- > A powerful CLI tool for interacting with MCP (Model Context Protocol) servers
3
+ > A CLI-native MCP client that loads tool schemas on-demand and resolves discover-then-call into a single invocation — keeping tool definitions out of your context window.
4
+
5
+ **One bash command → tool discovery + schema resolution + precise invocation. No persistent tool definitions, no token waste.**
4
6
 
5
7
  [![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat-square&logo=go)](https://golang.org)
6
8
  [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE)
9
+ [![npm](https://img.shields.io/npm/v/@weibaohui/mcp2cli?style=flat-square)](https://www.npmjs.com/package/@weibaohui/mcp2cli)
7
10
 
8
- ## Quick Usage
11
+ ## Why mcp2cli?
9
12
 
10
- ```bash
11
- # Install
12
- go install github.com/weibaohui/mcp2cli@latest
13
+ When an LLM uses MCP tools directly, every call carries heavy overhead:
14
+ - Tool discovery: list tools → read schemas → understand parameters → construct call → parse response
15
+ - Each MCP tool definition (schema, descriptions, types) stays in context, consuming tokens for the **entire conversation**
16
+ - A single "search GitHub and summarize" task can burn thousands of tokens just on protocol overhead
13
17
 
14
- # Rename to mcp for convenience
15
- mv $(go env GOPATH)/bin/mcp2cli $(go env GOPATH)/bin/mcp
18
+ **mcp2cli compresses that into one bash command:**
16
19
 
17
- # List configured servers (no server connection)
18
- mcp
19
-
20
- # Inspect a server's available tools
21
- mcp openDeepWiki
22
-
23
- # View tool details with parameter examples
24
- mcp openDeepWiki list_repositories
25
-
26
- # Call a tool
27
- mcp openDeepWiki list_repositories limit=3
20
+ ```
21
+ # Direct MCP: 3 rounds, ~2000+ tokens of context
22
+ 1. list_tools(server) → get all tool schemas
23
+ 2. get_tool_details(server, tool) read parameter definitions
24
+ 3. call_tool(server, tool, args) → get result
28
25
 
29
- # Call with typed arguments (recommended)
30
- mcp openDeepWiki list_repositories limit:number=3 enabled:bool=true
26
+ # mcp2cli: 1 bash call, ~200 tokens
27
+ mcp openDeepWiki get_repo_structure repoOwner=github repoName=vscode
31
28
  ```
32
29
 
33
- ## Argument Format
30
+ **Result: 80-90% fewer tokens per tool interaction.**
34
31
 
35
- Arguments can be in two formats:
32
+ ## Quick Start
36
33
 
37
34
  ```bash
38
- # Simple key=value (string type by default)
39
- mcp server tool name=John age=30
35
+ # Install
36
+ npm install -g @weibaohui/mcp2cli
40
37
 
41
- # Typed key:type=value (recommended for precision)
42
- mcp server tool name:string=John age:number=30 enabled:bool=true
43
- ```
38
+ # List servers
39
+ mcp
44
40
 
45
- **Supported types:** `string`, `number`, `int`, `float`, `bool`
41
+ # Explore tools on a server
42
+ mcp openDeepWiki
46
43
 
47
- ---
44
+ # View tool details + param examples
45
+ mcp openDeepWiki get_repo_structure
48
46
 
49
- ## Features
47
+ # Call a tool
48
+ mcp openDeepWiki get_repo_structure repoOwner=github repoName=vscode
49
+ ```
50
50
 
51
- - **🔍 Discover Servers** - List all configured MCP servers without connecting
52
- - **📋 Explore Tools** - View detailed tool information with formatted parameters
53
- - **🚀 Invoke Tools** - Call tools directly with type-safe arguments
54
- - **🔌 Multiple Transports** - Support for SSE, Streamable HTTP, and Stdio
55
- - **📁 Smart Config** - Auto-detects and merges configs from standard locations
56
- - **📤 Unified JSON Output** - Machine-readable output for scripting
51
+ ## How It Saves Tokens
57
52
 
58
- ## Installation
53
+ ### Before: Direct MCP (verbose)
59
54
 
60
- ### Binary (latest release)
55
+ Every MCP interaction requires the LLM to maintain tool schemas in context:
61
56
 
62
- Download from [GitHub Releases](https://github.com/weibaohui/mcp2cli/releases/latest)
57
+ ```json
58
+ // Tool schema alone = ~500 tokens, stays in EVERY message
59
+ {
60
+ "name": "get_repo_structure",
61
+ "description": "Retrieves the complete file and directory structure of a Git repository...",
62
+ "inputSchema": {
63
+ "type": "object",
64
+ "properties": {
65
+ "repoOwner": {"type": "string", "description": "..."},
66
+ "repoName": {"type": "string", "description": "..."},
67
+ ...
68
+ },
69
+ "required": ["repoOwner", "repoName"]
70
+ }
71
+ }
72
+ ```
63
73
 
64
- ### From source
74
+ Multiply this by **every tool on every server** — a server with 20 tools = ~10,000 tokens permanently in context.
65
75
 
66
- ```bash
67
- go install github.com/weibaohui/mcp2cli@latest
68
- ```
76
+ ### After: mcp2cli (lean)
69
77
 
70
- ### Build from source
78
+ The LLM only needs a short bash command. No schemas, no tool definitions, no protocol overhead:
71
79
 
72
80
  ```bash
73
- git clone https://github.com/weibaohui/mcp2cli.git
74
- cd mcp2cli
75
- make build
81
+ # Token cost: just the command string (~30 tokens)
82
+ mcp openDeepWiki get_repo_structure repoOwner=github repoName=vscode
76
83
  ```
77
84
 
78
- ## Configuration
79
-
80
- Create `~/.config/mcp/config.json`:
81
-
82
85
  ```json
86
+ // Output is concise JSON (~100 tokens)
83
87
  {
84
- "mcpServers": {
85
- "openDeepWiki": {
86
- "url": "https://opendeepwiki.k8m.site/mcp/streamable",
87
- "timeout": 30000
88
- }
89
- }
88
+ "success": true,
89
+ "data": { "server": "openDeepWiki", "method": "get_repo_structure", "result": "..." },
90
+ "meta": { "timestamp": "2026-03-28T10:00:00Z", "version": "v0.3.0" }
90
91
  }
91
92
  ```
92
93
 
93
- ### Config File Search Paths
94
+ ### Token Comparison
95
+
96
+ | Scenario | Direct MCP | mcp2cli | Saving |
97
+ |----------|-----------|---------|--------|
98
+ | Discover 1 tool | ~500 tokens (schema in context) | ~100 tokens (one bash call) | 80% |
99
+ | Call 1 tool | ~300 tokens (schema + call overhead) | ~130 tokens (command + output) | 57% |
100
+ | 10-tool server in context | ~10,000 tokens (persistent) | 0 tokens (loaded on demand) | 100% |
101
+ | Full workflow (discover + call) | ~2,000 tokens | ~230 tokens | 89% |
94
102
 
95
- | Platform | Priority Order |
96
- |----------|---------------|
97
- | macOS/Linux | `~/.config/modelcontextprotocol/mcp.json` → `~/.config/mcp/config.json` → `./mcp.json` → `./.mcp/config.json` → `/etc/mcp/config.json` |
98
- | Windows | `%APPDATA%\modelcontextprotocol\mcp.json` → `%APPDATA%\mcp\config.json` → `%USERPROFILE%\.mcp\config.json` → `.\mcp.json` → `.\.mcp\config.json` |
103
+ ## Usage in Claude Code / Cursor / Windsurf
99
104
 
100
- ### Config File Format
105
+ Add to your project's MCP config (e.g. `.mcp/config.json` or `~/.config/mcp/config.json`):
101
106
 
102
107
  ```json
103
108
  {
104
109
  "mcpServers": {
105
- "serverName": {
106
- "transport": "streamable",
107
- "url": "https://example.com/mcp",
108
- "command": "npx",
109
- "args": ["-y", "@server/mcp"],
110
- "env": {"KEY": "value"},
111
- "timeout": 30000,
112
- "headers": {
113
- "Authorization": "Bearer ${API_TOKEN}",
114
- "X-API-Key": "${API_KEY}"
115
- }
110
+ "openDeepWiki": {
111
+ "url": "https://opendeepwiki.k8m.site/mcp/streamable"
116
112
  }
117
113
  }
118
114
  }
119
115
  ```
120
116
 
121
- ### Authentication
117
+ Then in your AI tool, just run bash commands:
122
118
 
123
- **HTTP Headers (API Key / Bearer Token):**
124
- ```json
125
- {
126
- "mcpServers": {
127
- "secure-server": {
128
- "url": "https://api.example.com/mcp",
129
- "headers": {
130
- "Authorization": "Bearer ${API_TOKEN}",
131
- "X-API-Key": "${API_KEY}"
132
- }
133
- }
134
- }
135
- }
136
119
  ```
120
+ # The LLM can explore and call tools in one step
121
+ $ mcp openDeepWiki list_repositories limit=3
137
122
 
138
- Supports `${VAR}` and `$VAR` environment variable substitution.
123
+ # No need to load tool schemas — just call
124
+ $ mcp openDeepWiki get_repo_structure repoOwner=weibaohui repoName=mcp2cli
125
+ ```
139
126
 
140
- **OAuth 2.1 with Static Access Token:**
141
- ```json
142
- {
143
- "mcpServers": {
144
- "oauth-server": {
145
- "url": "https://api.example.com/mcp",
146
- "auth": {
147
- "oauth": {
148
- "accessToken": "${OAUTH_ACCESS_TOKEN}"
149
- }
150
- }
151
- }
152
- }
153
- }
127
+ ## Argument Format
128
+
129
+ ### Simple Arguments (key=value)
130
+
131
+ ```bash
132
+ # Simple key=value (string by default)
133
+ mcp server tool name=John age=30
134
+
135
+ # Typed key:type=value (for precision)
136
+ mcp server tool name:string=John age:number=30 enabled:bool=true
154
137
  ```
155
138
 
156
- **Transport Types:**
157
- | Type | Description |
158
- |------|-------------|
159
- | `streamable` | Modern streaming HTTP (default) |
160
- | `sse` | Server-Sent Events over HTTP |
161
- | `stdio` | Local subprocess communication |
139
+ **Supported types:** `string`, `number`, `int`, `float`, `bool`
162
140
 
163
- ## Command Reference
141
+ ### YAML Input (for complex parameters)
142
+
143
+ For complex parameters (objects, arrays, multi-line text), use YAML format:
164
144
 
165
145
  ```bash
166
- # List all configured servers
167
- mcp
146
+ # Inline YAML with --yaml or -y
147
+ mcp server tool --yaml 'name: John details: {age: 30, city: NYC}'
148
+ mcp server tool -y 'tags: [dev, ops] enabled: true'
168
149
 
169
- # Get server info with tools list
170
- mcp <server_name>
150
+ # Multi-line YAML
151
+ mcp server tool --yaml 'limit: 10
152
+ offset: 5
153
+ status: "ready"'
171
154
 
172
- # Get tool details with parameter examples
173
- mcp <server_name> <tool_name>
155
+ # Read from file (like kubectl apply -f)
156
+ mcp server tool -f params.yaml
174
157
 
175
- # Call a tool with arguments
176
- mcp <server_name> <tool_name> <key=value> [key2=value2]...
158
+ # Pipe YAML to stdin
159
+ cat params.yaml | mcp server tool
177
160
  ```
178
161
 
179
- ## Output Format
162
+ **Priority:** `-f` > `--yaml/-y` > stdin pipe > `key=value`
180
163
 
181
- All commands return unified JSON:
164
+ ### Output Format
182
165
 
183
- ```json
184
- {
185
- "success": true,
186
- "data": {
187
- "configFiles": ["/home/user/.config/mcp/config.json"],
188
- "servers": [
189
- {
190
- "name": "openDeepWiki",
191
- "transport": "streamable",
192
- "url": "https://opendeepwiki.k8m.site/mcp/streamable"
193
- }
194
- ]
195
- },
196
- "meta": {
197
- "timestamp": "2026-03-24T10:00:00Z",
198
- "version": "v0.2.8"
199
- }
200
- }
201
- ```
166
+ Control output format with `--output` / `-o`:
167
+
168
+ ```bash
169
+ # JSON (default, human-readable with indentation)
170
+ mcp server tool
202
171
 
203
- ## Architecture
172
+ # YAML output
173
+ mcp --output yaml server tool
204
174
 
175
+ # Text output (compact JSON, good for piping)
176
+ mcp -o text server tool
205
177
  ```
206
- cmd/mcp/main.go # CLI entry point, argument routing
207
- internal/mcp/
208
- ├── types.go # Error codes, shared types
209
- ├── config.go # Config loading & merging
210
- ├── config_paths.go # Platform-specific paths
211
- ├── client.go # MCP server client
212
- ├── dispatcher.go # Multi-server coordination
213
- └── formatter.go # Schema formatting, arg parsing
178
+
179
+ | Format | Description | Use Case |
180
+ |--------|-------------|----------|
181
+ | `json` | Pretty-printed JSON | Default, debugging |
182
+ | `yaml` | YAML format | Config files, readability |
183
+ | `text` | Compact JSON | Piping, scripts |
184
+
185
+ ## Installation
186
+
187
+ ### npm (recommended)
188
+
189
+ ```bash
190
+ npm install -g @weibaohui/mcp2cli
214
191
  ```
215
192
 
216
- ## Development
193
+ Supports Linux, macOS, Windows on amd64/arm64. `mcp` command ready immediately.
194
+
195
+ ### Go install
217
196
 
218
197
  ```bash
219
- # Build for current platform
220
- make build
198
+ go install github.com/weibaohui/mcp2cli@latest
199
+ mv $(go env GOPATH)/bin/mcp2cli $(go env GOPATH)/bin/mcp
200
+ ```
221
201
 
222
- # Build for all platforms
223
- make build-all
202
+ ### Binary download
224
203
 
225
- # Run tests
226
- make test
204
+ Download from [GitHub Releases](https://github.com/weibaohui/mcp2cli/releases/latest):
227
205
 
228
- # Lint code
229
- make lint
206
+ ```bash
207
+ # macOS / Linux
208
+ mv mcp2cli-darwin-arm64 mcp && chmod +x mcp && sudo mv mcp /usr/local/bin/
209
+
210
+ # Windows
211
+ ren mcp2cli-windows-amd64.exe mcp.exe
230
212
  ```
231
213
 
214
+ ## Command Reference
215
+
216
+ | Command | Description |
217
+ |---------|-------------|
218
+ | `mcp` | List configured servers |
219
+ | `mcp <server>` | List tools on a server |
220
+ | `mcp <server> <tool>` | Show tool details + param examples |
221
+ | `mcp <server> <tool> key=value ...` | Call a tool |
222
+
223
+ ### Global Flags
224
+
225
+ | Flag | Short | Description | Default |
226
+ |------|-------|-------------|---------|
227
+ | `--output` | `-o` | Output format (json\|yaml\|text) | `json` |
228
+ | `--yaml` | `-y` | YAML parameters (inline) | |
229
+ | `--file` | `-f` | YAML file with parameters | |
230
+ | `--stream` | `-s` | Enable streaming output | `false` |
231
+
232
232
  ## License
233
233
 
234
234
  MIT License - see [LICENSE](LICENSE) for details.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weibaohui/mcp2cli",
3
- "version": "0.2.8",
3
+ "version": "0.4.0",
4
4
  "description": "CLI tool for interacting with MCP (Model Context Protocol) Servers",
5
5
  "author": "weibaohui",
6
6
  "license": "MIT",
@@ -24,20 +24,19 @@
24
24
  "x64",
25
25
  "arm64"
26
26
  ],
27
- "main": "index.js",
28
27
  "bin": {
29
- "mcp": "./install.js"
28
+ "mcp": "./run.js"
30
29
  },
31
30
  "files": [
32
31
  "dist/",
33
- "index.js",
34
- "install.js",
32
+ "run.js",
33
+ "postinstall.js",
35
34
  "README.md"
36
35
  ],
37
36
  "engines": {
38
37
  "node": ">=18.0.0"
39
38
  },
40
39
  "scripts": {
41
- "postinstall": "node install.js"
40
+ "postinstall": "node postinstall.js"
42
41
  }
43
42
  }
@@ -6,14 +6,12 @@ const path = require('path');
6
6
  const platform = process.platform;
7
7
  const arch = process.arch;
8
8
 
9
- // Map platform names
10
9
  const platformMap = {
11
10
  'darwin': 'darwin',
12
11
  'linux': 'linux',
13
12
  'win32': 'windows'
14
13
  };
15
14
 
16
- // Map arch names - npm uses x64, Go uses amd64
17
15
  const archMap = {
18
16
  'x64': 'amd64',
19
17
  'arm64': 'arm64'
@@ -29,10 +27,7 @@ if (!npmPlatform || !npmArch) {
29
27
 
30
28
  const binaryName = `mcp2cli-${npmPlatform}-${npmArch}`;
31
29
  const binaryPath = path.join(__dirname, 'dist', binaryName);
32
- const targetPath = path.join(__dirname, 'mcp2cli');
33
-
34
- // Add .exe on Windows
35
- const exeTargetPath = platform === 'win32' ? targetPath + '.exe' : targetPath;
30
+ const targetPath = path.join(__dirname, platform === 'win32' ? 'mcp2cli.exe' : 'mcp2cli');
36
31
 
37
32
  if (!fs.existsSync(binaryPath)) {
38
33
  console.error(`Binary not found: ${binaryPath}`);
@@ -40,12 +35,8 @@ if (!fs.existsSync(binaryPath)) {
40
35
  process.exit(1);
41
36
  }
42
37
 
43
- // Copy binary to target location
44
- fs.copyFileSync(binaryPath, exeTargetPath);
38
+ fs.copyFileSync(binaryPath, targetPath);
45
39
 
46
- // Make executable on Unix systems
47
40
  if (platform !== 'win32') {
48
- fs.chmodSync(exeTargetPath, 0o755);
41
+ fs.chmodSync(targetPath, 0o755);
49
42
  }
50
-
51
- console.log(`Installed mcp2cli ${npmPlatform}/${npmArch} successfully`);
package/run.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require('child_process');
4
+ const path = require('path');
5
+
6
+ const binary = process.platform === 'win32'
7
+ ? path.join(__dirname, 'mcp2cli.exe')
8
+ : path.join(__dirname, 'mcp2cli');
9
+
10
+ try {
11
+ execFileSync(binary, process.argv.slice(2), { stdio: 'inherit' });
12
+ } catch (e) {
13
+ process.exit(e.status || 1);
14
+ }