@apify/mcpc 0.1.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.
Files changed (178) hide show
  1. package/.claude/settings.local.json +36 -0
  2. package/.eslintrc.json +44 -0
  3. package/.idea/codeStyles/Project.xml +60 -0
  4. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +11 -0
  6. package/.idea/prettier.xml +6 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/.idea/workspace.xml +572 -0
  9. package/LICENSE +201 -0
  10. package/PHASE1-SUMMARY.md +269 -0
  11. package/PUBLISHING.md +111 -0
  12. package/README.md +1056 -0
  13. package/TESTING.md +212 -0
  14. package/TODOs.md +94 -0
  15. package/bin/mcpc +9 -0
  16. package/bin/mcpc-bridge +9 -0
  17. package/dist/bridge/index.d.ts +3 -0
  18. package/dist/bridge/index.d.ts.map +1 -0
  19. package/dist/bridge/index.js +587 -0
  20. package/dist/bridge/index.js.map +1 -0
  21. package/dist/cli/commands/auth.d.ts +9 -0
  22. package/dist/cli/commands/auth.d.ts.map +1 -0
  23. package/dist/cli/commands/auth.js +81 -0
  24. package/dist/cli/commands/auth.js.map +1 -0
  25. package/dist/cli/commands/clean.d.ts +11 -0
  26. package/dist/cli/commands/clean.d.ts.map +1 -0
  27. package/dist/cli/commands/clean.js +224 -0
  28. package/dist/cli/commands/clean.js.map +1 -0
  29. package/dist/cli/commands/index.d.ts +8 -0
  30. package/dist/cli/commands/index.d.ts.map +1 -0
  31. package/dist/cli/commands/index.js +8 -0
  32. package/dist/cli/commands/index.js.map +1 -0
  33. package/dist/cli/commands/logging.d.ts +3 -0
  34. package/dist/cli/commands/logging.d.ts.map +1 -0
  35. package/dist/cli/commands/logging.js +22 -0
  36. package/dist/cli/commands/logging.js.map +1 -0
  37. package/dist/cli/commands/prompts.d.ts +6 -0
  38. package/dist/cli/commands/prompts.d.ts.map +1 -0
  39. package/dist/cli/commands/prompts.js +27 -0
  40. package/dist/cli/commands/prompts.js.map +1 -0
  41. package/dist/cli/commands/resources.d.ts +11 -0
  42. package/dist/cli/commands/resources.d.ts.map +1 -0
  43. package/dist/cli/commands/resources.js +70 -0
  44. package/dist/cli/commands/resources.js.map +1 -0
  45. package/dist/cli/commands/sessions.d.ts +28 -0
  46. package/dist/cli/commands/sessions.d.ts.map +1 -0
  47. package/dist/cli/commands/sessions.js +356 -0
  48. package/dist/cli/commands/sessions.js.map +1 -0
  49. package/dist/cli/commands/tools.d.ts +8 -0
  50. package/dist/cli/commands/tools.d.ts.map +1 -0
  51. package/dist/cli/commands/tools.js +54 -0
  52. package/dist/cli/commands/tools.js.map +1 -0
  53. package/dist/cli/commands/utilities.d.ts +3 -0
  54. package/dist/cli/commands/utilities.d.ts.map +1 -0
  55. package/dist/cli/commands/utilities.js +20 -0
  56. package/dist/cli/commands/utilities.js.map +1 -0
  57. package/dist/cli/helpers.d.ts +18 -0
  58. package/dist/cli/helpers.d.ts.map +1 -0
  59. package/dist/cli/helpers.js +165 -0
  60. package/dist/cli/helpers.js.map +1 -0
  61. package/dist/cli/index.d.ts +3 -0
  62. package/dist/cli/index.d.ts.map +1 -0
  63. package/dist/cli/index.js +326 -0
  64. package/dist/cli/index.js.map +1 -0
  65. package/dist/cli/output.d.ts +18 -0
  66. package/dist/cli/output.d.ts.map +1 -0
  67. package/dist/cli/output.js +221 -0
  68. package/dist/cli/output.js.map +1 -0
  69. package/dist/cli/parser.d.ts +19 -0
  70. package/dist/cli/parser.d.ts.map +1 -0
  71. package/dist/cli/parser.js +168 -0
  72. package/dist/cli/parser.js.map +1 -0
  73. package/dist/cli/shell-parser.d.ts +5 -0
  74. package/dist/cli/shell-parser.d.ts.map +1 -0
  75. package/dist/cli/shell-parser.js +38 -0
  76. package/dist/cli/shell-parser.js.map +1 -0
  77. package/dist/cli/shell.d.ts +2 -0
  78. package/dist/cli/shell.d.ts.map +1 -0
  79. package/dist/cli/shell.js +277 -0
  80. package/dist/cli/shell.js.map +1 -0
  81. package/dist/cli/tool-result.d.ts +2 -0
  82. package/dist/cli/tool-result.d.ts.map +1 -0
  83. package/dist/cli/tool-result.js +19 -0
  84. package/dist/cli/tool-result.js.map +1 -0
  85. package/dist/core/factory.d.ts +19 -0
  86. package/dist/core/factory.d.ts.map +1 -0
  87. package/dist/core/factory.js +55 -0
  88. package/dist/core/factory.js.map +1 -0
  89. package/dist/core/index.d.ts +4 -0
  90. package/dist/core/index.d.ts.map +1 -0
  91. package/dist/core/index.js +4 -0
  92. package/dist/core/index.js.map +1 -0
  93. package/dist/core/mcp-client.d.ts +30 -0
  94. package/dist/core/mcp-client.d.ts.map +1 -0
  95. package/dist/core/mcp-client.js +215 -0
  96. package/dist/core/mcp-client.js.map +1 -0
  97. package/dist/core/transports.d.ts +12 -0
  98. package/dist/core/transports.d.ts.map +1 -0
  99. package/dist/core/transports.js +65 -0
  100. package/dist/core/transports.js.map +1 -0
  101. package/dist/lib/auth/auth-profiles.d.ts +7 -0
  102. package/dist/lib/auth/auth-profiles.d.ts.map +1 -0
  103. package/dist/lib/auth/auth-profiles.js +105 -0
  104. package/dist/lib/auth/auth-profiles.js.map +1 -0
  105. package/dist/lib/auth/keychain.d.ts +22 -0
  106. package/dist/lib/auth/keychain.d.ts.map +1 -0
  107. package/dist/lib/auth/keychain.js +92 -0
  108. package/dist/lib/auth/keychain.js.map +1 -0
  109. package/dist/lib/auth/oauth-flow.d.ts +7 -0
  110. package/dist/lib/auth/oauth-flow.d.ts.map +1 -0
  111. package/dist/lib/auth/oauth-flow.js +236 -0
  112. package/dist/lib/auth/oauth-flow.js.map +1 -0
  113. package/dist/lib/auth/oauth-provider.d.ts +24 -0
  114. package/dist/lib/auth/oauth-provider.d.ts.map +1 -0
  115. package/dist/lib/auth/oauth-provider.js +144 -0
  116. package/dist/lib/auth/oauth-provider.js.map +1 -0
  117. package/dist/lib/auth/oauth-token-manager.d.ts +25 -0
  118. package/dist/lib/auth/oauth-token-manager.d.ts.map +1 -0
  119. package/dist/lib/auth/oauth-token-manager.js +70 -0
  120. package/dist/lib/auth/oauth-token-manager.js.map +1 -0
  121. package/dist/lib/auth/oauth-utils.d.ts +14 -0
  122. package/dist/lib/auth/oauth-utils.d.ts.map +1 -0
  123. package/dist/lib/auth/oauth-utils.js +68 -0
  124. package/dist/lib/auth/oauth-utils.js.map +1 -0
  125. package/dist/lib/auth/token-refresh.d.ts +2 -0
  126. package/dist/lib/auth/token-refresh.d.ts.map +1 -0
  127. package/dist/lib/auth/token-refresh.js +70 -0
  128. package/dist/lib/auth/token-refresh.js.map +1 -0
  129. package/dist/lib/bridge-client.d.ts +23 -0
  130. package/dist/lib/bridge-client.d.ts.map +1 -0
  131. package/dist/lib/bridge-client.js +181 -0
  132. package/dist/lib/bridge-client.js.map +1 -0
  133. package/dist/lib/bridge-manager.d.ts +17 -0
  134. package/dist/lib/bridge-manager.d.ts.map +1 -0
  135. package/dist/lib/bridge-manager.js +240 -0
  136. package/dist/lib/bridge-manager.js.map +1 -0
  137. package/dist/lib/config.d.ts +6 -0
  138. package/dist/lib/config.d.ts.map +1 -0
  139. package/dist/lib/config.js +116 -0
  140. package/dist/lib/config.js.map +1 -0
  141. package/dist/lib/errors.d.ts +23 -0
  142. package/dist/lib/errors.d.ts.map +1 -0
  143. package/dist/lib/errors.js +81 -0
  144. package/dist/lib/errors.js.map +1 -0
  145. package/dist/lib/file-lock.d.ts +2 -0
  146. package/dist/lib/file-lock.d.ts.map +1 -0
  147. package/dist/lib/file-lock.js +46 -0
  148. package/dist/lib/file-lock.js.map +1 -0
  149. package/dist/lib/file-logger.d.ts +19 -0
  150. package/dist/lib/file-logger.d.ts.map +1 -0
  151. package/dist/lib/file-logger.js +126 -0
  152. package/dist/lib/file-logger.js.map +1 -0
  153. package/dist/lib/index.d.ts +6 -0
  154. package/dist/lib/index.d.ts.map +1 -0
  155. package/dist/lib/index.js +6 -0
  156. package/dist/lib/index.js.map +1 -0
  157. package/dist/lib/logger.d.ts +24 -0
  158. package/dist/lib/logger.d.ts.map +1 -0
  159. package/dist/lib/logger.js +189 -0
  160. package/dist/lib/logger.js.map +1 -0
  161. package/dist/lib/session-client.d.ts +28 -0
  162. package/dist/lib/session-client.d.ts.map +1 -0
  163. package/dist/lib/session-client.js +104 -0
  164. package/dist/lib/session-client.js.map +1 -0
  165. package/dist/lib/sessions.d.ts +9 -0
  166. package/dist/lib/sessions.d.ts.map +1 -0
  167. package/dist/lib/sessions.js +116 -0
  168. package/dist/lib/sessions.js.map +1 -0
  169. package/dist/lib/types.d.ts +117 -0
  170. package/dist/lib/types.d.ts.map +1 -0
  171. package/dist/lib/types.js +2 -0
  172. package/dist/lib/types.js.map +1 -0
  173. package/dist/lib/utils.d.ts +29 -0
  174. package/dist/lib/utils.d.ts.map +1 -0
  175. package/dist/lib/utils.js +173 -0
  176. package/dist/lib/utils.js.map +1 -0
  177. package/package.json +71 -0
  178. package/tsconfig.test.json +11 -0
