@agimon-ai/model-proxy-mcp 0.2.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 ADDED
@@ -0,0 +1,52 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: AgiFlow
6
+ Licensed Work: @agimon-ai/public-packages
7
+ The Licensed Work is (c) 2026 AgiFlow.
8
+ Additional Use Grant: None
9
+ Change Date: 2030-03-06
10
+ Change License: Apache License, Version 2.0
11
+
12
+ Terms
13
+
14
+ The Licensor hereby grants you the right to copy, modify, create derivative
15
+ works, redistribute, and make non-production use of the Licensed Work. The
16
+ Licensor may make an Additional Use Grant, above, permitting limited
17
+ production use.
18
+
19
+ Effective on the Change Date, or the fourth anniversary of the first publicly
20
+ available distribution of a specific version of the Licensed Work under this
21
+ License, whichever comes first, the Licensor hereby grants you rights under
22
+ the terms of the Change License, and the rights granted in the paragraph
23
+ above terminate.
24
+
25
+ If your use of the Licensed Work does not comply with the requirements
26
+ currently in effect as described in this License, you must purchase a
27
+ commercial license from the Licensor, its affiliated entities, or authorized
28
+ resellers, or you must refrain from using the Licensed Work.
29
+
30
+ All copies of the original and modified Licensed Work, and derivative works
31
+ of the Licensed Work, are subject to this License. This License applies
32
+ separately for each version of the Licensed Work and the Change Date may vary
33
+ for each version of the Licensed Work released by Licensor.
34
+
35
+ You must conspicuously display this License on each original or modified copy
36
+ of the Licensed Work. If you receive the Licensed Work in original or
37
+ modified form from a third party, the terms and conditions set forth in this
38
+ License apply to your use of that work.
39
+
40
+ Any use of the Licensed Work in violation of this License will automatically
41
+ terminate your rights under this License for the current and all other
42
+ versions of the Licensed Work.
43
+
44
+ This License does not grant you any right in any trademark or logo of
45
+ Licensor or its affiliates (provided that you may use a trademark or logo of
46
+ Licensor as expressly required by this License).
47
+
48
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
49
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
50
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
52
+ TITLE.
package/README.md ADDED
@@ -0,0 +1,251 @@
1
+ # model-proxy-mcp
2
+
3
+ Claude-compatible model proxy MCP with ChatGPT Codex upstream support.
4
+
5
+ ## What it does
6
+
7
+ This package provides:
8
+
9
+ - A Claude-compatible HTTP proxy server for `/v1/messages` and `/v1/models`
10
+ - An MCP server over stdio
11
+ - A `claude` wrapper command that launches Claude Code against a scoped proxy URL
12
+ - Scoped model/profile configuration and request history
13
+ - An admin HTTP UI and admin JSON endpoints
14
+
15
+ Key entrypoints:
16
+
17
+ - CLI entry: `packages/mcp/model-proxy-mcp/src/cli.ts:16`
18
+ - Claude wrapper: `packages/mcp/model-proxy-mcp/src/commands/claude.ts:233`
19
+ - HTTP server: `packages/mcp/model-proxy-mcp/src/server/http.ts:41`
20
+ - Gateway service: `packages/mcp/model-proxy-mcp/src/services/GatewayService.ts:118`
21
+
22
+ ## Commands
23
+
24
+ ### Start both HTTP and MCP services
25
+
26
+ ```bash
27
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts start
28
+ ```
29
+
30
+ Options from `packages/mcp/model-proxy-mcp/src/commands/start.ts:7`:
31
+
32
+ - `--mcp-only`
33
+ - `--http-only`
34
+ - `-p, --port <port>`
35
+
36
+ ### Start only the HTTP proxy
37
+
38
+ ```bash
39
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts http-serve
40
+ ```
41
+
42
+ Default port is `43191` from `packages/mcp/model-proxy-mcp/src/constants/defaults.ts:11`.
43
+
44
+ ### Start only the MCP server
45
+
46
+ ```bash
47
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts mcp-serve
48
+ ```
49
+
50
+ Options from `packages/mcp/model-proxy-mcp/src/commands/mcp-serve.ts:10`:
51
+
52
+ - `--cleanup`
53
+ - `-p, --port <port>`
54
+
55
+ ### Show status
56
+
57
+ ```bash
58
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts status
59
+ ```
60
+
61
+ Optional scope:
62
+
63
+ ```bash
64
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts status --scope my-scope
65
+ ```
66
+
67
+ ### Stop the background HTTP server
68
+
69
+ ```bash
70
+ pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts stop
71
+ ```
72
+
73
+ ## Launch Claude Code through the proxy
74
+
75
+ The `claude` command seeds scope config, ensures the HTTP proxy is running, sets Claude model env vars, and launches Claude Code against:
76
+
77
+ ```text
78
+ http://127.0.0.1:<port>/scopes/<scope>
79
+ ```
80
+
81
+ See `packages/mcp/model-proxy-mcp/src/commands/claude.ts:75` and `packages/mcp/model-proxy-mcp/src/commands/claude.ts:176`.
82
+
83
+ Example:
84
+
85
+ ```bash
86
+ env -u CLAUDECODE pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts \
87
+ claude --scope demo --clear-session -- \
88
+ -p "hi, how are you doing?"
89
+ ```
90
+
91
+ Why `env -u CLAUDECODE`? Claude Code blocks nested sessions when launched from inside another Claude Code session.
92
+
93
+ Supported wrapper options from `packages/mcp/model-proxy-mcp/src/commands/claude.ts:233`:
94
+
95
+ - `-s, --scope <scope>`
96
+ - `-p, --port <port>`
97
+ - `-c, --config-file <path>`
98
+ - `--config <path>`
99
+ - `--clear-session`
100
+
101
+ All remaining args are forwarded directly to the upstream `claude` CLI via `claudeArgs` in `packages/mcp/model-proxy-mcp/src/commands/claude.ts:196`.
102
+
103
+ ## Headless and streaming usage
104
+
105
+ ### One-shot headless response
106
+
107
+ ```bash
108
+ env -u CLAUDECODE pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts \
109
+ claude --scope test-headless --clear-session -- \
110
+ -p "hi, how are you doing?"
111
+ ```
112
+
113
+ ### Stream JSON output
114
+
115
+ ```bash
116
+ env -u CLAUDECODE pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts \
117
+ claude --scope test-headless --clear-session -- \
118
+ -p --output-format stream-json --include-partial-messages \
119
+ "hi, how are you doing?"
120
+ ```
121
+
122
+ ### Stream JSON input and output
123
+
124
+ ```bash
125
+ env -u CLAUDECODE pnpm exec tsx packages/mcp/model-proxy-mcp/src/cli.ts \
126
+ claude --scope test-headless --clear-session -- \
127
+ -p --input-format stream-json --output-format stream-json --include-partial-messages
128
+ ```
129
+
130
+ ## HTTP API
131
+
132
+ HTTP routes are defined in `packages/mcp/model-proxy-mcp/src/server/http.ts:45`.
133
+
134
+ Core routes:
135
+
136
+ - `GET /health`
137
+ - `GET /status`
138
+ - `GET /v1/models`
139
+ - `POST /v1/messages`
140
+ - `GET /scopes/:scope/status`
141
+ - `GET /scopes/:scope/v1/models`
142
+ - `POST /scopes/:scope/v1/messages`
143
+
144
+ Admin routes:
145
+
146
+ - `GET /admin`
147
+ - `GET /admin/scopes`
148
+ - `GET /admin/config?scope=<scope>`
149
+ - `GET /admin/profiles?scope=<scope>`
150
+ - `GET /admin/current-model?scope=<scope>&slot=<slot>`
151
+ - `GET /admin/history?scope=<scope>&limit=<n>&cursor=<cursor>`
152
+ - `GET /admin/history/stats?scope=<scope>`
153
+ - `PUT /admin/profiles/:id?scope=<scope>`
154
+ - `PUT /admin/active-profile?scope=<scope>`
155
+ - `PUT /admin/current-model?scope=<scope>`
156
+ - `PUT /admin/config?scope=<scope>`
157
+ - `DELETE /admin/history?scope=<scope>`
158
+
159
+ ## Configuration
160
+
161
+ Default config locations come from `packages/mcp/model-proxy-mcp/src/constants/defaults.ts:5`:
162
+
163
+ - Settings dir: `~/.model-proxy`
164
+ - Provider config: `~/.model-proxy/model-provider.yaml`
165
+ - Model list: `~/.model-proxy/model-list.yaml`
166
+ - Scope settings dir: `~/.model-proxy/scopes`
167
+ - History DB: `~/.model-proxy/history.sqlite`
168
+ - Codex auth file: `~/.codex/auth.json`
169
+
170
+ Environment overrides used by `packages/mcp/model-proxy-mcp/src/services/ProfileStore.ts:107` and `packages/mcp/model-proxy-mcp/src/services/GatewayService.ts:47`:
171
+
172
+ - `MODEL_PROXY_MCP_PROVIDER_PATH`
173
+ - `MODEL_PROXY_MCP_MODEL_LIST_PATH`
174
+ - `MODEL_PROXY_MCP_SCOPE_DIR`
175
+ - `ANTHROPIC_AUTH_TOKEN`
176
+ - `MODEL_PROXY_MCP_UPSTREAM_AUTH_TOKEN`
177
+ - `MODEL_PROXY_MCP_UPSTREAM_AUTH_ENV`
178
+ - `MODEL_PROXY_MCP_UPSTREAM_TIMEOUT_MS`
179
+ - `API_TIMEOUT_MS`
180
+
181
+ The Claude wrapper also sets these model aliases in the child Claude process at `packages/mcp/model-proxy-mcp/src/commands/claude.ts:80`:
182
+
183
+ - `ANTHROPIC_DEFAULT_OPUS_MODEL=ccproxy-opus`
184
+ - `ANTHROPIC_DEFAULT_SONNET_MODEL=ccproxy-sonnet`
185
+ - `ANTHROPIC_DEFAULT_HAIKU_MODEL=ccproxy-haiku`
186
+ - `CLAUDE_CODE_SUBAGENT_MODEL=ccproxy-subagent`
187
+
188
+ ## Upstream providers
189
+
190
+ The default provider registry includes:
191
+
192
+ - `chatgpt-codex`
193
+ - `zai-anthropic-compat`
194
+
195
+ See `packages/mcp/model-proxy-mcp/src/constants/defaults.ts:15`.
196
+
197
+ The gateway resolves Claude model aliases like `ccproxy-opus` and routes them to the configured scope slot in `packages/mcp/model-proxy-mcp/src/services/GatewayService.ts:31`.
198
+
199
+ ## Authentication
200
+
201
+ ChatGPT Codex auth is loaded from `~/.codex/auth.json` by `packages/mcp/model-proxy-mcp/src/adapters/codex/CodexAuth.ts:25`.
202
+
203
+ Behavior:
204
+
205
+ - Reads `access_token`, `refresh_token`, and `account_id`
206
+ - Refreshes expired access tokens through OpenAI OAuth
207
+ - Persists refreshed tokens back to the auth file
208
+
209
+ ## Development
210
+
211
+ Install dependencies from the monorepo root:
212
+
213
+ ```bash
214
+ pnpm install
215
+ ```
216
+
217
+ Build:
218
+
219
+ ```bash
220
+ nx build model-proxy-mcp
221
+ ```
222
+
223
+ Test:
224
+
225
+ ```bash
226
+ nx test model-proxy-mcp
227
+ ```
228
+
229
+ Typecheck:
230
+
231
+ ```bash
232
+ nx typecheck model-proxy-mcp
233
+ ```
234
+
235
+ Direct package scripts from `packages/mcp/model-proxy-mcp/package.json:22`:
236
+
237
+ ```bash
238
+ pnpm --dir packages/mcp/model-proxy-mcp run build
239
+ pnpm --dir packages/mcp/model-proxy-mcp run test
240
+ pnpm --dir packages/mcp/model-proxy-mcp run typecheck
241
+ ```
242
+
243
+ ## Current test coverage in repo
244
+
245
+ Existing tests include:
246
+
247
+ - `packages/mcp/model-proxy-mcp/tests/commands/claude.test.ts:12`
248
+ - `packages/mcp/model-proxy-mcp/tests/server/http.test.ts:1`
249
+ - `packages/mcp/model-proxy-mcp/tests/services/GatewayService.test.ts:1`
250
+ - `packages/mcp/model-proxy-mcp/tests/services/ProfileStore.test.ts:1`
251
+ - `packages/mcp/model-proxy-mcp/tests/services/ConversationHistoryService.test.ts:1`
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };