@apify/mcpc 0.1.3 → 0.1.5
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/.claude/settings.local.json +53 -1
- package/.idea/codeStyles/Project.xml +7 -0
- package/.idea/workspace.xml +314 -280
- package/CONTRIBUTING.md +210 -0
- package/README.md +690 -763
- package/dist/bridge/index.js +82 -18
- package/dist/bridge/index.js.map +1 -1
- package/dist/bridge/proxy-server.d.ts +21 -0
- package/dist/bridge/proxy-server.d.ts.map +1 -0
- package/dist/bridge/proxy-server.js +160 -0
- package/dist/bridge/proxy-server.js.map +1 -0
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +9 -4
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/clean.d.ts.map +1 -1
- package/dist/cli/commands/clean.js +21 -27
- package/dist/cli/commands/clean.js.map +1 -1
- package/dist/cli/commands/logging.js +1 -1
- package/dist/cli/commands/logging.js.map +1 -1
- package/dist/cli/commands/prompts.d.ts.map +1 -1
- package/dist/cli/commands/prompts.js +37 -5
- package/dist/cli/commands/prompts.js.map +1 -1
- package/dist/cli/commands/resources.js +5 -5
- package/dist/cli/commands/resources.js.map +1 -1
- package/dist/cli/commands/sessions.d.ts +7 -1
- package/dist/cli/commands/sessions.d.ts.map +1 -1
- package/dist/cli/commands/sessions.js +130 -189
- package/dist/cli/commands/sessions.js.map +1 -1
- package/dist/cli/commands/tools.d.ts +0 -1
- package/dist/cli/commands/tools.d.ts.map +1 -1
- package/dist/cli/commands/tools.js +48 -10
- package/dist/cli/commands/tools.js.map +1 -1
- package/dist/cli/commands/utilities.js +1 -1
- package/dist/cli/commands/utilities.js.map +1 -1
- package/dist/cli/helpers.d.ts +9 -4
- package/dist/cli/helpers.d.ts.map +1 -1
- package/dist/cli/helpers.js +62 -81
- package/dist/cli/helpers.js.map +1 -1
- package/dist/cli/index.js +104 -46
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/output.d.ts +19 -3
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +374 -82
- package/dist/cli/output.js.map +1 -1
- package/dist/cli/parser.d.ts +10 -1
- package/dist/cli/parser.d.ts.map +1 -1
- package/dist/cli/parser.js +155 -43
- package/dist/cli/parser.js.map +1 -1
- package/dist/cli/shell.d.ts.map +1 -1
- package/dist/cli/shell.js +31 -18
- package/dist/cli/shell.js.map +1 -1
- package/dist/core/factory.d.ts +2 -4
- package/dist/core/factory.d.ts.map +1 -1
- package/dist/core/factory.js +3 -34
- package/dist/core/factory.js.map +1 -1
- package/dist/core/mcp-client.d.ts +7 -2
- package/dist/core/mcp-client.d.ts.map +1 -1
- package/dist/core/mcp-client.js +86 -36
- package/dist/core/mcp-client.js.map +1 -1
- package/dist/core/transports.d.ts +2 -2
- package/dist/core/transports.d.ts.map +1 -1
- package/dist/core/transports.js +36 -45
- package/dist/core/transports.js.map +1 -1
- package/dist/lib/auth/keychain.d.ts +3 -0
- package/dist/lib/auth/keychain.d.ts.map +1 -1
- package/dist/lib/auth/keychain.js +18 -0
- package/dist/lib/auth/keychain.js.map +1 -1
- package/dist/lib/auth/oauth-flow.d.ts.map +1 -1
- package/dist/lib/auth/oauth-flow.js +55 -12
- package/dist/lib/auth/oauth-flow.js.map +1 -1
- package/dist/lib/auth/oauth-provider.d.ts.map +1 -1
- package/dist/lib/auth/oauth-provider.js +5 -23
- package/dist/lib/auth/oauth-provider.js.map +1 -1
- package/dist/lib/auth/oauth-token-manager.d.ts.map +1 -1
- package/dist/lib/auth/oauth-token-manager.js +0 -10
- package/dist/lib/auth/oauth-token-manager.js.map +1 -1
- package/dist/lib/auth/profiles.d.ts +5 -1
- package/dist/lib/auth/profiles.d.ts.map +1 -1
- package/dist/lib/auth/profiles.js +80 -13
- package/dist/lib/auth/profiles.js.map +1 -1
- package/dist/lib/bridge-manager.d.ts +3 -2
- package/dist/lib/bridge-manager.d.ts.map +1 -1
- package/dist/lib/bridge-manager.js +42 -24
- package/dist/lib/bridge-manager.js.map +1 -1
- package/dist/lib/config.d.ts +3 -3
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +6 -1
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +13 -1
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/logger.d.ts +7 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +20 -1
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/schema-validator.d.ts +36 -0
- package/dist/lib/schema-validator.d.ts.map +1 -0
- package/dist/lib/schema-validator.js +265 -0
- package/dist/lib/schema-validator.js.map +1 -0
- package/dist/lib/session-client.d.ts +2 -2
- package/dist/lib/session-client.d.ts.map +1 -1
- package/dist/lib/session-client.js +3 -3
- package/dist/lib/session-client.js.map +1 -1
- package/dist/lib/sessions.d.ts +1 -1
- package/dist/lib/sessions.d.ts.map +1 -1
- package/dist/lib/sessions.js +22 -10
- package/dist/lib/sessions.js.map +1 -1
- package/dist/lib/types.d.ts +19 -25
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +13 -1
- package/dist/lib/utils.js.map +1 -1
- package/docs/README.md +19 -0
- package/docs/TODOs.md +43 -0
- package/docs/claude-skill/SKILL.md +50 -30
- package/docs/images/mcpc-screenshot.png +0 -0
- package/package.json +15 -10
- package/PUBLISHING.md +0 -111
- package/TESTING.md +0 -212
- package/TODOs.md +0 -85
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Contributing to mcpc
|
|
2
|
+
|
|
3
|
+
`mcpc` is under active development and some things might not work 100% yet. You have been warned.
|
|
4
|
+
Contributions are welcome!
|
|
5
|
+
|
|
6
|
+
## Design principles
|
|
7
|
+
|
|
8
|
+
- Delightful for humans and AI agents alike (interactive + scripting)
|
|
9
|
+
- Avoid unnecessary interaction loops, provide sufficient context, yet be concise (save tokens)
|
|
10
|
+
- One clear way to do things (orthogonal commands, no surprises)
|
|
11
|
+
- Do not ask for user input (except `shell` and `login`, no unexpected OAuth flows)
|
|
12
|
+
- Be forgiving, always help users make progress (great errors + guidance)
|
|
13
|
+
- Be consistent with the [MCP specification](https://modelcontextprotocol.io/specification/latest), with `--json` strictly
|
|
14
|
+
- Minimal and portable (few deps, cross-platform)
|
|
15
|
+
- Keep backwards compatibility to the maximum extent possible
|
|
16
|
+
- No slop!
|
|
17
|
+
|
|
18
|
+
## Development setup
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Clone repository
|
|
22
|
+
git clone https://github.com/apify/mcpc.git
|
|
23
|
+
cd mcpc
|
|
24
|
+
|
|
25
|
+
# Install dependencies
|
|
26
|
+
npm install
|
|
27
|
+
|
|
28
|
+
# Run tests
|
|
29
|
+
npm test
|
|
30
|
+
|
|
31
|
+
# Build
|
|
32
|
+
npm run build
|
|
33
|
+
|
|
34
|
+
# Test locally
|
|
35
|
+
npm link
|
|
36
|
+
mcpc --help
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Testing
|
|
40
|
+
|
|
41
|
+
See [`test/README.md`](./test/README.md) for details on running unit and E2E tests.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm test # Run all tests (unit + e2e)
|
|
45
|
+
npm run test:unit # Run unit tests only
|
|
46
|
+
npm run test:e2e # Run e2e tests only
|
|
47
|
+
npm run test:coverage # Run all tests with coverage
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Release process
|
|
51
|
+
|
|
52
|
+
Use the release script to publish a new version
|
|
53
|
+
of the [@apify/mcpc](https://www.npmjs.com/package/@apify/mcpc) package on NPM:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm run release # patch version bump (0.1.2 → 0.1.3)
|
|
57
|
+
npm run release:minor # minor version bump (0.1.2 → 0.2.0)
|
|
58
|
+
npm run release:major # major version bump (0.1.2 → 1.0.0)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The script automatically:
|
|
62
|
+
- Ensures you're on `main` branch
|
|
63
|
+
- Ensures working directory is clean (no uncommitted changes)
|
|
64
|
+
- Ensures branch is up-to-date with remote
|
|
65
|
+
- Runs lint, build, and tests
|
|
66
|
+
- Bumps the version in package.json
|
|
67
|
+
- Creates a git commit and annotated tag (`v{version}`)
|
|
68
|
+
- Pushes the commit and tag to origin
|
|
69
|
+
- Publishes to npm
|
|
70
|
+
|
|
71
|
+
After publishing, create a GitHub release at the provided link.
|
|
72
|
+
|
|
73
|
+
## Architecture overview
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
mcpc (single package)
|
|
77
|
+
├── src/
|
|
78
|
+
│ ├── core/ # Core MCP protocol implementation
|
|
79
|
+
│ ├── bridge/ # Bridge process logic
|
|
80
|
+
│ ├── cli/ # CLI interface
|
|
81
|
+
│ └── lib/ # Shared utilities
|
|
82
|
+
├── bin/
|
|
83
|
+
│ ├── mcpc # Main CLI executable
|
|
84
|
+
│ └── mcpc-bridge # Bridge process executable
|
|
85
|
+
└── test/
|
|
86
|
+
└── e2e/
|
|
87
|
+
└── server/ # Test MCP server for E2E tests
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Core module (runtime-agnostic)
|
|
91
|
+
|
|
92
|
+
Implemented with minimal dependencies to support both Node.js (≥18.0.0) and Bun (≥1.0.0).
|
|
93
|
+
|
|
94
|
+
**Core responsibilities:**
|
|
95
|
+
- Transport selection and initialization (Streamable HTTP vs stdio)
|
|
96
|
+
- MCP protocol implementation and version negotiation
|
|
97
|
+
- Session state machine management
|
|
98
|
+
- Streamable HTTP connection management (reconnection with exponential backoff)
|
|
99
|
+
- Request/response correlation (JSON-RPC style with request IDs)
|
|
100
|
+
- Multiplexing concurrent requests (up to 10 concurrent)
|
|
101
|
+
- Event emitter for async notifications
|
|
102
|
+
|
|
103
|
+
**Key dependencies:**
|
|
104
|
+
- Native `fetch` API (available in Node.js 18+ and Bun)
|
|
105
|
+
- Native process APIs for stdio transport
|
|
106
|
+
- Minimal: UUID generation, event emitter abstraction
|
|
107
|
+
|
|
108
|
+
### Bridge process
|
|
109
|
+
|
|
110
|
+
Implemented as a separate executable (`mcpc-bridge`) that maintains persistent connections.
|
|
111
|
+
|
|
112
|
+
**Bridge responsibilities:**
|
|
113
|
+
- Session persistence (reads/writes `~/.mcpc/sessions.json` with file locking)
|
|
114
|
+
- Process lifecycle management for local package servers
|
|
115
|
+
- Stdio framing and protocol handling
|
|
116
|
+
- Unix domain socket server for CLI communication
|
|
117
|
+
- Heartbeat mechanism for health monitoring
|
|
118
|
+
- Orphaned process cleanup on startup
|
|
119
|
+
|
|
120
|
+
**IPC protocol:**
|
|
121
|
+
- Unix domain sockets (located in `~/.mcpc/bridges/<session-name>.sock`)
|
|
122
|
+
- Named pipes on Windows
|
|
123
|
+
- JSON-RPC style messages over socket
|
|
124
|
+
- Control messages: init, request, cancel, close, health-check
|
|
125
|
+
|
|
126
|
+
**Bridge discovery:**
|
|
127
|
+
- CLI reads `~/.mcpc/sessions.json` to find socket path and PID
|
|
128
|
+
- Validates bridge is alive (connect to socket + health-check)
|
|
129
|
+
- Auto-restarts crashed bridges (detected via socket connection failure)
|
|
130
|
+
- Cleanup: removes stale socket files for dead processes
|
|
131
|
+
|
|
132
|
+
**Concurrency safety:**
|
|
133
|
+
- `~/.mcpc/sessions.json` protected with file locking (`proper-lockfile` package)
|
|
134
|
+
- Atomic writes (write to temp file, then rename)
|
|
135
|
+
- Lock timeout: 5 seconds (fails if can't acquire lock)
|
|
136
|
+
|
|
137
|
+
### CLI executable
|
|
138
|
+
|
|
139
|
+
The main `mcpc` command provides the user interface.
|
|
140
|
+
|
|
141
|
+
**CLI responsibilities:**
|
|
142
|
+
- Argument parsing using Commander.js
|
|
143
|
+
- Output formatting (human-readable vs `--json`)
|
|
144
|
+
- Bridge lifecycle: start/connect/stop
|
|
145
|
+
- Communication with bridge via socket
|
|
146
|
+
- Interactive shell (REPL using Node.js `readline`)
|
|
147
|
+
- Configuration file loading (standard MCP JSON format)
|
|
148
|
+
- Credential management (OS keychain via `keytar` package)
|
|
149
|
+
|
|
150
|
+
**Shell implementation:**
|
|
151
|
+
- Built on Node.js `readline` module for input handling with history support
|
|
152
|
+
- Command history using `~/.mcpc/history` (last 1000 commands)
|
|
153
|
+
- Real-time notification display during shell sessions
|
|
154
|
+
- Graceful exit handling (cleanup on Ctrl+C/Ctrl+D)
|
|
155
|
+
|
|
156
|
+
### Session lifecycle
|
|
157
|
+
|
|
158
|
+
1. User: `mcpc https://mcp.apify.com session @apify`
|
|
159
|
+
2. CLI: Atomically creates session entry in `~/.mcpc/sessions.json`
|
|
160
|
+
3. CLI: Spawns bridge process (`mcpc-bridge`)
|
|
161
|
+
4. Bridge: Creates Unix socket at `~/.mcpc/bridges/apify.sock`
|
|
162
|
+
5. Bridge: Performs MCP initialization handshake with server:
|
|
163
|
+
- Sends initialize request with protocol version and capabilities
|
|
164
|
+
- Receives server info, version, and capabilities
|
|
165
|
+
- Sends initialized notification to activate session
|
|
166
|
+
6. Bridge: Updates session in `~/.mcpc/sessions.json` (adds PID, socket path, protocol version)
|
|
167
|
+
7. CLI: Confirms session created
|
|
168
|
+
8. User: mcpc @apify tools-list
|
|
169
|
+
9. CLI: Reads `~/.mcpc/sessions.json`, finds socket path
|
|
170
|
+
10. CLI: Connects to bridge socket
|
|
171
|
+
11. CLI: Sends `tools/list` JSON-RPC request via socket
|
|
172
|
+
12. Bridge: Forwards to MCP server via Streamable HTTP
|
|
173
|
+
13. Bridge: Returns response via socket
|
|
174
|
+
14. CLI: Formats and displays to user
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
### Error recovery
|
|
178
|
+
|
|
179
|
+
**Bridge crashes:**
|
|
180
|
+
1. CLI detects socket connection failure
|
|
181
|
+
2. Reads `~/.mcpc/sessions.json` for last known config
|
|
182
|
+
3. Spawns new bridge process
|
|
183
|
+
4. Bridge re-initializes connection to MCP server
|
|
184
|
+
5. Continues request
|
|
185
|
+
|
|
186
|
+
**Network failures:**
|
|
187
|
+
1. Bridge detects connection error
|
|
188
|
+
2. Begins exponential backoff reconnection
|
|
189
|
+
3. Queues incoming requests (up to 100, max 3min)
|
|
190
|
+
4. On reconnect: drains queue
|
|
191
|
+
5. On timeout: fails queued requests with network error
|
|
192
|
+
|
|
193
|
+
**Orphaned processes:**
|
|
194
|
+
1. On startup, CLI scans `~/.mcpc/bridges/` directory
|
|
195
|
+
2. For each socket file, attempts connection
|
|
196
|
+
3. If connection fails, reads PID from sessions.json
|
|
197
|
+
4. Checks if process exists (via `kill -0` or similar)
|
|
198
|
+
5. If dead: removes socket file and session entry
|
|
199
|
+
6. If alive but unresponsive: kills process, removes entries
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
## References
|
|
203
|
+
|
|
204
|
+
- [Official MCP documentation](https://modelcontextprotocol.io/llms.txt)
|
|
205
|
+
- [Official TypeScript SDK for MCP servers and clients](https://www.npmjs.com/package/@modelcontextprotocol/sdk)
|
|
206
|
+
- [MCP Inspector](https://github.com/modelcontextprotocol/inspector) - CLI client implementation for reference
|
|
207
|
+
|
|
208
|
+
## Getting help
|
|
209
|
+
|
|
210
|
+
Please open an issue or pull request on [GitHub](https://github.com/apify/mcpc).
|