@myatkyawthu/mcp-connect 0.2.0 → 0.3.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 myat-kyaw-thu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 myat-kyaw-thu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,170 +1,394 @@
1
- # mcp-connect
2
-
3
- > Dead simple MCP (Model Context Protocol) server for exposing your app functions to AI agents
4
-
5
- [![npm version](https://badge.fury.io/js/mcp-connect.svg)](https://www.npmjs.com/package/mcp-connect)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
-
8
- ## 🚀 Claude Desktop Setup (5 Minutes)
9
-
10
- ### Step 1: Install mcp-connect
11
-
12
- ```bash
13
- npm install -g @myatkyawthu/mcp-connect
14
- ```
15
- ### Step 2: Create mcp.config.js
16
-
17
- ### Step 2: Create Your MCP Server
18
-
19
- ```bash
20
- # Navigate to your project directory
21
- cd your-project
22
-
23
- # Generate sample config
24
- mcp-connect init
25
- ```
26
-
27
- This creates `mcp.config.js` with example tools:
28
-
29
- ```javascript
30
- import { defineMCP } from "@myatkyawthu/mcp-connect";
31
-
32
- export default defineMCP({
33
- name: "My MCP App",
34
- version: "1.0.0",
35
- tools: [
36
- ["hello", async ({ name = "World" }) => `Hello ${name}!`],
37
- ["echo", async ({ message }) => `Echo: ${message}`]
38
- ]
39
- });
40
- ```
41
- ### Step 3: Test Locally
42
-
43
- ### Step 3: Configure Claude Desktop
44
-
45
- Open Claude Desktop config file:
46
- - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
47
- - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
48
-
49
- Add your MCP server:
50
-
51
- ```json
52
- {
53
- "mcpServers": {
54
- "my-app": {
55
- "command": "mcp-connect",
56
- "args": ["C:/full/path/to/your/mcp.config.js"]
57
- }
58
- }
59
- }
60
- ```
61
-
62
- **Important**: Use the full absolute path to your `mcp.config.js` file.
63
-
64
- ### Step 4: Start & Test
65
-
66
- 1. **Restart Claude Desktop** completely
67
- 2. **Test connection**: Ask Claude *"What tools do you have available?"*
68
- 3. **Use your tools**: Try *"Hello there!"* or *"Echo this message"*
69
-
70
- ✅ **Done!** Your functions are now available to Claude Desktop.
71
-
72
- ---
73
-
74
- ## 📖 Tool Definition Guide
75
-
76
- ### Simple Format (Recommended)
77
-
78
- ```javascript
79
- // Just name and function
80
- ["toolName", async (args) => "result"]
81
- ```
82
- ## 🔧 CLI Usage
83
-
84
- ### Advanced Format (With Validation)
85
-
86
- ```javascript
87
- {
88
- name: "toolName",
89
- description: "What this tool does",
90
- schema: {
91
- type: "object",
92
- properties: {
93
- param: { type: "string", description: "Parameter description" }
94
- },
95
- required: ["param"]
96
- },
97
- handler: async ({ param }) => `Result: ${param}`
98
- }
99
- ```
100
-
101
- ## 🛠 Development Commands
102
-
103
- ```bash
104
- # Start with auto-reload during development
105
- npm run dev
106
-
107
- # Start server with specific config file
108
- mcp-connect /path/to/your/mcp.config.js
109
-
110
- # Format code
111
- npm run format
112
-
113
- # Lint code
114
- npm run lint
115
- ```
116
-
117
- ## 🔧 Troubleshooting
118
-
119
- ### Config File Not Found
120
- ```bash
121
- # Create sample config
122
- mcp-connect init
123
- ```
124
-
125
- ### Claude Desktop Not Connecting
126
- 1. Check config file path is absolute
127
- 2. Restart Claude Desktop completely
128
- 3. Check Claude Desktop logs for errors
129
-
130
- ### Tool Not Working
131
- 1. Verify tool syntax in `mcp.config.js`
132
- 2. Check server logs for errors
133
- 3. Test with simple tools first
134
-
135
- ## 📋 Examples
136
-
137
- ### File Operations
138
- ```javascript
139
- ["readFile", async ({ path }) => {
140
- const fs = await import('fs/promises');
141
- return await fs.readFile(path, 'utf8');
142
- }]
143
- ```
144
-
145
- ### API Calls
146
- ```javascript
147
- ["getWeather", async ({ city }) => {
148
- const response = await fetch(`https://api.weather.com/${city}`);
149
- return await response.json();
150
- }]
151
- ```
152
-
153
- ### Database Queries
154
- ```javascript
155
- ["getUser", async ({ id }) => {
156
- // Your database logic here
157
- return { id, name: "John Doe", email: "john@example.com" };
158
- }]
159
- ```
160
-
161
- ## 🌐 Other MCP Clients
162
-
163
- Claude Desktop setup is covered above. Tutorials for other MCP clients coming soon:
164
- - VS Code extensions
165
- - Custom applications
166
- - Other AI platforms
167
-
168
- ## 📄 License
169
-
1
+ # mcp-connect
2
+
3
+ > Dead simple MCP server framework. Define your tools as async functions it handles the protocol, transport, security, and dashboard.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@myatkyawthu/mcp-connect.svg)](https://www.npmjs.com/package/@myatkyawthu/mcp-connect)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ---
9
+
10
+ ## What is this?
11
+
12
+ **Model Context Protocol (MCP)** is the standard way AI tools (Claude, Cursor, Cline, etc.) call your app's functions. Think of it like a plugin system — any MCP-compatible AI can discover and call your tools.
13
+
14
+ `mcp-connect` removes all the boilerplate. You write async functions. It handles the rest: JSON-RPC wiring, transport, schema advertisement, rate limiting, auth, error handling, and a live inspector dashboard.
15
+
16
+ ```js
17
+ import { defineMCP } from "@myatkyawthu/mcp-connect";
18
+
19
+ export default defineMCP({
20
+ name: "my-server",
21
+ version: "1.0.0",
22
+ tools: [
23
+ ["hello", async ({ name = "World" }) => `Hello ${name}!`],
24
+ {
25
+ name: "echo",
26
+ description: "Echo back the input",
27
+ schema: {
28
+ type: "object",
29
+ properties: { message: { type: "string" } },
30
+ required: ["message"]
31
+ },
32
+ handler: async ({ message }) => `Echo: ${message}`
33
+ }
34
+ ]
35
+ });
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ # Global CLI (recommended)
44
+ npm install -g @myatkyawthu/mcp-connect
45
+
46
+ # Or as a project dependency
47
+ npm install @myatkyawthu/mcp-connect
48
+ ```
49
+
50
+ Requires **Node.js 18+**.
51
+
52
+ ---
53
+
54
+ ## Quick Start
55
+
56
+ ```bash
57
+ # 1. Create a config file
58
+ mcp-connect init
59
+
60
+ # 2. Edit mcp.config.js and add your tools
61
+
62
+ # 3. Run it
63
+ mcp-connect # STDIO mode (for Claude Desktop)
64
+ mcp-connect --port 3000 # SSE/HTTP mode (for web clients, IDEs)
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Three Modes — Pick One
70
+
71
+ ### Mode 1 — STDIO (Local, for Claude Desktop)
72
+
73
+ Your AI tool spawns the process. Communication happens via stdin/stdout pipes. No port, no HTTP.
74
+
75
+ ```bash
76
+ mcp-connect mcp.config.js
77
+ ```
78
+
79
+ **Claude Desktop config** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "my-app": {
84
+ "command": "mcp-connect",
85
+ "args": ["/absolute/path/to/mcp.config.js"]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ ### Mode 2 SSE / HTTP (Deployed on a Server)
94
+
95
+ Starts an HTTP server. AI clients connect to `/sse` and send requests to `/message`. **This is the mode for deploying on a VPS or cloud** so any client can reach it over the internet.
96
+
97
+ ```bash
98
+ mcp-connect mcp.config.js --port 3000
99
+ ```
100
+
101
+ Once deployed behind HTTPS, clients connect to:
102
+ ```
103
+ https://yourserver.com/sse
104
+ ```
105
+
106
+ **Client compatibility:**
107
+
108
+ | Client | SSE Support |
109
+ | :--- | :---: |
110
+ | Claude.ai (web) | ✅ |
111
+ | Cursor | ✅ |
112
+ | Cline (VS Code) | ✅ |
113
+ | Windsurf | ✅ |
114
+ | Continue.dev | ✅ |
115
+ | Zed | ✅ |
116
+ | Claude Desktop | ❌ (STDIO only) |
117
+
118
+ **Endpoints exposed:**
119
+
120
+ | Endpoint | Description |
121
+ | :--- | :--- |
122
+ | `GET /sse` | AI client connects here (long-lived SSE stream) |
123
+ | `POST /message` | AI client sends JSON-RPC requests |
124
+ | `GET /health` | JSON health check with tool list |
125
+ | `GET /` | Live inspector dashboard |
126
+
127
+ ---
128
+
129
+ ### Mode 3 — Tunnel (Behind NAT, No Open Port)
130
+
131
+ If your machine can't receive inbound connections (home laptop, office network), use the tunnel. Run a tiny relay on any $5/month VPS — your local machine connects outbound to it. Remote clients hit the VPS and get proxied to your machine.
132
+
133
+ **Step 1 Start the relay on your VPS (one-time setup):**
134
+ ```bash
135
+ mcp-connect relay --port 4000
136
+ ```
137
+
138
+ **Step 2 — Start your server on your local machine:**
139
+ ```bash
140
+ mcp-connect mcp.config.js --port 3111 --tunnel
141
+ ```
142
+
143
+ Your terminal will print:
144
+ ```
145
+ MCP Tunnel bridge active!
146
+ Remote SSE endpoint: http://your-vps.com/t/<tunnelId>/sse
147
+ ```
148
+
149
+ Share that URL with any MCP client. Done.
150
+
151
+ > The relay auto-reconnects if the tunnel drops. All payloads can be AES-256-GCM encrypted end-to-end (see Security section below).
152
+
153
+ ---
154
+
155
+ ## Tool Definition Formats
156
+
157
+ ### Short format (tuple)
158
+ For simple one-liner tools:
159
+ ```js
160
+ ["toolName", async (args) => result]
161
+ ```
162
+
163
+ ### Full format (object)
164
+ For tools that need schema validation, descriptions, or a security confirmation gate:
165
+ ```js
166
+ {
167
+ name: "delete_record",
168
+ description: "Permanently delete a record by ID",
169
+ schema: {
170
+ type: "object",
171
+ properties: {
172
+ id: { type: "string", description: "Record ID to delete" }
173
+ },
174
+ required: ["id"]
175
+ },
176
+ confirm: true, // asks "y/N?" in terminal before executing
177
+ handler: async ({ id }) => {
178
+ await db.delete(id);
179
+ return `Deleted ${id}`;
180
+ }
181
+ }
182
+ ```
183
+
184
+ The AI receives the schema and knows exactly what arguments to pass. You don't have to document it separately.
185
+
186
+ ---
187
+
188
+ ## Security
189
+
190
+ All security features are optional — enable only what you need.
191
+
192
+ ### Bearer Token Auth
193
+
194
+ Protect the `/sse` and `/message` endpoints. Any request without the correct token gets a `401`.
195
+
196
+ ```bash
197
+ # Set via environment variable
198
+ MCP_TUNNEL_TOKEN=my-secret-token mcp-connect mcp.config.js --port 3000
199
+ ```
200
+
201
+ Or in config:
202
+ ```js
203
+ server: {
204
+ tunnel: { token: "my-secret-token" }
205
+ }
206
+ ```
207
+
208
+ Clients must send: `Authorization: Bearer my-secret-token`
209
+
210
+ ---
211
+
212
+ ### CORS Origin Allowlist
213
+
214
+ Restrict which origins can connect. Without this, all origins are allowed (`*`).
215
+
216
+ ```js
217
+ server: {
218
+ cors: {
219
+ origins: ["https://claude.ai", "https://cursor.sh"]
220
+ }
221
+ }
222
+ ```
223
+
224
+ Requests from unlisted origins get `403 Origin not allowed`.
225
+
226
+ ---
227
+
228
+ ### End-to-End Encryption (Tunnel mode)
229
+
230
+ Encrypt all payloads over the tunnel so the relay server only sees ciphertext. Uses AES-256-GCM.
231
+
232
+ ```js
233
+ server: {
234
+ tunnel: {
235
+ encryptionKey: "my-32-char-passphrase-or-64hex"
236
+ }
237
+ }
238
+ ```
239
+
240
+ The relay cannot read your tool calls or responses even if it's compromised.
241
+
242
+ ---
243
+
244
+ ### Confirm Gate for Dangerous Tools
245
+
246
+ Add `confirm: true` to any tool. Before it runs, the terminal prompts you:
247
+ ```
248
+ ⚠️ [MCP SECURITY] Allow tool "delete_record" execution? (y/N):
249
+ ```
250
+
251
+ The tool only runs if you type `y`. Otherwise it's rejected with an error.
252
+
253
+ ---
254
+
255
+ ## Built-in Protections (Always On)
256
+
257
+ These run automatically without any config:
258
+
259
+ | Protection | Detail |
260
+ | :--- | :--- |
261
+ | **Rate limiting** | 100 requests/minute per server |
262
+ | **Tool timeout** | 30 seconds max per tool call |
263
+ | **Response size cap** | 1MB max, truncated if exceeded |
264
+ | **Error sanitization** | Stack traces stripped before returning to AI |
265
+ | **Circular reference guard** | Safe JSON serialization |
266
+
267
+ ---
268
+
269
+ ## Inspector Dashboard
270
+
271
+ Available at `http://localhost:<port>/` whenever running in SSE mode.
272
+
273
+ - **Logs tab** — live feed of every tool call with timestamp, duration, pass/fail status. Click any row to see full request args and response.
274
+ - **Test Tool tab** — pick a tool, fill in args as JSON, hit Execute. See the response immediately. No AI client needed for debugging.
275
+
276
+ The dashboard connects to `/api/events` over SSE — it updates in real-time without refreshing.
277
+
278
+ ---
279
+
280
+ ## Full Config Reference
281
+
282
+ ```js
283
+ import { defineMCP } from "@myatkyawthu/mcp-connect";
284
+
285
+ export default defineMCP({
286
+ name: "my-server", // required
287
+ version: "1.0.0", // required
288
+ description: "...", // optional
289
+
290
+ server: {
291
+ port: 3000, // optional — same as --port flag
292
+
293
+ cors: {
294
+ origins: [ // optional — allowlist of origins
295
+ "https://claude.ai",
296
+ "http://localhost:5173"
297
+ ]
298
+ },
299
+
300
+ tunnel: {
301
+ enabled: true, // optional — same as --tunnel flag
302
+ relayUrl: "http://your-vps.com:4000", // relay address
303
+ token: "secret", // bearer token for auth
304
+ encryptionKey: "..." // AES-256-GCM key (passphrase or 64-char hex)
305
+ }
306
+ },
307
+
308
+ tools: [
309
+ // Short format
310
+ ["hello", async ({ name = "World" }) => `Hello ${name}!`],
311
+
312
+ // Full format
313
+ {
314
+ name: "echo",
315
+ description: "Echo back the input",
316
+ schema: {
317
+ type: "object",
318
+ properties: {
319
+ message: { type: "string" }
320
+ },
321
+ required: ["message"]
322
+ },
323
+ handler: async ({ message }) => `Echo: ${message}`
324
+ },
325
+
326
+ // Dangerous tool with confirmation gate
327
+ {
328
+ name: "delete_all",
329
+ description: "Wipe everything",
330
+ confirm: true,
331
+ handler: async () => {
332
+ await nuke();
333
+ return "Done.";
334
+ }
335
+ }
336
+ ]
337
+ });
338
+ ```
339
+
340
+ ---
341
+
342
+ ## CLI Reference
343
+
344
+ ```bash
345
+ mcp-connect init # Scaffold mcp.config.js in current directory
346
+ mcp-connect [config.js] # Start in STDIO mode
347
+ mcp-connect [config.js] --port <port> # Start in SSE/HTTP mode
348
+ mcp-connect [config.js] --tunnel # Start with outbound tunnel
349
+ mcp-connect relay --port <port> # Run a relay gateway (deploy on VPS)
350
+ ```
351
+
352
+ Config file defaults to `mcp.config.js` in the current directory if not specified.
353
+
354
+ ---
355
+
356
+ ## Deployment Recipes
357
+
358
+ ### Deploy on Railway / Render / Fly.io
359
+
360
+ 1. Push your repo with `mcp.config.js`
361
+ 2. Set start command: `mcp-connect mcp.config.js --port 3000`
362
+ 3. Set env var: `MCP_TUNNEL_TOKEN=your-secret`
363
+ 4. Add your domain/URL to your AI client as the MCP server URL: `https://yourapp.railway.app/sse`
364
+
365
+ ### Self-hosted VPS (nginx + HTTPS)
366
+
367
+ ```nginx
368
+ location / {
369
+ proxy_pass http://localhost:3000;
370
+ proxy_http_version 1.1;
371
+ proxy_set_header Connection ''; # keep SSE alive
372
+ proxy_buffering off; # required for SSE streaming
373
+ proxy_cache off;
374
+ proxy_set_header Host $host;
375
+ }
376
+ ```
377
+
378
+ Then run: `mcp-connect mcp.config.js --port 3000`
379
+
380
+ ### Laptop behind NAT (tunnel setup)
381
+
382
+ ```bash
383
+ # On VPS
384
+ mcp-connect relay --port 4000
385
+
386
+ # On laptop
387
+ MCP_TUNNEL_TOKEN=secret mcp-connect mcp.config.js --port 3111 --tunnel
388
+ ```
389
+
390
+ ---
391
+
392
+ ## License
393
+
170
394
  MIT © [myat-kyaw-thu](https://github.com/myat-kyaw-thu)