@monoes/mcp 1.0.1 → 1.0.3
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 +191 -0
- package/README.md +36 -7
- package/dist/auth.d.ts +19 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +72 -0
- package/dist/auth.js.map +1 -0
- package/dist/connection-pool.d.ts +0 -0
- package/dist/connection-pool.d.ts.map +0 -0
- package/dist/connection-pool.js +0 -0
- package/dist/connection-pool.js.map +0 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +21 -7
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +21 -24
- package/dist/oauth.js.map +1 -1
- package/dist/prompt-registry.d.ts +0 -0
- package/dist/prompt-registry.d.ts.map +0 -0
- package/dist/prompt-registry.js +0 -0
- package/dist/prompt-registry.js.map +0 -0
- package/dist/rate-limiter.d.ts +0 -0
- package/dist/rate-limiter.d.ts.map +0 -0
- package/dist/rate-limiter.js +0 -0
- package/dist/rate-limiter.js.map +0 -0
- package/dist/resource-registry.d.ts +0 -0
- package/dist/resource-registry.d.ts.map +0 -0
- package/dist/resource-registry.js +0 -0
- package/dist/resource-registry.js.map +0 -0
- package/dist/sampling.d.ts +0 -0
- package/dist/sampling.d.ts.map +0 -0
- package/dist/sampling.js +0 -0
- package/dist/sampling.js.map +0 -0
- package/dist/schema-validator.d.ts +0 -0
- package/dist/schema-validator.d.ts.map +0 -0
- package/dist/schema-validator.js +0 -0
- package/dist/schema-validator.js.map +0 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +241 -38
- package/dist/server.js.map +1 -1
- package/dist/session-manager.d.ts +0 -0
- package/dist/session-manager.d.ts.map +0 -0
- package/dist/session-manager.js +0 -0
- package/dist/session-manager.js.map +0 -0
- package/dist/task-manager.d.ts +0 -0
- package/dist/task-manager.d.ts.map +0 -0
- package/dist/task-manager.js +0 -0
- package/dist/task-manager.js.map +0 -0
- package/dist/tool-registry.d.ts +0 -0
- package/dist/tool-registry.d.ts.map +0 -0
- package/dist/tool-registry.js +0 -0
- package/dist/tool-registry.js.map +0 -0
- package/dist/transport/http.d.ts +16 -5
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +81 -72
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/index.d.ts +0 -0
- package/dist/transport/index.d.ts.map +0 -0
- package/dist/transport/index.js +0 -0
- package/dist/transport/index.js.map +0 -0
- package/dist/transport/stdio.d.ts +0 -0
- package/dist/transport/stdio.d.ts.map +0 -0
- package/dist/transport/stdio.js +0 -0
- package/dist/transport/stdio.js.map +0 -0
- package/dist/transport/websocket.d.ts +14 -13
- package/dist/transport/websocket.d.ts.map +1 -1
- package/dist/transport/websocket.js +36 -37
- package/dist/transport/websocket.js.map +1 -1
- package/dist/types.d.ts +16 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -0
- package/dist/types.js.map +1 -1
- package/package.json +8 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
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
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on
|
|
53
|
+
behalf of the copyright owner. For the purposes of this definition,
|
|
54
|
+
"submitted" means any form of electronic, verbal, or written
|
|
55
|
+
communication sent to the Licensor or its representatives, including
|
|
56
|
+
but not limited to communication on electronic mailing lists, source
|
|
57
|
+
code control systems, and issue tracking systems that are managed by,
|
|
58
|
+
or on behalf of, the Licensor for the purpose of discussing and
|
|
59
|
+
improving the Work, but excluding communication that is conspicuously
|
|
60
|
+
marked or otherwise designated in writing by the copyright owner as
|
|
61
|
+
"Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 monoes
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/monoes/monomind/main/assets/packages/mcp.png" alt="@monoes/mcp" width="600" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# @monoes/mcp
|
|
2
6
|
|
|
3
7
|
[](https://www.npmjs.com/package/@monoes/mcp)
|
|
4
8
|
[](https://github.com/monoes/monomind/blob/main/LICENSE)
|
|
5
9
|
[](https://nodejs.org)
|
|
6
10
|
|
|
7
|
-
**Standalone MCP server** — stdio, HTTP, and WebSocket transports with tool registry, resources, prompts, sessions, and connection pooling. Zero `@monomind/*` dependencies.
|
|
11
|
+
**Standalone MCP server engine** — Version `1.0.1`. Supports stdio, HTTP, and WebSocket transports with tool registry, resources, prompts, sessions, rate limiting, and connection pooling. Zero `@monomind/*` dependencies.
|
|
8
12
|
|
|
9
13
|
> Part of the [Monomind](https://github.com/monoes/monomind) ecosystem.
|
|
10
14
|
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Package Architecture & Versioning
|
|
18
|
+
|
|
19
|
+
The Monomind MCP Subsystem is split across two core packages:
|
|
20
|
+
|
|
21
|
+
1. **`@monoes/mcp` (`v1.0.1`)** (*This package*): Standalone MCP protocol engine powering stdio, HTTP (Express/Cors/Helmet), and WebSocket (`ws`) transports, connection pooling, prompt/resource registries, rate limiting, and session lifecycle management.
|
|
22
|
+
2. **`@monoes/monomindcli` (`v2.9.0`)**: Implements CLI integration, binary entry points (`monomind-mcp`), MCP server manager, MCP client loader, and 30+ domain tool modules (`src/mcp-tools/`).
|
|
23
|
+
|
|
24
|
+
- **Protocol Version**: Returns `protocolVersion: '2024-11-05'` per standard MCP specification release ([`packages/@monomind/cli/src/mcp-server.ts:532`](packages/@monomind/cli/src/mcp-server.ts#L532) & [`packages/@monomind/mcp/src/server.ts:91`](packages/@monomind/mcp/src/server.ts#L91)).
|
|
25
|
+
- **Server Identity Version Drift**: The binary `monomind-mcp` hardcodes server identity `VERSION = '3.0.0'` in its JSON-RPC `initialize` response (`serverInfo: { name: 'monomind', version: '3.0.0' }` at [`packages/@monomind/cli/bin/mcp-server.js:13`](packages/@monomind/cli/bin/mcp-server.js#L13)), decoupled from package versioning (`v2.9.0`).
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Server Entry Points
|
|
30
|
+
|
|
31
|
+
| Entry Point / Module | Location | Description & Role |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| **`bin/mcp-server.js`** | `packages/@monomind/cli/bin/mcp-server.js` | Direct stdio MCP server binary (`monomind-mcp`). Reads lines from `process.stdin` and handles JSON-RPC calls (`initialize`, `tools/list`, `tools/call`, `ping`, `notifications/initialized`) with hardcoded version `3.0.0` protocol handshake behavior for direct Claude Code integration. |
|
|
34
|
+
| **`commands/mcp.ts`** | `packages/@monomind/cli/src/commands/mcp.ts` | User-facing CLI command handler for `monomind mcp` subcommands (`start`, `stop`, `status`, `list`, `call`, `toggle`, `health`, `logs`, `metrics`, `test`). |
|
|
35
|
+
| **`mcp-server.ts`** | `packages/@monomind/cli/src/mcp-server.ts` | Implements `MCPServerManager` class managing server process lifecycle, PID file management (`~/.monomind/mcp-server.pid`), background daemonization, and health monitoring. |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
11
39
|
## Install
|
|
12
40
|
|
|
13
41
|
```bash
|
|
@@ -36,7 +64,7 @@ await server.start();
|
|
|
36
64
|
|
|
37
65
|
## Transports
|
|
38
66
|
|
|
39
|
-
> **Note:**
|
|
67
|
+
> **Note:** Monomind's `monomind-mcp` binary uses direct stdio transport (`bin/mcp-server.js`) for minimal latency with Claude Code. The `@monoes/mcp` package provides full transport modularity (stdio, HTTP, WebSocket) for custom or standalone integrations.
|
|
40
68
|
|
|
41
69
|
```typescript
|
|
42
70
|
import { createMCPServer } from '@monoes/mcp';
|
|
@@ -70,13 +98,13 @@ import { createToolRegistry, defineTool } from '@monoes/mcp';
|
|
|
70
98
|
const registry = createToolRegistry(logger);
|
|
71
99
|
|
|
72
100
|
registry.register({
|
|
73
|
-
name: '
|
|
74
|
-
description: '
|
|
75
|
-
inputSchema: { type: 'object', properties: {
|
|
76
|
-
handler: async ({
|
|
101
|
+
name: 'add',
|
|
102
|
+
description: 'Add two numbers',
|
|
103
|
+
inputSchema: { type: 'object', properties: { a: { type: 'number' }, b: { type: 'number' } }, required: ['a', 'b'] },
|
|
104
|
+
handler: async ({ a, b }) => ({ result: a + b }),
|
|
77
105
|
});
|
|
78
106
|
|
|
79
|
-
const result = await registry.execute('
|
|
107
|
+
const result = await registry.execute('add', { a: 2, b: 2 });
|
|
80
108
|
```
|
|
81
109
|
|
|
82
110
|
## Resources & prompts
|
|
@@ -127,3 +155,4 @@ interface IMCPServer {
|
|
|
127
155
|
## License
|
|
128
156
|
|
|
129
157
|
MIT
|
|
158
|
+
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AuthConfig } from './types.js';
|
|
2
|
+
export interface AuthInfo {
|
|
3
|
+
method: 'token' | 'api-key';
|
|
4
|
+
credentialIndex: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AuthValidationResult {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
error?: string;
|
|
9
|
+
authInfo?: AuthInfo;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SECURITY: Timing-safe token comparison to prevent timing attacks.
|
|
13
|
+
* Mismatched lengths still run a constant-time compare (against itself)
|
|
14
|
+
* before returning false, so length differences aren't observable via timing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function timingSafeCompare(a: string, b: string): boolean;
|
|
17
|
+
export declare function validateCredential(authConfig: AuthConfig, authorizationHeader: string | undefined, apiKeyHeader: string | undefined): AuthValidationResult;
|
|
18
|
+
export declare function authMiddleware(authConfig: AuthConfig): (req: any, res: any, next: () => void) => void;
|
|
19
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAU/D;AAoBD,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS,EACvC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,oBAAoB,CA8BtB;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,SACtC,GAAG,OAAO,GAAG,QAAQ,MAAM,IAAI,UAsB7C"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'crypto';
|
|
2
|
+
/**
|
|
3
|
+
* SECURITY: Timing-safe token comparison to prevent timing attacks.
|
|
4
|
+
* Mismatched lengths still run a constant-time compare (against itself)
|
|
5
|
+
* before returning false, so length differences aren't observable via timing.
|
|
6
|
+
*/
|
|
7
|
+
export function timingSafeCompare(a, b) {
|
|
8
|
+
const bufA = Buffer.from(a, 'utf-8');
|
|
9
|
+
const bufB = Buffer.from(b, 'utf-8');
|
|
10
|
+
if (bufA.length !== bufB.length) {
|
|
11
|
+
timingSafeEqual(bufA, bufA);
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return timingSafeEqual(bufA, bufB);
|
|
15
|
+
}
|
|
16
|
+
function matchCredential(supplied, configured, method) {
|
|
17
|
+
if (!configured || configured.length === 0) {
|
|
18
|
+
return { valid: false, error: `No ${method === 'token' ? 'tokens' : 'API keys'} configured for authentication` };
|
|
19
|
+
}
|
|
20
|
+
for (let i = 0; i < configured.length; i++) {
|
|
21
|
+
if (timingSafeCompare(supplied, configured[i])) {
|
|
22
|
+
return { valid: true, authInfo: { method, credentialIndex: i } };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { valid: false, error: method === 'token' ? 'Invalid token' : 'Invalid API key' };
|
|
26
|
+
}
|
|
27
|
+
export function validateCredential(authConfig, authorizationHeader, apiKeyHeader) {
|
|
28
|
+
if (!authConfig.enabled || authConfig.method === 'none') {
|
|
29
|
+
return { valid: true };
|
|
30
|
+
}
|
|
31
|
+
if (authConfig.method === 'token') {
|
|
32
|
+
if (!authorizationHeader) {
|
|
33
|
+
return { valid: false, error: 'Authorization header required' };
|
|
34
|
+
}
|
|
35
|
+
const tokenMatch = authorizationHeader.match(/^Bearer\s+(.+)$/i);
|
|
36
|
+
if (!tokenMatch) {
|
|
37
|
+
return { valid: false, error: 'Invalid authorization format' };
|
|
38
|
+
}
|
|
39
|
+
return matchCredential(tokenMatch[1], authConfig.tokens, 'token');
|
|
40
|
+
}
|
|
41
|
+
if (authConfig.method === 'api-key') {
|
|
42
|
+
const bearerMatch = authorizationHeader?.match(/^Bearer\s+(.+)$/i);
|
|
43
|
+
const credential = bearerMatch?.[1] ?? apiKeyHeader;
|
|
44
|
+
if (!credential) {
|
|
45
|
+
return { valid: false, error: 'API key required (Authorization: Bearer <key> or X-API-Key header)' };
|
|
46
|
+
}
|
|
47
|
+
return matchCredential(credential, authConfig.apiKeys, 'api-key');
|
|
48
|
+
}
|
|
49
|
+
if (authConfig.method === 'oauth') {
|
|
50
|
+
return { valid: false, error: 'OAuth inbound validation not implemented — use token or api-key method' };
|
|
51
|
+
}
|
|
52
|
+
return { valid: false, error: `Unsupported auth method: ${authConfig.method}` };
|
|
53
|
+
}
|
|
54
|
+
export function authMiddleware(authConfig) {
|
|
55
|
+
return (req, res, next) => {
|
|
56
|
+
const result = validateCredential(authConfig, req.headers?.authorization, req.headers?.['x-api-key']);
|
|
57
|
+
if (!result.valid) {
|
|
58
|
+
res.status(401).json({
|
|
59
|
+
jsonrpc: '2.0',
|
|
60
|
+
id: null,
|
|
61
|
+
error: {
|
|
62
|
+
code: -32001,
|
|
63
|
+
message: `Unauthorized - ${result.error}`,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
req.authInfo = result.authInfo;
|
|
69
|
+
next();
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources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AK,EAAE,wEAAwE,EAAE,CAAC;IAC3G,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,4BAA4B,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,UAAsB;IACnD,OAAO,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAgB,EAAE,EAAE;QAC9C,MAAM,MAAM,GAAG,kBAAkB,CAC/B,UAAU,EACV,GAAG,CAAC,OAAO,EAAE,aAAa,EAC1B,GAAG,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAC3B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,IAAI;gBACR,KAAK,EAAE;oBACL,IAAI,EAAE,CAAC,KAAK;oBACZ,OAAO,EAAE,kBAAkB,MAAM,CAAC,KAAK,EAAE;iBAC1C;aACF,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC/B,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
|
File without changes
|
|
File without changes
|
package/dist/connection-pool.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -36,8 +36,10 @@ export { RateLimiter, createRateLimiter, rateLimitMiddleware, } from './rate-lim
|
|
|
36
36
|
export type { RateLimitConfig, RateLimitResult } from './rate-limiter.js';
|
|
37
37
|
export { SamplingManager, createSamplingManager, createMockProvider, createAnthropicProvider, } from './sampling.js';
|
|
38
38
|
export type { LLMProvider, SamplingConfig, SamplingContext } from './sampling.js';
|
|
39
|
-
export { OAuthManager, createOAuthManager,
|
|
39
|
+
export { OAuthManager, createOAuthManager, InMemoryTokenStorage, createGitHubOAuthConfig, createGoogleOAuthConfig, } from './oauth.js';
|
|
40
40
|
export type { OAuthConfig, OAuthTokens, TokenStorage, AuthorizationRequest, } from './oauth.js';
|
|
41
|
+
export { authMiddleware, validateCredential, timingSafeCompare, } from './auth.js';
|
|
42
|
+
export type { AuthInfo, AuthValidationResult } from './auth.js';
|
|
41
43
|
export { createTransport, createInProcessTransport, TransportManager, createTransportManager, DEFAULT_TRANSPORT_CONFIGS, StdioTransport, HttpTransport, WebSocketTransport, } from './transport/index.js';
|
|
42
44
|
export type { TransportConfig, StdioTransportConfig, HttpTransportConfig, WebSocketTransportConfig, } from './transport/index.js';
|
|
43
45
|
import type { MCPServerConfig, ILogger } from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,YAAY,EACV,cAAc,EACd,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,OAAO,EAEP,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,YAA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,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGlF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,YAAY,EACV,cAAc,EACd,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,OAAO,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BAAmB,EACnB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAChC,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,SAAS,CAAC,CAsBpB;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,WAAW,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -38,8 +38,10 @@ export { validateSchema, formatValidationErrors, createValidator, } from './sche
|
|
|
38
38
|
export { RateLimiter, createRateLimiter, rateLimitMiddleware, } from './rate-limiter.js';
|
|
39
39
|
// Sampling (Server-initiated LLM)
|
|
40
40
|
export { SamplingManager, createSamplingManager, createMockProvider, createAnthropicProvider, } from './sampling.js';
|
|
41
|
-
// OAuth 2.1
|
|
42
|
-
export { OAuthManager, createOAuthManager,
|
|
41
|
+
// OAuth 2.1 (outbound client)
|
|
42
|
+
export { OAuthManager, createOAuthManager, InMemoryTokenStorage, createGitHubOAuthConfig, createGoogleOAuthConfig, } from './oauth.js';
|
|
43
|
+
// Inbound auth middleware
|
|
44
|
+
export { authMiddleware, validateCredential, timingSafeCompare, } from './auth.js';
|
|
43
45
|
// Transport layer
|
|
44
46
|
export { createTransport, createInProcessTransport, TransportManager, createTransportManager, DEFAULT_TRANSPORT_CONFIGS, StdioTransport, HttpTransport, WebSocketTransport, } from './transport/index.js';
|
|
45
47
|
/**
|
|
@@ -65,12 +67,23 @@ export { createTransport, createInProcessTransport, TransportManager, createTran
|
|
|
65
67
|
* ```
|
|
66
68
|
*/
|
|
67
69
|
export async function quickStart(config, logger) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
// With stdio transport, stdout is the JSON-RPC protocol channel — the
|
|
71
|
+
// default logger must write everything to stderr or it corrupts the wire
|
|
72
|
+
// (issue #94).
|
|
73
|
+
const isStdio = (config.transport ?? 'stdio') === 'stdio';
|
|
74
|
+
const defaultLogger = logger || (isStdio
|
|
75
|
+
? {
|
|
76
|
+
debug: (msg, data) => console.error(`[DEBUG] ${msg}`, data || ''),
|
|
77
|
+
info: (msg, data) => console.error(`[INFO] ${msg}`, data || ''),
|
|
78
|
+
warn: (msg, data) => console.error(`[WARN] ${msg}`, data || ''),
|
|
79
|
+
error: (msg, data) => console.error(`[ERROR] ${msg}`, data || ''),
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
debug: (msg, data) => console.debug(`[DEBUG] ${msg}`, data || ''),
|
|
83
|
+
info: (msg, data) => console.info(`[INFO] ${msg}`, data || ''),
|
|
84
|
+
warn: (msg, data) => console.warn(`[WARN] ${msg}`, data || ''),
|
|
85
|
+
error: (msg, data) => console.error(`[ERROR] ${msg}`, data || ''),
|
|
86
|
+
});
|
|
74
87
|
const server = createMCPServer(config, defaultLogger);
|
|
75
88
|
return server;
|
|
76
89
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAqFH,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExD,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;AAGtC,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAElF,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5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C;IAEP,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAEtD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC"}
|
package/dist/oauth.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monoes/mcp - OAuth 2.1
|
|
2
|
+
* @monoes/mcp - Outbound OAuth 2.1 client helper
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This module is an OUTBOUND OAuth 2.1 + PKCE client: it builds authorization
|
|
5
|
+
* URLs, exchanges codes for tokens, refreshes/revokes tokens, and stores them
|
|
6
|
+
* — for use when THIS server needs to call OUT to a third-party OAuth
|
|
7
|
+
* provider (e.g. a GitHub- or Google-backed tool). It does not validate
|
|
8
|
+
* incoming credentials and has no importers outside this file and its
|
|
9
|
+
* factories (createGitHubOAuthConfig/createGoogleOAuthConfig) — nothing here
|
|
10
|
+
* authenticates a caller of this MCP server.
|
|
11
|
+
*
|
|
12
|
+
* For INBOUND auth (verifying a request/connection reaching this server),
|
|
13
|
+
* see auth.ts's `validateCredential`/`authMiddleware`, wired into both
|
|
14
|
+
* transports (transport/http.ts, transport/websocket.ts). `validateCredential`
|
|
15
|
+
* currently supports `token` and `api-key` methods; an `oauth`-method
|
|
16
|
+
* AuthConfig explicitly rejects with "OAuth inbound validation not
|
|
17
|
+
* implemented" (auth.ts) rather than silently accepting requests — inbound
|
|
18
|
+
* OAuth (JWKS/introspection-based resource-server verification) is not
|
|
19
|
+
* implemented anywhere in this package.
|
|
5
20
|
*/
|
|
6
21
|
import { EventEmitter } from 'events';
|
|
7
22
|
import type { ILogger } from './types.js';
|
|
@@ -65,7 +80,10 @@ export declare class InMemoryTokenStorage implements TokenStorage {
|
|
|
65
80
|
delete(key: string): Promise<void>;
|
|
66
81
|
}
|
|
67
82
|
/**
|
|
68
|
-
* OAuth 2.1
|
|
83
|
+
* Outbound OAuth 2.1 client — drives the authorization-code + PKCE flow
|
|
84
|
+
* against a third-party provider on this server's behalf. Not a resource-
|
|
85
|
+
* server verifier; it never inspects an incoming request. See the module
|
|
86
|
+
* header for the inbound-auth pointer (auth.ts).
|
|
69
87
|
*/
|
|
70
88
|
export declare class OAuthManager extends EventEmitter {
|
|
71
89
|
private readonly logger;
|
|
@@ -131,10 +149,6 @@ export declare class OAuthManager extends EventEmitter {
|
|
|
131
149
|
* Create OAuth manager
|
|
132
150
|
*/
|
|
133
151
|
export declare function createOAuthManager(logger: ILogger, config: OAuthConfig): OAuthManager;
|
|
134
|
-
/**
|
|
135
|
-
* OAuth middleware for Express/Connect
|
|
136
|
-
*/
|
|
137
|
-
export declare function oauthMiddleware(oauthManager: OAuthManager, storageKey?: string): (req: any, res: any, next: () => void) => Promise<void>;
|
|
138
152
|
/**
|
|
139
153
|
* Create GitHub OAuth provider config
|
|
140
154
|
*/
|
package/dist/oauth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;I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W,GAAG,YAAY,CAErF;AAGD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,MAAM,EAAkB,GAC/B,WAAW,CAUb;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,MAAM,EAAmC,GAChD,WAAW,CAUb"}
|
package/dist/oauth.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monoes/mcp - OAuth 2.1
|
|
2
|
+
* @monoes/mcp - Outbound OAuth 2.1 client helper
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This module is an OUTBOUND OAuth 2.1 + PKCE client: it builds authorization
|
|
5
|
+
* URLs, exchanges codes for tokens, refreshes/revokes tokens, and stores them
|
|
6
|
+
* — for use when THIS server needs to call OUT to a third-party OAuth
|
|
7
|
+
* provider (e.g. a GitHub- or Google-backed tool). It does not validate
|
|
8
|
+
* incoming credentials and has no importers outside this file and its
|
|
9
|
+
* factories (createGitHubOAuthConfig/createGoogleOAuthConfig) — nothing here
|
|
10
|
+
* authenticates a caller of this MCP server.
|
|
11
|
+
*
|
|
12
|
+
* For INBOUND auth (verifying a request/connection reaching this server),
|
|
13
|
+
* see auth.ts's `validateCredential`/`authMiddleware`, wired into both
|
|
14
|
+
* transports (transport/http.ts, transport/websocket.ts). `validateCredential`
|
|
15
|
+
* currently supports `token` and `api-key` methods; an `oauth`-method
|
|
16
|
+
* AuthConfig explicitly rejects with "OAuth inbound validation not
|
|
17
|
+
* implemented" (auth.ts) rather than silently accepting requests — inbound
|
|
18
|
+
* OAuth (JWKS/introspection-based resource-server verification) is not
|
|
19
|
+
* implemented anywhere in this package.
|
|
5
20
|
*/
|
|
6
21
|
import { EventEmitter } from 'events';
|
|
7
22
|
import * as crypto from 'crypto';
|
|
@@ -21,7 +36,10 @@ export class InMemoryTokenStorage {
|
|
|
21
36
|
}
|
|
22
37
|
}
|
|
23
38
|
/**
|
|
24
|
-
* OAuth 2.1
|
|
39
|
+
* Outbound OAuth 2.1 client — drives the authorization-code + PKCE flow
|
|
40
|
+
* against a third-party provider on this server's behalf. Not a resource-
|
|
41
|
+
* server verifier; it never inspects an incoming request. See the module
|
|
42
|
+
* header for the inbound-auth pointer (auth.ts).
|
|
25
43
|
*/
|
|
26
44
|
export class OAuthManager extends EventEmitter {
|
|
27
45
|
logger;
|
|
@@ -266,27 +284,6 @@ export class OAuthManager extends EventEmitter {
|
|
|
266
284
|
export function createOAuthManager(logger, config) {
|
|
267
285
|
return new OAuthManager(logger, config);
|
|
268
286
|
}
|
|
269
|
-
/**
|
|
270
|
-
* OAuth middleware for Express/Connect
|
|
271
|
-
*/
|
|
272
|
-
export function oauthMiddleware(oauthManager, storageKey = 'default') {
|
|
273
|
-
return async (req, res, next) => {
|
|
274
|
-
const token = await oauthManager.getAccessToken(storageKey);
|
|
275
|
-
if (!token) {
|
|
276
|
-
res.status(401).json({
|
|
277
|
-
jsonrpc: '2.0',
|
|
278
|
-
id: null,
|
|
279
|
-
error: {
|
|
280
|
-
code: -32000,
|
|
281
|
-
message: 'Unauthorized - OAuth authentication required',
|
|
282
|
-
},
|
|
283
|
-
});
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
req.oauthToken = token;
|
|
287
|
-
next();
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
287
|
/**
|
|
291
288
|
* Create GitHub OAuth provider config
|
|
292
289
|
*/
|