@deotio/mcp-sigv4-proxy 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/README.md +2 -1
- package/dist/proxy.js +29 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,12 +14,13 @@ Add to your `.mcp.json`:
|
|
|
14
14
|
"args": ["-y", "@deotio/mcp-sigv4-proxy"],
|
|
15
15
|
"env": {
|
|
16
16
|
"AWS_PROFILE": "dot-finops",
|
|
17
|
+
"AWS_REGION": "us-east-1",
|
|
17
18
|
"MCP_SERVER_URL": "https://bedrock-agentcore.us-east-1.amazonaws.com/runtimes/.../invocations?qualifier=DEFAULT"
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Always set `AWS_REGION` explicitly — the proxy can infer it from standard AWS hostnames, but `AWS_REGION` from your shell environment takes precedence and may point to a different region. `AWS_SERVICE` is inferred automatically and only needs to be set for non-standard endpoints.
|
|
23
24
|
|
|
24
25
|
## How it works
|
|
25
26
|
|
package/dist/proxy.js
CHANGED
|
@@ -5,8 +5,9 @@ import { Sha256 } from '@aws-crypto/sha256-js';
|
|
|
5
5
|
import readline from 'readline';
|
|
6
6
|
export const MAX_SSE_BUFFER_BYTES = 1_048_576; // 1 MB
|
|
7
7
|
const DEFAULT_TIMEOUT_MS = 180_000; // 180s, matches AWS proxy
|
|
8
|
-
const DEFAULT_RETRIES =
|
|
8
|
+
const DEFAULT_RETRIES = 2;
|
|
9
9
|
const RETRY_BASE_MS = 1000;
|
|
10
|
+
const COLD_START_RETRY_MS = 5000;
|
|
10
11
|
const LOG_LEVEL_ORDER = {
|
|
11
12
|
DEBUG: 0,
|
|
12
13
|
INFO: 1,
|
|
@@ -112,10 +113,15 @@ export function parseInputLine(line) {
|
|
|
112
113
|
}
|
|
113
114
|
// --- Request building ---
|
|
114
115
|
export function buildHttpRequest(url, body) {
|
|
116
|
+
const query = {};
|
|
117
|
+
url.searchParams.forEach((value, key) => {
|
|
118
|
+
query[key] = value;
|
|
119
|
+
});
|
|
115
120
|
return new HttpRequest({
|
|
116
121
|
method: 'POST',
|
|
117
122
|
hostname: url.hostname,
|
|
118
|
-
path: url.pathname
|
|
123
|
+
path: url.pathname,
|
|
124
|
+
...(Object.keys(query).length > 0 && { query }),
|
|
119
125
|
headers: {
|
|
120
126
|
'Content-Type': 'application/json',
|
|
121
127
|
'Content-Length': String(Buffer.byteLength(body)),
|
|
@@ -140,10 +146,14 @@ async function fetchWithRetry(url, init, timeoutMs, retries) {
|
|
|
140
146
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
141
147
|
try {
|
|
142
148
|
const response = await fetchWithTimeout(url, init, timeoutMs);
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
// Retry on 5xx server errors and 424 (AgentCore cold-start timeout)
|
|
150
|
+
const retryable = response.status >= 500 || response.status === 424;
|
|
151
|
+
if (retryable && attempt < retries) {
|
|
152
|
+
const delay = response.status === 424
|
|
153
|
+
? COLD_START_RETRY_MS * Math.pow(2, attempt)
|
|
154
|
+
: RETRY_BASE_MS * Math.pow(2, attempt);
|
|
155
|
+
log('WARNING', `HTTP ${response.status}, retrying in ${delay}ms (${attempt + 1}/${retries})`);
|
|
156
|
+
await sleep(delay);
|
|
147
157
|
continue;
|
|
148
158
|
}
|
|
149
159
|
return response;
|
|
@@ -167,10 +177,22 @@ export async function handleResponse(response, requestId) {
|
|
|
167
177
|
if (!response.ok) {
|
|
168
178
|
const text = await response.text();
|
|
169
179
|
log('ERROR', `HTTP ${response.status}: ${text}`);
|
|
180
|
+
// Extract the upstream message for the JSON-RPC error (if JSON, use .message; otherwise trim)
|
|
181
|
+
let detail = '';
|
|
182
|
+
try {
|
|
183
|
+
const parsed = JSON.parse(text);
|
|
184
|
+
if (typeof parsed.message === 'string')
|
|
185
|
+
detail = `: ${parsed.message}`;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
const trimmed = text.trim();
|
|
189
|
+
if (trimmed.length > 0 && trimmed.length <= 200)
|
|
190
|
+
detail = `: ${trimmed}`;
|
|
191
|
+
}
|
|
170
192
|
process.stdout.write(JSON.stringify({
|
|
171
193
|
jsonrpc: '2.0',
|
|
172
194
|
id: requestId,
|
|
173
|
-
error: { code: -32000, message: `HTTP ${response.status}` },
|
|
195
|
+
error: { code: -32000, message: `HTTP ${response.status}${detail}` },
|
|
174
196
|
}) + '\n');
|
|
175
197
|
return;
|
|
176
198
|
}
|
package/package.json
CHANGED