mcpose 2.0.1 → 2.0.2
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 +126 -0
- package/package.json +9 -11
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# mcpose
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/mcpose)
|
|
4
|
+
[](https://github.com/amir-gorji/mcpose/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
**The composable middleware proxy for MCP.**
|
|
7
|
+
|
|
8
|
+
mcpose sits between a **client** (an LLM or agent) and an **upstream** MCP server, forwarding every tool, resource, and `list_tools` call through a **pipeline** of composable middleware. It is a transparent proxy: the client talks to mcpose exactly as it would talk to the upstream, while you intercept, transform, hide, or govern calls in between — without touching the upstream server.
|
|
9
|
+
|
|
10
|
+
## When to reach for it
|
|
11
|
+
|
|
12
|
+
- Add cross-cutting behavior (logging, PII redaction, identity resolution, rate limiting) to an MCP server you don't own.
|
|
13
|
+
- Hide or gate specific tools/resources per caller.
|
|
14
|
+
- Resolve a caller **identity** once per session and stamp it on every request.
|
|
15
|
+
- Lay the foundation for compliance-grade audit trails with [`@mcpose/audit`](https://www.npmjs.com/package/@mcpose/audit).
|
|
16
|
+
|
|
17
|
+
If you only need the audit chain or the compliance test helpers, see the ecosystem packages below — they build on this core.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install mcpose
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires Node.js 18+. Ships ESM with TypeScript types.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Connect to an upstream over stdio, add one middleware, and serve the proxy:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createBackendClient, startProxy } from 'mcpose';
|
|
33
|
+
import type { ToolMiddleware } from 'mcpose';
|
|
34
|
+
|
|
35
|
+
// 1. Connect to the upstream MCP server (stdio)
|
|
36
|
+
const backend = await createBackendClient({
|
|
37
|
+
command: 'node',
|
|
38
|
+
args: ['/path/to/backend-server.mjs'],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// 2. Define middleware: (req, next, ctx) => Promise<result>
|
|
42
|
+
const loggingMW: ToolMiddleware = async (req, next) => {
|
|
43
|
+
console.error(`→ ${req.params.name}`);
|
|
44
|
+
const result = await next(req);
|
|
45
|
+
console.error(`← ${req.params.name} done`);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 3. Start the proxy on stdio
|
|
50
|
+
await startProxy(backend, {
|
|
51
|
+
toolMiddleware: [loggingMW],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
To serve over HTTP instead — with identity resolution, mTLS, session limits, and SSE reconnect replay — use `startHttpProxy`:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { createBackendClient, startHttpProxy } from 'mcpose';
|
|
59
|
+
|
|
60
|
+
// Supplied by your application:
|
|
61
|
+
// extractJwt — a resolveIdentity function returning an Identity from the request
|
|
62
|
+
const backend = await createBackendClient({ url: 'http://localhost:9000/mcp' });
|
|
63
|
+
|
|
64
|
+
await startHttpProxy(
|
|
65
|
+
backend,
|
|
66
|
+
{ toolMiddleware: [loggingMW] },
|
|
67
|
+
{
|
|
68
|
+
port: 3000,
|
|
69
|
+
resolveIdentity: extractJwt, // stamped on every ProxyContext in the session
|
|
70
|
+
onSessionClosed: (sessionId) => {/* flush audit manifest, etc. */},
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Core concepts
|
|
76
|
+
|
|
77
|
+
- **Middleware** — a single function `(req, next, ctx) => Promise<result>`. Call `next(req)` to delegate downstream; transform the request before, or the response after. Middlewares nest onion-style.
|
|
78
|
+
- **Pipeline** — middlewares passed to `ProxyOptions` run in response-processing order (first = innermost). `[piiMW, auditMW]` redacts before it audits.
|
|
79
|
+
- **ProxyContext** — per-request metadata threaded through the pipeline: `requestId`, `transport`, `sessionId`, resolved `identity`, and the agent `delegatedFrom` chain.
|
|
80
|
+
|
|
81
|
+
## API surface
|
|
82
|
+
|
|
83
|
+
| Export | Purpose |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `createBackendClient(config)` | Connect to an upstream over stdio (`command`/`args`) or HTTP (`url`). |
|
|
86
|
+
| `startProxy(backend, options?)` | Serve the proxy over **stdio**. |
|
|
87
|
+
| `startHttpProxy(backend, proxyOptions?, httpOptions?)` | Serve over **HTTP/SSE** — identity, mTLS, sessions, reconnect replay. |
|
|
88
|
+
| `createProxyServer(backend, options?)` | Build the underlying `Server` without binding a transport. |
|
|
89
|
+
| `compose(middlewares)` | Compose middlewares into one (outermost-first). |
|
|
90
|
+
| `createProxyContext(overrides?)` | Construct a `ProxyContext` (useful in tests). |
|
|
91
|
+
| `createInMemoryEventStore()` | Default SSE reconnect event store; swap for a `PersistentEventStore`. |
|
|
92
|
+
| `hasToolContent(result)` | Type guard for tool-call results. |
|
|
93
|
+
|
|
94
|
+
**Key types:** `Middleware<Req, Res>`, `ToolMiddleware`, `ResourceMiddleware`, `ListToolsMiddleware`, `ProxyContext`, `Identity`, `BackendConfig`, `ProxyOptions`, `HttpProxyOptions`, `RejectionReason`, `TelemetryEvent`, `PersistentEventStore`.
|
|
95
|
+
|
|
96
|
+
### Governance options (`ProxyOptions`)
|
|
97
|
+
|
|
98
|
+
`hiddenTools` / `hiddenResources` reject calls with a structured [`RejectionReason`](https://github.com/amir-gorji/mcpose#rejectionreason) in the MCP error `data` field; `passThroughTools` skip the pipeline entirely; `onTelemetry` emits per-call timing and outcome.
|
|
99
|
+
|
|
100
|
+
### Test helpers — `mcpose/testing`
|
|
101
|
+
|
|
102
|
+
The core package exposes proxy/middleware test utilities under a subpath:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { createMockBackendClient, runToolMiddleware } from 'mcpose/testing';
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **Not to be confused with** [`@mcpose/testing`](https://www.npmjs.com/package/@mcpose/testing), the separate package of compliance-chain assertions.
|
|
109
|
+
|
|
110
|
+
## The mcpose ecosystem
|
|
111
|
+
|
|
112
|
+
| Package | What it adds |
|
|
113
|
+
|---|---|
|
|
114
|
+
| **`mcpose`** (this package) | Proxy core — pipeline, transports, identity, governance. |
|
|
115
|
+
| [`@mcpose/audit`](https://www.npmjs.com/package/@mcpose/audit) | Tamper-evident, HMAC-chained audit events + Merkle `ReplayManifest`. |
|
|
116
|
+
| [`@mcpose/testing`](https://www.npmjs.com/package/@mcpose/testing) | Runner-agnostic compliance assertions for the audit chain. |
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- [Full README & API reference](https://github.com/amir-gorji/mcpose#readme)
|
|
121
|
+
- [CONTEXT.md](https://github.com/amir-gorji/mcpose/blob/main/CONTEXT.md) — canonical domain glossary
|
|
122
|
+
- [Architecture decision records](https://github.com/amir-gorji/mcpose/tree/main/docs/adr)
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT © Amir Gorji
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcpose",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "The audit and governance layer for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,10 +15,7 @@
|
|
|
15
15
|
"default": "./dist/testing.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
"files": [
|
|
19
|
-
"dist",
|
|
20
|
-
"README.md"
|
|
21
|
-
],
|
|
18
|
+
"files": ["dist", "README.md"],
|
|
22
19
|
"keywords": [
|
|
23
20
|
"mcp",
|
|
24
21
|
"middleware",
|
|
@@ -37,6 +34,12 @@
|
|
|
37
34
|
"url": "git+https://github.com/amir-gorji/mcpose.git",
|
|
38
35
|
"directory": "packages/core"
|
|
39
36
|
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"ts:ci": "tsc --noEmit",
|
|
40
|
+
"test": "vitest run --passWithNoTests",
|
|
41
|
+
"prepublishOnly": "pnpm run ts:ci && pnpm run test && pnpm run build"
|
|
42
|
+
},
|
|
40
43
|
"peerDependencies": {
|
|
41
44
|
"@modelcontextprotocol/sdk": ">=1.0.0"
|
|
42
45
|
},
|
|
@@ -45,10 +48,5 @@
|
|
|
45
48
|
"@types/node": "^22.0.0",
|
|
46
49
|
"typescript": "^5.0.0",
|
|
47
50
|
"vitest": "^3.0.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsc -p tsconfig.build.json",
|
|
51
|
-
"ts:ci": "tsc --noEmit",
|
|
52
|
-
"test": "vitest run --passWithNoTests"
|
|
53
51
|
}
|
|
54
|
-
}
|
|
52
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Amir Gorji
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|