package/TESTING.md ADDED
@@ -0,0 +1,212 @@
1
+ # Quick Testing Guide for mcpc
2
+
3
+ This guide provides quick commands to test the current implementation of mcpc.
4
+
5
+ ## Prerequisites
6
+
7
+ ```bash
8
+ npm install
9
+ npm run build
10
+ ```
11
+
12
+ ## Quick Tests
13
+
14
+ ### 1. Help and Version
15
+
16
+ ```bash
17
+ # Show help
18
+ node dist/cli/index.js --help
19
+
20
+ # Show version
21
+ node dist/cli/index.js --version
22
+ ```
23
+
24
+ ### 2. HTTP URL Targets
25
+
26
+ ```bash
27
+ # Try to connect to a URL (will fail - no real server)
28
+ node dist/cli/index.js https://example.com/mcp tools-list
29
+
30
+ # With verbose logging
31
+ node dist/cli/index.js https://example.com/mcp --verbose tools-list
32
+ ```
33
+
34
+ ### 3. Config File Loading
35
+
36
+ ```bash
37
+ # List servers in config
38
+ cat examples/test-config.json
39
+
40
+ # Use HTTP server from config (will fail to connect)
41
+ node dist/cli/index.js --config examples/test-config.json example-http tools-list
42
+
43
+ # Try non-existent server (shows error)
44
+ node dist/cli/index.js --config examples/test-config.json bad-server tools-list
45
+
46
+ # Test environment variable substitution
47
+ EXAMPLE_API_TOKEN=secret123 node dist/cli/index.js \
48
+ --config examples/test-config.json example-http tools-list
49
+ ```
50
+
51
+ ### 4. Package Resolution
52
+
53
+ ```bash
54
+ # Create test package in node_modules
55
+ mkdir -p node_modules/example-mcp-server
56
+ cp -r examples/test-package/* node_modules/example-mcp-server/
57
+
58
+ # Try to use the package (will fail - not a real MCP server)
59
+ node dist/cli/index.js example-mcp-server tools-list
60
+
61
+ # Try non-existent package (shows helpful error)
62
+ node dist/cli/index.js nonexistent-package tools-list
63
+
64
+ # With verbose to see resolution details
65
+ node dist/cli/index.js example-mcp-server --verbose tools-list
66
+ ```
67
+
68
+ ### 5. Named Sessions (Not Implemented)
69
+
70
+ ```bash
71
+ # Try named session (shows "not implemented")
72
+ node dist/cli/index.js @my-session tools-list
73
+ ```
74
+
75
+ ## Real MCP Server Testing
76
+
77
+ To test with an actual MCP server, you can:
78
+
79
+ ### Option 1: Install an official MCP server package
80
+
81
+ ```bash
82
+ # Install a real MCP server (example - adjust as needed)
83
+ npm install -g @modelcontextprotocol/server-filesystem
84
+
85
+ # Use it with mcpc
86
+ mcpc @modelcontextprotocol/server-filesystem tools-list
87
+ ```
88
+
89
+ ### Option 2: Use a remote MCP server
90
+
91
+ ```bash
92
+ # If you have access to a real MCP server URL
93
+ mcpc https://your-mcp-server.com tools-list
94
+ mcpc https://your-mcp-server.com resources-list
95
+ ```
96
+
97
+ ### Option 3: Create a config file for your servers
98
+
99
+ ```json
100
+ {
101
+ "mcpServers": {
102
+ "my-server": {
103
+ "url": "https://my-real-mcp-server.com",
104
+ "headers": {
105
+ "Authorization": "Bearer ${MY_API_KEY}"
106
+ }
107
+ },
108
+ "filesystem": {
109
+ "command": "npx",
110
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ Then use it:
117
+ ```bash
118
+ MY_API_KEY=secret mcpc --config my-config.json my-server tools-list
119
+ mcpc --config my-config.json filesystem resources-list
120
+ ```
121
+
122
+ ## Unit Tests
123
+
124
+ ```bash
125
+ # Run all tests
126
+ npm test
127
+
128
+ # Run specific test file
129
+ npm test -- test/lib/config.test.ts
130
+ npm test -- test/lib/logger.test.ts
131
+
132
+ # Run with coverage
133
+ npm run test:coverage
134
+
135
+ # Watch mode
136
+ npm run test:watch
137
+ ```
138
+
139
+ ## Linting
140
+
141
+ ```bash
142
+ # Check for issues
143
+ npm run lint
144
+
145
+ # Auto-fix issues
146
+ npm run lint:fix
147
+ ```
148
+
149
+ ## Expected Behaviors
150
+
151
+ ### ✅ Should Work
152
+
153
+ - CLI help and version display
154
+ - HTTP URL parsing and resolution
155
+ - Config file loading and parsing
156
+ - Environment variable substitution in configs
157
+ - Package discovery in node_modules
158
+ - Global package discovery (npm and Bun)
159
+ - Clear error messages for missing files/packages
160
+ - Verbose logging with --verbose flag
161
+
162
+ ### ❌ Will Fail (Expected)
163
+
164
+ These will fail because they require actual MCP servers:
165
+
166
+ - Connecting to example.com (not an MCP server)
167
+ - Using the test package (doesn't implement MCP protocol)
168
+ - Any command that needs actual MCP communication
169
+
170
+ These will fail because they're not implemented yet:
171
+
172
+ - Named sessions (@session-name)
173
+ - Session commands (connect, close)
174
+ - Interactive shell
175
+
176
+ ## Troubleshooting
177
+
178
+ ### "Package not found" error
179
+ - Make sure the package is installed in node_modules or globally
180
+ - Check the package name spelling
181
+ - Verify package.json exists in the package
182
+
183
+ ### "Config file not found" error
184
+ - Check the path to the config file
185
+ - Use absolute path or path relative to current directory
186
+
187
+ ### "Server not found in config" error
188
+ - Check the server name matches exactly (case-sensitive)
189
+ - List available servers in the error message
190
+
191
+ ### "Failed to connect" error
192
+ - This is expected when testing with non-real MCP servers
193
+ - Use a real MCP server URL or package to test actual connections
194
+
195
+ ## What's Next
196
+
197
+ After confirming tests work, you can proceed with:
198
+
199
+ **Phase 2: Bridge & Sessions**
200
+ - Persistent MCP connections
201
+ - Session management
202
+ - Unix socket IPC
203
+
204
+ **Phase 3: Authentication**
205
+ - OAuth 2.1 support
206
+ - Keychain integration
207
+ - Auth profile management
208
+
209
+ **Phase 4: Enhancements**
210
+ - Interactive shell
211
+ - Caching
212
+ - Tab completion
package/TODOs.md ADDED
@@ -0,0 +1,94 @@
1
+
2
+ # TODOs
3
+
4
+
5
+ ## Bugs
6
+ - Seems calling invalid/unknown MCP command in shell (perhaps also normally) causes the bridge to be flagged as expired
7
+
8
+ - reconnection doesn't work
9
+ mcpc @apify session  1 ✘
10
+ error: missing required argument 'name'
11
+
12
+
13
+
14
+ ## Next
15
+
16
+ - nit: consistent good server and session info, on server/session info, print also auth info
17
+ - [Using session: apify-docs] => change to show server + transport + version? + auth info!!!
18
+ Active MCP sessions:
19
+ @fs → npx (stdio) --- show also args instead of just "npx"
20
+ - print PID of bridge process
21
+
22
+ Visual examples:
23
+
24
+ Xxx/
25
+ ├── run.sh # Master runner (parallel by suite)
26
+ ├── lib/
27
+ │ ├── common.sh # Assertions, temp dirs, cleanup
28
+ │ ├── server.sh # Start/stop test server helpers
29
+ │ └── mcpc.sh # Wrapper to invoke mcpc with coverage
30
+ ├── fixtures/
31
+ │ └── configs/ # Test config files
32
+ ├── server/
33
+ │ └── index.ts # Configurable test MCP server
34
+
35
+
36
+ * ▐▛███▜▌ * Claude Code v2.0.75
37
+ * ▝▜█████▛▘ * Opus 4.5 · Claude Team
38
+ * ▘▘ ▝▝ * ~/Projects/mcpc
39
+
40
+
41
+ - Better error handling:
42
+ - "mcpc https://mcp.sentry.dev/mcp" with an unknown sever => should hint to use "login"
43
+ - Handle MCP errors by failing the command tool, e.g. invalid tool name..
44
+
45
+ - implement resources-subscribe/resources-unsubscribe command properly
46
+ - > # TODO: automatically update the -o file on changes, without it just keep track of changed files in bridge process' cache, and report in resources-list
47
+
48
+
49
+ ## Security
50
+ - Double-check the MCP security guidelines
51
+ - OAuth issuer - maybe save it and double-check it to ensure domain is not spoofed?
52
+
53
+
54
+ ## Later
55
+
56
+ - nit: Colorize output, e.g. JSONs in one color. MCP provided data like descriptions and instructions in orange.
57
+ - warnings could be orange, errors red
58
+ - - docs: add Claude Skills file to /docs, maybe also man page?
59
+ - Add support for MCP elicitations, and potentially for sampling (e.g. via shell interface?)
60
+ - Add `--proxy [HOST:]PORT` feature to `connect` command to enable MCP proxy:
61
+ - `--proxy-bearer-token X` to require auth token for better security
62
+ - `--proxy-capabilities tools:TOOL_NAME,TOOL_NAME2,...,prompts[:...],...` to limit access to selected MCP features and tools
63
+ (what if tools have ":" or "," in their names?)
64
+ In theory, we could add limit of capabilities to normal sessions, but the LLM could still break out of it, so what's the point.
65
+ - Explain this is useful for AI sandboxing!
66
+ - Implement typing completions (e.g. "mcpc @a...") - not sure how difficult that is
67
+ - nit: Nicer OAuth flow finish web page, add Apify example there. E.g. next step - check Apify rather than close
68
+ - nit: cooler OAuth web pages "Authentication successful!" - show mcpc info
69
+ - audit that on every command, we print next steps as examples
70
+ - more shortcuts, e.g. --profile => -p
71
+ - nit: in README, explain the MCP commands better in a standlone section, with details how they work
72
+
73
+
74
+
75
+ ## E2E test scenarios
76
+ - add end-to-end tests e.g. under `test/e2e` - one bash script per test suite , organized in directories, and one master script that runs them all or selected ones (per directory) in parallel
77
+ - Invariants:
78
+ - --verbose only adds extra info to stderr, never to stdout
79
+ - --json always returns single JSON object to stdout on success (exit code = 0), or an object or nothing at all on error (exit code != 0)
80
+ - We'll need a testing server with all the available features and configurable, for testing.
81
+ - Things to test:
82
+ - handling of errors, invalid params, names, etc.
83
+ - pagination
84
+ - env vars...
85
+ - stdio + filesystem operations,
86
+ - sessions
87
+ - for all commands, tests --verbose doesn't print anything extra to stdout, --json returns json
88
+ - that on session close we send HTTP DELETE https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
89
+ - Test session failover - e.g. kill the bridge process, and try to access the session again (should be restarted)
90
+ - Test server session aborting - if session is aborted by server, bridge process should exit and set session status to "expired"
91
+ - Test auth profiles work long-term and sessions too
92
+ - Can we track test coverage also this way?
93
+ - Text copy can change, but the core texts needs to be shown in both text and JSON mode
94
+
package/bin/mcpc ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Main CLI executable for mcpc
4
+ // This wrapper imports the compiled TypeScript CLI entry point
5
+
6
+ import('../dist/cli/index.js').catch((err) => {
7
+ console.error('Failed to load mcpc CLI:', err.message);
8
+ process.exit(1);
9
+ });
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Bridge process executable for mcpc
4
+ // This wrapper imports the compiled TypeScript bridge entry point
5
+
6
+ import('../dist/bridge/index.js').catch((err) => {
7
+ console.error('Failed to load mcpc-bridge:', err.message);
8
+ process.exit(1);
9
+ });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":""}