@deotio/mcp-sigv4-proxy 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.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Deotio
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @deotio/mcp-sigv4-proxy
2
+
3
+ A stdio MCP proxy that signs requests with AWS SigV4 using the standard credential chain. Drop it into your `.mcp.json` as a `command` entry to connect Claude Code (or any MCP client) to IAM-authenticated MCP servers like AWS Bedrock AgentCore — with per-profile auth via `AWS_PROFILE`.
4
+
5
+ ## Quick start
6
+
7
+ Add to your `.mcp.json`:
8
+
9
+ ```json
10
+ "finops": {
11
+ "command": "npx",
12
+ "args": ["-y", "@deotio/mcp-sigv4-proxy"],
13
+ "env": {
14
+ "AWS_PROFILE": "dot-finops",
15
+ "AWS_REGION": "us-east-1",
16
+ "MCP_SERVER_URL": "https://bedrock-agentcore.us-east-1.amazonaws.com/runtimes/.../invocations?qualifier=DEFAULT"
17
+ }
18
+ }
19
+ ```
20
+
21
+ ## How it works
22
+
23
+ ```
24
+ stdin (JSON-RPC) -> validate -> SigV4 sign -> HTTPS POST -> response relay -> stdout
25
+ ```
26
+
27
+ 1. Reads JSON-RPC messages from stdin (one per line)
28
+ 2. Validates each message is well-formed JSON-RPC 2.0
29
+ 3. Signs the request with AWS SigV4 using the configured credentials
30
+ 4. Forwards to the target MCP endpoint via HTTPS
31
+ 5. Relays the response (JSON or SSE stream) back to stdout
32
+
33
+ ## Environment variables
34
+
35
+ | Variable | Required | Default | Description |
36
+ |---|---|---|---|
37
+ | `MCP_SERVER_URL` | yes | — | Full HTTPS URL of the target MCP HTTP endpoint |
38
+ | `AWS_PROFILE` | no | SDK default chain | AWS named profile for signing |
39
+ | `AWS_REGION` | no | `us-east-1` | AWS region for SigV4 signing |
40
+ | `AWS_SERVICE` | no | `bedrock-agentcore` | SigV4 service name |
41
+
42
+ ## Prerequisites
43
+
44
+ Your AWS profile needs the appropriate IAM permissions for the target service. For Bedrock AgentCore:
45
+
46
+ ```
47
+ bedrock-agentcore:InvokeAgentRuntime
48
+ ```
49
+
50
+ ## Security
51
+
52
+ - **HTTPS-only** — `MCP_SERVER_URL` must use `https://`. Other schemes (`http://`, `file://`, `ftp://`) are rejected at startup to prevent SSRF.
53
+ - **TLS enforcement** — the proxy refuses to start if `NODE_TLS_REJECT_UNAUTHORIZED=0` is set, since it sends signed AWS credentials.
54
+ - **Input validation** — only well-formed JSON-RPC 2.0 messages are signed and forwarded.
55
+ - **Sanitized errors** — HTTP error bodies from the upstream are logged to stderr, not forwarded to the MCP client. Only the status code is relayed.
56
+ - **Buffer limits** — SSE streams are capped at 1 MB to prevent unbounded memory growth.
57
+
58
+ ## License
59
+
60
+ Apache-2.0
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { startProxy } from './proxy.js';
3
+ startProxy();
package/dist/proxy.js ADDED
@@ -0,0 +1,175 @@
1
+ import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
2
+ import { SignatureV4 } from '@smithy/signature-v4';
3
+ import { HttpRequest } from '@smithy/protocol-http';
4
+ import { Sha256 } from '@aws-crypto/sha256-js';
5
+ import readline from 'readline';
6
+ export const MAX_SSE_BUFFER_BYTES = 1_048_576; // 1 MB
7
+ export function validateEnv() {
8
+ if (!process.env.MCP_SERVER_URL) {
9
+ process.stderr.write('mcp-sigv4-proxy: MCP_SERVER_URL is required\n');
10
+ process.exit(1);
11
+ }
12
+ if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
13
+ process.stderr.write('mcp-sigv4-proxy: NODE_TLS_REJECT_UNAUTHORIZED=0 is not allowed — ' +
14
+ 'this proxy sends signed AWS credentials and requires verified TLS\n');
15
+ process.exit(1);
16
+ }
17
+ const url = new URL(process.env.MCP_SERVER_URL);
18
+ if (url.protocol !== 'https:') {
19
+ process.stderr.write(`mcp-sigv4-proxy: MCP_SERVER_URL must use https:// (got ${url.protocol})\n`);
20
+ process.exit(1);
21
+ }
22
+ return {
23
+ url,
24
+ region: process.env.AWS_REGION ?? 'us-east-1',
25
+ service: process.env.AWS_SERVICE ?? 'bedrock-agentcore',
26
+ };
27
+ }
28
+ export function createSigner(config) {
29
+ return new SignatureV4({
30
+ credentials: fromNodeProviderChain(),
31
+ region: config.region,
32
+ service: config.service,
33
+ sha256: Sha256,
34
+ });
35
+ }
36
+ export function parseInputLine(line) {
37
+ const body = line.trim();
38
+ if (!body)
39
+ return null;
40
+ let parsed;
41
+ try {
42
+ parsed = JSON.parse(body);
43
+ }
44
+ catch {
45
+ process.stderr.write('mcp-sigv4-proxy: ignoring non-JSON input line\n');
46
+ return null;
47
+ }
48
+ if (typeof parsed !== 'object' ||
49
+ parsed === null ||
50
+ parsed.jsonrpc !== '2.0') {
51
+ process.stderr.write('mcp-sigv4-proxy: ignoring non-JSON-RPC message\n');
52
+ return null;
53
+ }
54
+ const requestId = parsed.id ?? null;
55
+ return { body, requestId };
56
+ }
57
+ export function buildHttpRequest(url, body) {
58
+ return new HttpRequest({
59
+ method: 'POST',
60
+ hostname: url.hostname,
61
+ path: url.pathname + url.search,
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ 'Content-Length': String(Buffer.byteLength(body)),
65
+ host: url.hostname,
66
+ },
67
+ body,
68
+ });
69
+ }
70
+ export async function handleResponse(response, requestId) {
71
+ if (!response.ok) {
72
+ const text = await response.text();
73
+ process.stderr.write(`mcp-sigv4-proxy: HTTP ${response.status}: ${text}\n`);
74
+ process.stdout.write(JSON.stringify({
75
+ jsonrpc: '2.0',
76
+ id: requestId,
77
+ error: { code: -32000, message: `HTTP ${response.status}` },
78
+ }) + '\n');
79
+ return;
80
+ }
81
+ const ct = response.headers.get('content-type') ?? '';
82
+ if (ct.includes('text/event-stream')) {
83
+ const reader = response.body.getReader();
84
+ const decoder = new TextDecoder();
85
+ let buffer = '';
86
+ // eslint-disable-next-line no-constant-condition
87
+ while (true) {
88
+ const { done, value } = await reader.read();
89
+ if (done)
90
+ break;
91
+ buffer += decoder.decode(value, { stream: true });
92
+ if (Buffer.byteLength(buffer) > MAX_SSE_BUFFER_BYTES) {
93
+ process.stderr.write('mcp-sigv4-proxy: SSE buffer exceeded 1 MB limit, aborting stream\n');
94
+ reader.cancel();
95
+ process.stdout.write(JSON.stringify({
96
+ jsonrpc: '2.0',
97
+ id: requestId,
98
+ error: { code: -32000, message: 'SSE stream exceeded buffer limit' },
99
+ }) + '\n');
100
+ break;
101
+ }
102
+ const lines = buffer.split('\n');
103
+ buffer = lines.pop();
104
+ for (const line of lines) {
105
+ if (line.startsWith('data: ')) {
106
+ const data = line.slice(6).trim();
107
+ try {
108
+ JSON.parse(data);
109
+ process.stdout.write(data + '\n');
110
+ }
111
+ catch {
112
+ process.stderr.write(`mcp-sigv4-proxy: dropping non-JSON SSE data: ${data.slice(0, 100)}\n`);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ else {
119
+ const text = await response.text();
120
+ const trimmed = text.trim();
121
+ try {
122
+ JSON.parse(trimmed);
123
+ process.stdout.write(trimmed + '\n');
124
+ }
125
+ catch {
126
+ process.stderr.write(`mcp-sigv4-proxy: dropping non-JSON response body: ${trimmed.slice(0, 100)}\n`);
127
+ }
128
+ }
129
+ }
130
+ export async function processLine(line, url, signer) {
131
+ const input = parseInputLine(line);
132
+ if (!input)
133
+ return;
134
+ const { body, requestId } = input;
135
+ const request = buildHttpRequest(url, body);
136
+ try {
137
+ const signed = await signer.sign(request);
138
+ const response = await fetch(url.toString(), {
139
+ method: 'POST',
140
+ headers: signed.headers,
141
+ body,
142
+ });
143
+ await handleResponse(response, requestId);
144
+ }
145
+ catch (err) {
146
+ process.stderr.write(`mcp-sigv4-proxy: request failed: ${err}\n`);
147
+ process.stdout.write(JSON.stringify({
148
+ jsonrpc: '2.0',
149
+ id: requestId,
150
+ error: { code: -32000, message: 'Proxy request failed' },
151
+ }) + '\n');
152
+ }
153
+ }
154
+ export function startProxy() {
155
+ const config = validateEnv();
156
+ const signer = createSigner(config);
157
+ const rl = readline.createInterface({ input: process.stdin, terminal: false });
158
+ let pending = Promise.resolve();
159
+ rl.on('line', (line) => {
160
+ pending = pending.then(() => processLine(line, config.url, signer)).catch(() => { });
161
+ });
162
+ rl.on('close', async () => {
163
+ process.stderr.write('mcp-sigv4-proxy: stdin closed, draining in-flight requests\n');
164
+ await pending;
165
+ process.exit(0);
166
+ });
167
+ process.on('SIGTERM', () => {
168
+ process.stderr.write('mcp-sigv4-proxy: received SIGTERM, shutting down\n');
169
+ rl.close();
170
+ });
171
+ process.on('SIGINT', () => {
172
+ process.stderr.write('mcp-sigv4-proxy: received SIGINT, shutting down\n');
173
+ rl.close();
174
+ });
175
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@deotio/mcp-sigv4-proxy",
3
+ "version": "0.1.0",
4
+ "description": "stdio MCP proxy with AWS SigV4 signing — connect Claude Code to any IAM-authenticated MCP server using a named AWS profile",
5
+ "type": "module",
6
+ "bin": {
7
+ "mcp-sigv4-proxy": "dist/index.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc && node -e \"const fs=require('fs');const f='dist/index.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f));\"",
15
+ "test": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
16
+ "lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
17
+ "prepublishOnly": "npm run build && npm test"
18
+ },
19
+ "dependencies": {
20
+ "@aws-sdk/credential-providers": "^3.0.0",
21
+ "@aws-crypto/sha256-js": "^5.0.0",
22
+ "@smithy/protocol-http": "^4.0.0",
23
+ "@smithy/signature-v4": "^4.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/jest": "^29.0.0",
27
+ "@types/node": "^22.0.0",
28
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
29
+ "@typescript-eslint/parser": "^7.0.0",
30
+ "eslint": "^8.0.0",
31
+ "jest": "^29.0.0",
32
+ "prettier": "^3.0.0",
33
+ "ts-jest": "^29.0.0",
34
+ "typescript": "^5.0.0"
35
+ },
36
+ "keywords": [
37
+ "mcp",
38
+ "model-context-protocol",
39
+ "aws",
40
+ "sigv4",
41
+ "agentcore",
42
+ "bedrock",
43
+ "proxy",
44
+ "iam",
45
+ "authentication"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "engines": {
51
+ "node": ">=20"
52
+ },
53
+ "license": "Apache-2.0",
54
+ "homepage": "https://github.com/deotio/mcp-sigv4-proxy#readme",
55
+ "bugs": {
56
+ "url": "https://github.com/deotio/mcp-sigv4-proxy/issues"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/deotio/mcp-sigv4-proxy.git"
61
+ }
62
+ }