@dcyfr/ai 3.0.9 → 3.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/CHANGELOG.md +14 -0
- package/README.md +2 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/ai/mcp/servers/analytics/index.js +9 -4
- package/dist/ai/mcp/servers/analytics/index.js.map +1 -1
- package/dist/ai/mcp/servers/content-manager/index.d.ts +1 -1
- package/dist/ai/mcp/servers/content-manager/index.d.ts.map +1 -1
- package/dist/ai/mcp/servers/content-manager/index.js +5 -0
- package/dist/ai/mcp/servers/content-manager/index.js.map +1 -1
- package/dist/ai/mcp/servers/delegation-monitor/index.d.ts.map +1 -1
- package/dist/ai/mcp/servers/delegation-monitor/index.js +10 -4
- package/dist/ai/mcp/servers/delegation-monitor/index.js.map +1 -1
- package/dist/ai/mcp/servers/design-tokens/index.d.ts +1 -1
- package/dist/ai/mcp/servers/design-tokens/index.d.ts.map +1 -1
- package/dist/ai/mcp/servers/design-tokens/index.js +5 -0
- package/dist/ai/mcp/servers/design-tokens/index.js.map +1 -1
- package/dist/ai/mcp/servers/promptintel/index.js +11 -4
- package/dist/ai/mcp/servers/promptintel/index.js.map +1 -1
- package/dist/ai/mcp/servers/shared/transport.d.ts +57 -0
- package/dist/ai/mcp/servers/shared/transport.d.ts.map +1 -0
- package/dist/ai/mcp/servers/shared/transport.js +93 -0
- package/dist/ai/mcp/servers/shared/transport.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../../../packages/ai/mcp/servers/shared/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,YAAY,CAAC;AAEtD,MAAM,MAAM,uBAAuB,GAC/B;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,GAC1B;IACE,aAAa,EAAE,YAAY,CAAC;IAC5B,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1E,CAAC;AAEN,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,aAAa,EAAE,IAAI,CAAC;CACrB;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAK9C;AAUD;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,aAAa,CAAC,CAiB/F;AAED,gEAAgE;AAChE,wBAAgB,sBAAsB,IAAI,uBAAuB,CAUhE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAQpG;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,GAAG,MAAM,CAK7F"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared MCP transport selection + remote auth for DCYFR FastMCP servers.
|
|
3
|
+
*
|
|
4
|
+
* The default transport is **stdio** (unchanged, fully backward-compatible).
|
|
5
|
+
* Setting `MCP_TRANSPORT=httpStream` switches a server to FastMCP's Streamable
|
|
6
|
+
* HTTP transport so it can be reached as a *remote* MCP server — usable today
|
|
7
|
+
* as a Claude Desktop / Anthropic API custom connector (with an
|
|
8
|
+
* `Authorization: Bearer` header), and the foundation for a claude.ai Custom
|
|
9
|
+
* Connector (which additionally needs public HTTPS + OAuth — see REMOTE.md).
|
|
10
|
+
*
|
|
11
|
+
* Remote mode is **fail-closed**: a server that exposes any write / open-world
|
|
12
|
+
* tool (e.g. `promptintel:submitReport`) MUST NOT bind an HTTP port without at
|
|
13
|
+
* least one bearer token configured. `assertRemoteAuthConfigured` enforces this
|
|
14
|
+
* at startup; `buildBearerAuthenticator` enforces it per request in constant
|
|
15
|
+
* time.
|
|
16
|
+
*
|
|
17
|
+
* Env:
|
|
18
|
+
* MCP_TRANSPORT "stdio" | "httpStream" (default "stdio")
|
|
19
|
+
* MCP_HTTP_PORT port for httpStream (default 8080)
|
|
20
|
+
* MCP_HTTP_ENDPOINT endpoint path (default "/mcp")
|
|
21
|
+
* MCP_HTTP_STATELESS "true" to run stateless (default false)
|
|
22
|
+
* MCP_BEARER_TOKEN comma-separated allowed bearer tokens (REQUIRED for httpStream)
|
|
23
|
+
*/
|
|
24
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
25
|
+
/** Parse the comma-separated allow-list of bearer tokens from the environment. */
|
|
26
|
+
export function allowedBearerTokens() {
|
|
27
|
+
return (process.env.MCP_BEARER_TOKEN ?? '')
|
|
28
|
+
.split(',')
|
|
29
|
+
.map((token) => token.trim())
|
|
30
|
+
.filter((token) => token.length > 0);
|
|
31
|
+
}
|
|
32
|
+
/** Constant-time string comparison (length-guarded) to avoid token timing leaks. */
|
|
33
|
+
function safeEqual(a, b) {
|
|
34
|
+
const ab = Buffer.from(a);
|
|
35
|
+
const bb = Buffer.from(b);
|
|
36
|
+
if (ab.length !== bb.length)
|
|
37
|
+
return false;
|
|
38
|
+
return timingSafeEqual(ab, bb);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build a FastMCP `authenticate` hook enforcing `Authorization: Bearer <token>`
|
|
42
|
+
* against `MCP_BEARER_TOKEN`. Returns a minimal session on success; throws a
|
|
43
|
+
* 401 `Response` on failure. Under stdio this is never invoked (no HTTP
|
|
44
|
+
* request), so it is safe to pass unconditionally.
|
|
45
|
+
*/
|
|
46
|
+
export function buildBearerAuthenticator() {
|
|
47
|
+
return async (request) => {
|
|
48
|
+
const tokens = allowedBearerTokens();
|
|
49
|
+
const header = request.headers['authorization'];
|
|
50
|
+
const raw = Array.isArray(header) ? header[0] : header;
|
|
51
|
+
const provided = raw && raw.startsWith('Bearer ') ? raw.slice('Bearer '.length).trim() : '';
|
|
52
|
+
const authorized = provided.length > 0 && tokens.some((token) => safeEqual(provided, token));
|
|
53
|
+
if (!authorized) {
|
|
54
|
+
throw new Response(JSON.stringify({ error: 'unauthorized' }), {
|
|
55
|
+
status: 401,
|
|
56
|
+
statusText: 'Unauthorized',
|
|
57
|
+
headers: { 'content-type': 'application/json' },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return { authenticated: true };
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Resolve the transport configuration from the environment. */
|
|
64
|
+
export function resolveTransportConfig() {
|
|
65
|
+
const transport = (process.env.MCP_TRANSPORT ?? 'stdio').trim();
|
|
66
|
+
if (transport === 'httpStream') {
|
|
67
|
+
const port = Number.parseInt(process.env.MCP_HTTP_PORT ?? '8080', 10);
|
|
68
|
+
const endpointRaw = (process.env.MCP_HTTP_ENDPOINT ?? '/mcp').trim();
|
|
69
|
+
const endpoint = (endpointRaw.startsWith('/') ? endpointRaw : `/${endpointRaw}`);
|
|
70
|
+
const stateless = /^(1|true|yes)$/i.test(process.env.MCP_HTTP_STATELESS ?? '');
|
|
71
|
+
return { transportType: 'httpStream', httpStream: { port, endpoint, stateless } };
|
|
72
|
+
}
|
|
73
|
+
return { transportType: 'stdio' };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Fail-closed guard: refuse to start an HTTP-exposed server without a bearer
|
|
77
|
+
* token. Call BEFORE `server.start()`.
|
|
78
|
+
*/
|
|
79
|
+
export function assertRemoteAuthConfigured(serverName, config) {
|
|
80
|
+
if (config.transportType === 'httpStream' && allowedBearerTokens().length === 0) {
|
|
81
|
+
throw new Error(`Refusing to start ${serverName} over httpStream without MCP_BEARER_TOKEN. ` +
|
|
82
|
+
'Remote MCP exposure requires at least one bearer token (comma-separated allowed). ' +
|
|
83
|
+
'Set MCP_BEARER_TOKEN, or use the default stdio transport for local use.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Human-readable one-line startup banner for the resolved transport. */
|
|
87
|
+
export function describeTransport(serverName, config) {
|
|
88
|
+
if (config.transportType === 'httpStream') {
|
|
89
|
+
return `✅ ${serverName} started (httpStream) on http://0.0.0.0:${config.httpStream.port}${config.httpStream.endpoint} — bearer auth enforced`;
|
|
90
|
+
}
|
|
91
|
+
return `✅ ${serverName} started (stdio mode)`;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../../packages/ai/mcp/servers/shared/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAgB9C,kFAAkF;AAClF,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;SACxC,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,oFAAoF;AACpF,SAAS,SAAS,CAAC,CAAS,EAAE,CAAS;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,eAAe,CAAC,EAAE,EAAE,EAA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