mcp4openapi 0.3.1 → 0.3.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/README.md +7 -0
- package/dist/src/core/cli-config.d.ts.map +1 -1
- package/dist/src/core/cli-config.js +2 -0
- package/dist/src/core/cli-config.js.map +1 -1
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +18 -3
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/index.js +0 -0
- package/dist/src/profile/profile-allowlist.d.ts +18 -0
- package/dist/src/profile/profile-allowlist.d.ts.map +1 -0
- package/dist/src/profile/profile-allowlist.js +68 -0
- package/dist/src/profile/profile-allowlist.js.map +1 -0
- package/dist/src/profile/profile-registry.d.ts +5 -0
- package/dist/src/profile/profile-registry.d.ts.map +1 -1
- package/dist/src/profile/profile-registry.js +38 -14
- package/dist/src/profile/profile-registry.js.map +1 -1
- package/package.json +2 -2
- package/profiles/gitlab/developer-profile-oauth.json +243 -41
- package/profiles/gitlab/developer-profile-oauth.test.json +1009 -5
- package/profiles/gitlab/openapi.yaml +1419 -164
- package/profiles/gitlab/profile-optimized-oauth.json +785 -0
- package/profiles/gitlab/profile-optimized-oauth.test.json +1566 -0
- package/profiles/grafana/openapi.json +28078 -0
- package/profiles/grafana/profile.json +1083 -0
- package/profiles/grafana/profile.test.json +235 -0
- package/profiles/mattermost/openapi.yaml +27434 -0
- package/profiles/mattermost/profile.json +463 -0
- package/profiles/mattermost/profile.test.json +607 -0
- package/profiles/n8n/profile-optimized.json +1002 -364
- package/profiles/n8n/profile-optimized.test.json +43 -43
- package/dist/src/argument-normalizer.d.ts +0 -5
- package/dist/src/argument-normalizer.d.ts.map +0 -1
- package/dist/src/argument-normalizer.js +0 -61
- package/dist/src/argument-normalizer.js.map +0 -1
- package/dist/src/cli-config.d.ts +0 -9
- package/dist/src/cli-config.d.ts.map +0 -1
- package/dist/src/cli-config.js +0 -111
- package/dist/src/cli-config.js.map +0 -1
- package/dist/src/composite-executor.d.ts +0 -77
- package/dist/src/composite-executor.d.ts.map +0 -1
- package/dist/src/composite-executor.js +0 -193
- package/dist/src/composite-executor.js.map +0 -1
- package/dist/src/constants.d.ts +0 -85
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -85
- package/dist/src/constants.js.map +0 -1
- package/dist/src/dag-executor.d.ts +0 -49
- package/dist/src/dag-executor.d.ts.map +0 -1
- package/dist/src/dag-executor.js +0 -138
- package/dist/src/dag-executor.js.map +0 -1
- package/dist/src/errors.d.ts +0 -59
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -119
- package/dist/src/errors.js.map +0 -1
- package/dist/src/filtering.d.ts +0 -19
- package/dist/src/filtering.d.ts.map +0 -1
- package/dist/src/filtering.js +0 -292
- package/dist/src/filtering.js.map +0 -1
- package/dist/src/http-client-factory.d.ts +0 -62
- package/dist/src/http-client-factory.d.ts.map +0 -1
- package/dist/src/http-client-factory.js +0 -133
- package/dist/src/http-client-factory.js.map +0 -1
- package/dist/src/http-transport-config.d.ts +0 -6
- package/dist/src/http-transport-config.d.ts.map +0 -1
- package/dist/src/http-transport-config.js +0 -47
- package/dist/src/http-transport-config.js.map +0 -1
- package/dist/src/http-transport.d.ts +0 -316
- package/dist/src/http-transport.d.ts.map +0 -1
- package/dist/src/http-transport.js +0 -2412
- package/dist/src/http-transport.js.map +0 -1
- package/dist/src/interceptors.d.ts +0 -116
- package/dist/src/interceptors.d.ts.map +0 -1
- package/dist/src/interceptors.js +0 -392
- package/dist/src/interceptors.js.map +0 -1
- package/dist/src/jsonrpc-validator.d.ts +0 -27
- package/dist/src/jsonrpc-validator.d.ts.map +0 -1
- package/dist/src/jsonrpc-validator.js +0 -58
- package/dist/src/jsonrpc-validator.js.map +0 -1
- package/dist/src/logger.d.ts +0 -59
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/logger.js +0 -177
- package/dist/src/logger.js.map +0 -1
- package/dist/src/mcp-server-manager.d.ts +0 -20
- package/dist/src/mcp-server-manager.d.ts.map +0 -1
- package/dist/src/mcp-server-manager.js +0 -38
- package/dist/src/mcp-server-manager.js.map +0 -1
- package/dist/src/mcp-server.d.ts +0 -203
- package/dist/src/mcp-server.d.ts.map +0 -1
- package/dist/src/mcp-server.js +0 -1369
- package/dist/src/mcp-server.js.map +0 -1
- package/dist/src/metrics.d.ts +0 -97
- package/dist/src/metrics.d.ts.map +0 -1
- package/dist/src/metrics.js +0 -273
- package/dist/src/metrics.js.map +0 -1
- package/dist/src/naming-warnings.d.ts +0 -23
- package/dist/src/naming-warnings.d.ts.map +0 -1
- package/dist/src/naming-warnings.js +0 -83
- package/dist/src/naming-warnings.js.map +0 -1
- package/dist/src/naming.d.ts +0 -58
- package/dist/src/naming.d.ts.map +0 -1
- package/dist/src/naming.js +0 -510
- package/dist/src/naming.js.map +0 -1
- package/dist/src/oauth-provider.d.ts +0 -131
- package/dist/src/oauth-provider.d.ts.map +0 -1
- package/dist/src/oauth-provider.js +0 -836
- package/dist/src/oauth-provider.js.map +0 -1
- package/dist/src/openapi-parser.d.ts +0 -70
- package/dist/src/openapi-parser.d.ts.map +0 -1
- package/dist/src/openapi-parser.js +0 -436
- package/dist/src/openapi-parser.js.map +0 -1
- package/dist/src/profile-loader.d.ts +0 -78
- package/dist/src/profile-loader.d.ts.map +0 -1
- package/dist/src/profile-loader.js +0 -483
- package/dist/src/profile-loader.js.map +0 -1
- package/dist/src/profile-registry.d.ts +0 -18
- package/dist/src/profile-registry.d.ts.map +0 -1
- package/dist/src/profile-registry.js +0 -26
- package/dist/src/profile-registry.js.map +0 -1
- package/dist/src/profile-resolver.d.ts +0 -19
- package/dist/src/profile-resolver.d.ts.map +0 -1
- package/dist/src/profile-resolver.js +0 -167
- package/dist/src/profile-resolver.js.map +0 -1
- package/dist/src/proxy-executor.d.ts +0 -86
- package/dist/src/proxy-executor.d.ts.map +0 -1
- package/dist/src/proxy-executor.js +0 -497
- package/dist/src/proxy-executor.js.map +0 -1
- package/dist/src/schema-validator.d.ts +0 -30
- package/dist/src/schema-validator.d.ts.map +0 -1
- package/dist/src/schema-validator.js +0 -128
- package/dist/src/schema-validator.js.map +0 -1
- package/dist/src/startup-profile.d.ts +0 -17
- package/dist/src/startup-profile.d.ts.map +0 -1
- package/dist/src/startup-profile.js +0 -30
- package/dist/src/startup-profile.js.map +0 -1
- package/dist/src/startup-validation.d.ts +0 -11
- package/dist/src/startup-validation.d.ts.map +0 -1
- package/dist/src/startup-validation.js +0 -21
- package/dist/src/startup-validation.js.map +0 -1
- package/dist/src/tool-filter.d.ts +0 -65
- package/dist/src/tool-filter.d.ts.map +0 -1
- package/dist/src/tool-filter.js +0 -471
- package/dist/src/tool-filter.js.map +0 -1
- package/dist/src/tool-generator.d.ts +0 -67
- package/dist/src/tool-generator.d.ts.map +0 -1
- package/dist/src/tool-generator.js +0 -182
- package/dist/src/tool-generator.js.map +0 -1
- package/dist/src/validation-utils.d.ts +0 -49
- package/dist/src/validation-utils.d.ts.map +0 -1
- package/dist/src/validation-utils.js +0 -138
- package/dist/src/validation-utils.js.map +0 -1
- package/profiles/gitlab/developer-profile.json +0 -1508
- package/profiles/gitlab/developer-profile.test.json +0 -3432
package/dist/src/errors.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structured error types for MCP server
|
|
3
|
-
*
|
|
4
|
-
* Provides type-safe error handling with machine-readable error codes
|
|
5
|
-
* and structured error details for better debugging and client handling.
|
|
6
|
-
*/
|
|
7
|
-
import { randomUUID } from 'node:crypto';
|
|
8
|
-
export class MCPError extends Error {
|
|
9
|
-
constructor(message, code, details) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.details = details;
|
|
13
|
-
this.name = 'MCPError';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class ValidationError extends MCPError {
|
|
17
|
-
constructor(message, details) {
|
|
18
|
-
super(message, 'VALIDATION_ERROR', details);
|
|
19
|
-
this.name = 'ValidationError';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export class OperationNotFoundError extends MCPError {
|
|
23
|
-
constructor(operationId) {
|
|
24
|
-
super(`Operation not found: ${operationId}`, 'OPERATION_NOT_FOUND', { operationId });
|
|
25
|
-
this.name = 'OperationNotFoundError';
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class ResourceNotFoundError extends MCPError {
|
|
29
|
-
constructor(resource, resourceType = 'Resource') {
|
|
30
|
-
super(`${resourceType} not found: ${resource}`, 'RESOURCE_NOT_FOUND', { resource, resourceType });
|
|
31
|
-
this.name = 'ResourceNotFoundError';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export class ParameterError extends MCPError {
|
|
35
|
-
constructor(paramName, reason) {
|
|
36
|
-
super(`Invalid parameter '${paramName}': ${reason}`, 'PARAMETER_ERROR', { paramName, reason });
|
|
37
|
-
this.name = 'ParameterError';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export class AuthenticationError extends MCPError {
|
|
41
|
-
constructor(message = 'Authentication required', details) {
|
|
42
|
-
super(message, 'AUTHENTICATION_ERROR', details);
|
|
43
|
-
this.name = 'AuthenticationError';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export class AuthorizationError extends MCPError {
|
|
47
|
-
constructor(message = 'Insufficient permissions') {
|
|
48
|
-
super(message, 'AUTHORIZATION_ERROR');
|
|
49
|
-
this.name = 'AuthorizationError';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export class RateLimitError extends MCPError {
|
|
53
|
-
constructor(message, retryAfter) {
|
|
54
|
-
super(message, 'RATE_LIMIT_EXCEEDED', retryAfter ? { retryAfter } : undefined);
|
|
55
|
-
this.name = 'RateLimitError';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export class NetworkError extends MCPError {
|
|
59
|
-
constructor(message, statusCode, details) {
|
|
60
|
-
super(message, 'NETWORK_ERROR', { statusCode, ...details });
|
|
61
|
-
this.name = 'NetworkError';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export class ConfigurationError extends MCPError {
|
|
65
|
-
constructor(message, details) {
|
|
66
|
-
super(message, 'CONFIGURATION_ERROR', details);
|
|
67
|
-
this.name = 'ConfigurationError';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export class SessionError extends MCPError {
|
|
71
|
-
constructor(message, sessionId) {
|
|
72
|
-
super(message, 'SESSION_ERROR', sessionId ? { sessionId } : undefined);
|
|
73
|
-
this.name = 'SessionError';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export class UnknownCliFlagError extends MCPError {
|
|
77
|
-
constructor(flags) {
|
|
78
|
-
const sortedFlags = [...flags].sort();
|
|
79
|
-
super(`Unknown CLI flags: ${sortedFlags.join(', ')}`, 'UNKNOWN_CLI_FLAG', { flags: sortedFlags });
|
|
80
|
-
this.name = 'UnknownCliFlagError';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Helper function to check if an error is an MCPError
|
|
85
|
-
*/
|
|
86
|
-
export function isMCPError(error) {
|
|
87
|
-
return error instanceof MCPError;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Generate a unique correlation ID for error tracking
|
|
91
|
-
*
|
|
92
|
-
* Why: Allows matching client-reported errors with server logs
|
|
93
|
-
*/
|
|
94
|
-
export function generateCorrelationId() {
|
|
95
|
-
return randomUUID();
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Helper function to get error details for logging
|
|
99
|
-
*/
|
|
100
|
-
export function getErrorDetails(error) {
|
|
101
|
-
if (isMCPError(error)) {
|
|
102
|
-
return {
|
|
103
|
-
name: error.name,
|
|
104
|
-
code: error.code,
|
|
105
|
-
message: error.message,
|
|
106
|
-
details: error.details,
|
|
107
|
-
stack: error.stack,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (error instanceof Error) {
|
|
111
|
-
return {
|
|
112
|
-
name: error.name,
|
|
113
|
-
message: error.message,
|
|
114
|
-
stack: error.stack,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return { message: String(error) };
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACE,OAAe,EACR,IAAY,EACZ,OAAiC;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAA0B;QAGxC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,QAAQ;IAClD,YAAY,WAAmB;QAC7B,KAAK,CACH,wBAAwB,WAAW,EAAE,EACrC,qBAAqB,EACrB,EAAE,WAAW,EAAE,CAChB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;IACjD,YAAY,QAAgB,EAAE,eAAuB,UAAU;QAC7D,KAAK,CACH,GAAG,YAAY,eAAe,QAAQ,EAAE,EACxC,oBAAoB,EACpB,EAAE,QAAQ,EAAE,YAAY,EAAE,CAC3B,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB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L,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
package/dist/src/filtering.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from './types/profile.js';
|
|
2
|
-
import type { OperationInfo } from './types/openapi.js';
|
|
3
|
-
export type FilteringRules = Record<string, string[]>;
|
|
4
|
-
export interface FilteringParseResult {
|
|
5
|
-
filtering: FilteringRules;
|
|
6
|
-
normalizedHeader: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function normalizeFilteringHeaderValue(value?: string): string | undefined;
|
|
9
|
-
export declare function parseFilteringHeader(headerValue: string): FilteringParseResult;
|
|
10
|
-
export declare function isControlKey(key: string): boolean;
|
|
11
|
-
export declare function getFilterMaxValues(): number;
|
|
12
|
-
export declare function enforceFiltering(context: {
|
|
13
|
-
filtering: FilteringRules;
|
|
14
|
-
toolDef: ToolDefinition;
|
|
15
|
-
args: Record<string, unknown>;
|
|
16
|
-
parameterAliases?: Record<string, string[]>;
|
|
17
|
-
operation?: OperationInfo;
|
|
18
|
-
}): void;
|
|
19
|
-
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOxD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAEtD,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,cAAc,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,6BAA6B,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOhF;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,oBAAoB,CA2D9E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEjD;AAaD,wBAAgB,kBAAkB,IAAI,MAAM,CAY3C;AAyJD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,GAAG,IAAI,CA+BP"}
|
package/dist/src/filtering.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { AuthorizationError, ValidationError } from './errors.js';
|
|
2
|
-
const CONTROL_KEYS = new Set(['_allow_list', '_allow_read']);
|
|
3
|
-
const KEY_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$/;
|
|
4
|
-
export function normalizeFilteringHeaderValue(value) {
|
|
5
|
-
if (value === undefined || value === null) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const normalized = value.trim();
|
|
9
|
-
return normalized.length > 0 ? normalized : undefined;
|
|
10
|
-
}
|
|
11
|
-
export function parseFilteringHeader(headerValue) {
|
|
12
|
-
const normalizedHeader = normalizeFilteringHeaderValue(headerValue);
|
|
13
|
-
if (!normalizedHeader) {
|
|
14
|
-
return { filtering: Object.create(null), normalizedHeader: '' };
|
|
15
|
-
}
|
|
16
|
-
const maxValues = getFilterMaxValues();
|
|
17
|
-
const filtering = Object.create(null);
|
|
18
|
-
const parts = normalizedHeader.split(',');
|
|
19
|
-
for (const part of parts) {
|
|
20
|
-
const trimmed = part.trim();
|
|
21
|
-
if (!trimmed) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const equalsIndex = trimmed.indexOf('=');
|
|
25
|
-
if (equalsIndex === -1) {
|
|
26
|
-
if (!CONTROL_KEYS.has(trimmed) || !KEY_PATTERN.test(trimmed)) {
|
|
27
|
-
throw new ValidationError('Invalid X-Mcp4-Params header. Expected comma-separated key=value pairs.');
|
|
28
|
-
}
|
|
29
|
-
filtering[trimmed] = filtering[trimmed] ?? [];
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const key = trimmed.slice(0, equalsIndex).trim();
|
|
33
|
-
const rawValue = trimmed.slice(equalsIndex + 1).trim();
|
|
34
|
-
if (!key || !KEY_PATTERN.test(key)) {
|
|
35
|
-
throw new ValidationError('Invalid X-Mcp4-Params header. Expected comma-separated key=value pairs.');
|
|
36
|
-
}
|
|
37
|
-
if (CONTROL_KEYS.has(key)) {
|
|
38
|
-
throw new ValidationError('Invalid X-Mcp4-Params header. Expected comma-separated key=value pairs.');
|
|
39
|
-
}
|
|
40
|
-
if (!rawValue) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
let decodedValue;
|
|
44
|
-
try {
|
|
45
|
-
decodedValue = decodeURIComponent(rawValue);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
throw new ValidationError('Invalid X-Mcp4-Params header. Expected comma-separated key=value pairs.');
|
|
49
|
-
}
|
|
50
|
-
const values = filtering[key] ?? [];
|
|
51
|
-
if (values.length >= maxValues) {
|
|
52
|
-
throw new ValidationError(`X-Mcp4-Params exceeds max values for key '${key}'. Max allowed is ${maxValues}.`);
|
|
53
|
-
}
|
|
54
|
-
values.push(decodedValue);
|
|
55
|
-
filtering[key] = values;
|
|
56
|
-
}
|
|
57
|
-
return { filtering, normalizedHeader };
|
|
58
|
-
}
|
|
59
|
-
export function isControlKey(key) {
|
|
60
|
-
return CONTROL_KEYS.has(key);
|
|
61
|
-
}
|
|
62
|
-
export function getFilterMaxValues() {
|
|
63
|
-
const raw = process.env.MCP4_FILTER_MAX_VALUES;
|
|
64
|
-
if (raw === undefined) {
|
|
65
|
-
return 10;
|
|
66
|
-
}
|
|
67
|
-
const parsed = parseInt(raw, 10);
|
|
68
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
69
|
-
throw new ValidationError(`Invalid MCP4_FILTER_MAX_VALUES: expected positive integer, got '${raw}'.`);
|
|
70
|
-
}
|
|
71
|
-
return parsed;
|
|
72
|
-
}
|
|
73
|
-
function prepareFilteringContext(filtering, toolDef, args, parameterAliases, operation) {
|
|
74
|
-
const aliasToCanonical = buildAliasToCanonical(parameterAliases);
|
|
75
|
-
const toolParamGroups = buildToolParamGroups(toolDef, parameterAliases, aliasToCanonical);
|
|
76
|
-
const filterKeys = Object.keys(filtering).filter(key => !isControlKey(key));
|
|
77
|
-
validateFilterKeys(filterKeys, toolParamGroups, toolDef.parameters);
|
|
78
|
-
const allowedByCanonical = buildAllowedByCanonical(filterKeys, filtering, aliasToCanonical, toolParamGroups);
|
|
79
|
-
const applicableCanonicals = Array.from(allowedByCanonical.keys());
|
|
80
|
-
const operationCategory = resolveOperationCategory(operation, args['action']);
|
|
81
|
-
return {
|
|
82
|
-
aliasToCanonical,
|
|
83
|
-
toolParamGroups,
|
|
84
|
-
allowedByCanonical,
|
|
85
|
-
applicableCanonicals,
|
|
86
|
-
operationCategory,
|
|
87
|
-
hasAnyFilterParam: applicableCanonicals.some(canonical => {
|
|
88
|
-
const group = toolParamGroups.get(canonical);
|
|
89
|
-
return group ? getArgumentValue(args, group.names) !== undefined : false;
|
|
90
|
-
}),
|
|
91
|
-
permissions: {
|
|
92
|
-
allowList: Object.prototype.hasOwnProperty.call(filtering, '_allow_list'),
|
|
93
|
-
allowRead: Object.prototype.hasOwnProperty.call(filtering, '_allow_read')
|
|
94
|
-
},
|
|
95
|
-
action: typeof args['action'] === 'string' ? args['action'] : undefined
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function buildAllowedByCanonical(filterKeys, filtering, aliasToCanonical, toolParamGroups) {
|
|
99
|
-
const allowedByCanonical = new Map();
|
|
100
|
-
for (const key of filterKeys) {
|
|
101
|
-
const canonical = aliasToCanonical.get(key) ?? key;
|
|
102
|
-
if (!toolParamGroups.has(canonical)) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
const values = filtering[key] ?? [];
|
|
106
|
-
if (values.length === 0) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const existing = allowedByCanonical.get(canonical) ?? [];
|
|
110
|
-
existing.push(...values);
|
|
111
|
-
allowedByCanonical.set(canonical, dedupe(existing));
|
|
112
|
-
}
|
|
113
|
-
return allowedByCanonical;
|
|
114
|
-
}
|
|
115
|
-
function validateParameterValue(argValue, allowedValues, canonical) {
|
|
116
|
-
const allowedSet = new Set(allowedValues);
|
|
117
|
-
if (Array.isArray(argValue)) {
|
|
118
|
-
for (const item of argValue) {
|
|
119
|
-
if (!isPrimitiveValue(item)) {
|
|
120
|
-
throw new AuthorizationError(`Filter conflict for '${canonical}': expected one of [${allowedValues.join(', ')}], got '${formatValue(item)}'.`);
|
|
121
|
-
}
|
|
122
|
-
const stringValue = String(item);
|
|
123
|
-
if (!allowedSet.has(stringValue)) {
|
|
124
|
-
throw new AuthorizationError(`Filter conflict for '${canonical}': expected one of [${allowedValues.join(', ')}], got '${stringValue}'.`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (typeof argValue === 'object' && argValue !== null) {
|
|
130
|
-
throw new AuthorizationError(`Filter conflict for '${canonical}': expected one of [${allowedValues.join(', ')}], got '${formatValue(argValue)}'.`);
|
|
131
|
-
}
|
|
132
|
-
const stringValue = String(argValue);
|
|
133
|
-
if (!allowedSet.has(stringValue)) {
|
|
134
|
-
throw new AuthorizationError(`Filter conflict for '${canonical}': expected one of [${allowedValues.join(', ')}], got '${stringValue}'.`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function validateCanonicalParameter(ctx, canonical, args, toolDef) {
|
|
138
|
-
const allowedValues = ctx.allowedByCanonical.get(canonical) ?? [];
|
|
139
|
-
const group = ctx.toolParamGroups.get(canonical);
|
|
140
|
-
if (!group) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const paramDefinition = toolDef.parameters[canonical];
|
|
144
|
-
const argValue = getArgumentValue(args, group.names);
|
|
145
|
-
const { operationCategory, permissions, hasAnyFilterParam, action } = ctx;
|
|
146
|
-
const isList = operationCategory === 'list';
|
|
147
|
-
const isRead = operationCategory === 'read';
|
|
148
|
-
const isModify = operationCategory === 'modify';
|
|
149
|
-
if (argValue === undefined) {
|
|
150
|
-
if ((isList && permissions.allowList) || (isRead && permissions.allowRead)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (action && isRequiredForAction(paramDefinition, action)) {
|
|
154
|
-
throw new AuthorizationError(`Filter requires parameter '${canonical}' for tool '${toolDef.name}' action '${action}'.`);
|
|
155
|
-
}
|
|
156
|
-
if (isModify && hasAnyFilterParam) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (isList || isRead || isModify) {
|
|
160
|
-
throw new AuthorizationError(`Filter requires parameter '${canonical}' for tool '${toolDef.name}'.`);
|
|
161
|
-
}
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
// For list/read operations, allow _allow_list/_allow_read to relax value enforcement.
|
|
165
|
-
// This enables "read/list any" access while keeping modify operations constrained to the allow-set.
|
|
166
|
-
if ((isList && permissions.allowList) || (isRead && permissions.allowRead)) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
validateParameterValue(argValue, allowedValues, canonical);
|
|
170
|
-
}
|
|
171
|
-
export function enforceFiltering(context) {
|
|
172
|
-
const { filtering, toolDef, args, parameterAliases, operation } = context;
|
|
173
|
-
const filterKeys = Object.keys(filtering).filter(key => !isControlKey(key));
|
|
174
|
-
if (filterKeys.length === 0) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const ctx = prepareFilteringContext(filtering, toolDef, args, parameterAliases ?? {}, operation);
|
|
178
|
-
if (ctx.applicableCanonicals.length === 0) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (ctx.operationCategory === 'modify' && !ctx.hasAnyFilterParam) {
|
|
182
|
-
for (const canonical of ctx.applicableCanonicals) {
|
|
183
|
-
const paramDefinition = toolDef.parameters[canonical];
|
|
184
|
-
if (ctx.action && isRequiredForAction(paramDefinition, ctx.action)) {
|
|
185
|
-
throw new AuthorizationError(`Filter requires parameter '${canonical}' for tool '${toolDef.name}' action '${ctx.action}'.`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
throw new AuthorizationError(`Filter requires at least one of [${ctx.applicableCanonicals.join(', ')}] for tool '${toolDef.name}'.`);
|
|
189
|
-
}
|
|
190
|
-
for (const canonical of ctx.applicableCanonicals) {
|
|
191
|
-
validateCanonicalParameter(ctx, canonical, args, toolDef);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function buildAliasToCanonical(parameterAliases) {
|
|
195
|
-
const aliasToCanonical = new Map();
|
|
196
|
-
for (const [canonical, aliases] of Object.entries(parameterAliases)) {
|
|
197
|
-
for (const alias of aliases) {
|
|
198
|
-
if (!aliasToCanonical.has(alias)) {
|
|
199
|
-
aliasToCanonical.set(alias, canonical);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return aliasToCanonical;
|
|
204
|
-
}
|
|
205
|
-
function buildToolParamGroups(toolDef, parameterAliases, aliasToCanonical) {
|
|
206
|
-
const groups = new Map();
|
|
207
|
-
for (const paramName of Object.keys(toolDef.parameters)) {
|
|
208
|
-
const canonical = aliasToCanonical.get(paramName) ?? paramName;
|
|
209
|
-
const aliasNames = parameterAliases[canonical] ?? [];
|
|
210
|
-
const group = groups.get(canonical) ?? { names: [] };
|
|
211
|
-
group.names = dedupe([canonical, ...aliasNames, paramName, ...group.names]);
|
|
212
|
-
groups.set(canonical, group);
|
|
213
|
-
}
|
|
214
|
-
return groups;
|
|
215
|
-
}
|
|
216
|
-
function validateFilterKeys(filterKeys, toolParamGroups, parameters) {
|
|
217
|
-
const allowedKeys = new Set();
|
|
218
|
-
for (const [canonical, group] of toolParamGroups.entries()) {
|
|
219
|
-
allowedKeys.add(canonical);
|
|
220
|
-
for (const name of group.names) {
|
|
221
|
-
allowedKeys.add(name);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
for (const key of Object.keys(parameters)) {
|
|
225
|
-
allowedKeys.add(key);
|
|
226
|
-
}
|
|
227
|
-
const unknownKeys = filterKeys.filter(key => !allowedKeys.has(key));
|
|
228
|
-
if (unknownKeys.length === 0) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const allowedList = Array.from(allowedKeys).sort().join(', ');
|
|
232
|
-
throw new ValidationError(`Unknown filter key '${unknownKeys[0]}'. Allowed keys: ${allowedList}`);
|
|
233
|
-
}
|
|
234
|
-
function isRequiredForAction(paramDefinition, action) {
|
|
235
|
-
if (!paramDefinition) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
if (paramDefinition.required) {
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
if (!paramDefinition.required_for || paramDefinition.required_for.length === 0) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
return paramDefinition.required_for.includes(action);
|
|
245
|
-
}
|
|
246
|
-
function getArgumentValue(args, names) {
|
|
247
|
-
for (const name of names) {
|
|
248
|
-
if (args[name] !== undefined) {
|
|
249
|
-
return args[name];
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
function resolveOperationCategory(operation, action) {
|
|
255
|
-
if (operation) {
|
|
256
|
-
const method = operation.method.toLowerCase();
|
|
257
|
-
if (method === 'get') {
|
|
258
|
-
const hasPathParams = operation.parameters.some(param => param.in === 'path');
|
|
259
|
-
return hasPathParams ? 'read' : 'list';
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
const actionValue = typeof action === 'string' ? action.toLowerCase() : '';
|
|
263
|
-
if (actionValue === 'list' || actionValue === 'search') {
|
|
264
|
-
return 'list';
|
|
265
|
-
}
|
|
266
|
-
if (actionValue === 'get' || actionValue === 'read') {
|
|
267
|
-
return 'read';
|
|
268
|
-
}
|
|
269
|
-
return 'modify';
|
|
270
|
-
}
|
|
271
|
-
function dedupe(values) {
|
|
272
|
-
return Array.from(new Set(values));
|
|
273
|
-
}
|
|
274
|
-
function isPrimitiveValue(value) {
|
|
275
|
-
return ['string', 'number', 'boolean'].includes(typeof value);
|
|
276
|
-
}
|
|
277
|
-
function formatValue(value) {
|
|
278
|
-
if (value === undefined) {
|
|
279
|
-
return 'undefined';
|
|
280
|
-
}
|
|
281
|
-
if (value === null) {
|
|
282
|
-
return 'null';
|
|
283
|
-
}
|
|
284
|
-
if (Array.isArray(value)) {
|
|
285
|
-
return 'array';
|
|
286
|
-
}
|
|
287
|
-
if (typeof value === 'object') {
|
|
288
|
-
return 'object';
|
|
289
|
-
}
|
|
290
|
-
return String(value);
|
|
291
|
-
}
|
|
292
|
-
//# sourceMappingURL=filtering.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.js","sourceRoot":"","sources":["../../src/filtering.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,mCAAmC,CAAC;AASxD,MAAM,UAAU,6BAA6B,CAAC,KAAc;IAC1D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,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GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,IAAI,WAAW,KAAK,MAAM,IAAI,WAAW,KAAK,QAAQ,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,WAAW,KAAK,KAAK,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QACpD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,MAAM,CAAC,MAAgB;IAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Client Factory - unified HTTP client management
|
|
3
|
-
*
|
|
4
|
-
* Why: Eliminates code duplication in HTTP client creation and management
|
|
5
|
-
* Provides consistent client lifecycle, auth handling, and caching
|
|
6
|
-
*/
|
|
7
|
-
import { HttpClient } from './interceptors.js';
|
|
8
|
-
import type { Profile } from './types/profile.js';
|
|
9
|
-
export interface HttpClientConfig {
|
|
10
|
-
profile: Profile;
|
|
11
|
-
baseUrl: string;
|
|
12
|
-
sessionToken?: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Factory for creating and managing HTTP clients
|
|
16
|
-
* Handles both global and session-specific clients
|
|
17
|
-
*/
|
|
18
|
-
export declare class HttpClientFactory {
|
|
19
|
-
private globalClient?;
|
|
20
|
-
private sessionClients;
|
|
21
|
-
/**
|
|
22
|
-
* Create global HTTP client (for stdio transport)
|
|
23
|
-
*/
|
|
24
|
-
createGlobalClient(config: HttpClientConfig): HttpClient;
|
|
25
|
-
/**
|
|
26
|
-
* Get or create session-specific HTTP client
|
|
27
|
-
*/
|
|
28
|
-
getOrCreateSessionClient(sessionId: string, config: HttpClientConfig): HttpClient;
|
|
29
|
-
/**
|
|
30
|
-
* Get global client (throws if not initialized)
|
|
31
|
-
*/
|
|
32
|
-
getGlobalClient(): HttpClient;
|
|
33
|
-
/**
|
|
34
|
-
* Get session client (throws if not exists)
|
|
35
|
-
*/
|
|
36
|
-
getSessionClient(sessionId: string): HttpClient;
|
|
37
|
-
/**
|
|
38
|
-
* Cleanup session client
|
|
39
|
-
*/
|
|
40
|
-
cleanupSessionClient(sessionId: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Check if global client exists
|
|
43
|
-
*/
|
|
44
|
-
hasGlobalClient(): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Check if session client exists
|
|
47
|
-
*/
|
|
48
|
-
hasSessionClient(sessionId: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Get auth token for client creation
|
|
51
|
-
*/
|
|
52
|
-
private getAuthToken;
|
|
53
|
-
/**
|
|
54
|
-
* Create interceptor chain for client
|
|
55
|
-
*/
|
|
56
|
-
private createInterceptorChain;
|
|
57
|
-
/**
|
|
58
|
-
* Validate client configuration
|
|
59
|
-
*/
|
|
60
|
-
validateClientConfig(config: HttpClientConfig): void;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=http-client-factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-client-factory.d.ts","sourceRoot":"","sources":["../../src/http-client-factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAa;IAClC,OAAO,CAAC,cAAc,CAAiC;IAEvD;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU;IAOxD;;OAEG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,UAAU;IAsBjF;;OAEG;IACH,eAAe,IAAI,UAAU;IAO7B;;OAEG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU;IAQ/C;;OAEG;IACH,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIhD;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI5C;;OAEG;IACH,OAAO,CAAC,YAAY;IAuBpB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAK9B;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;CAsBrD"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Client Factory - unified HTTP client management
|
|
3
|
-
*
|
|
4
|
-
* Why: Eliminates code duplication in HTTP client creation and management
|
|
5
|
-
* Provides consistent client lifecycle, auth handling, and caching
|
|
6
|
-
*/
|
|
7
|
-
import { InterceptorChain, HttpClient } from './interceptors.js';
|
|
8
|
-
import { ConfigurationError, AuthenticationError } from './errors.js';
|
|
9
|
-
/**
|
|
10
|
-
* Factory for creating and managing HTTP clients
|
|
11
|
-
* Handles both global and session-specific clients
|
|
12
|
-
*/
|
|
13
|
-
export class HttpClientFactory {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.sessionClients = new Map();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create global HTTP client (for stdio transport)
|
|
19
|
-
*/
|
|
20
|
-
createGlobalClient(config) {
|
|
21
|
-
const interceptors = this.createInterceptorChain(config);
|
|
22
|
-
const client = new HttpClient(config.baseUrl, interceptors);
|
|
23
|
-
this.globalClient = client;
|
|
24
|
-
return client;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get or create session-specific HTTP client
|
|
28
|
-
*/
|
|
29
|
-
getOrCreateSessionClient(sessionId, config) {
|
|
30
|
-
// Check cache first
|
|
31
|
-
let client = this.sessionClients.get(sessionId);
|
|
32
|
-
if (client) {
|
|
33
|
-
return client;
|
|
34
|
-
}
|
|
35
|
-
// Create new client for session
|
|
36
|
-
const interceptors = this.createInterceptorChain(config);
|
|
37
|
-
const newClient = new HttpClient(config.baseUrl, interceptors);
|
|
38
|
-
// Double-check for race condition
|
|
39
|
-
const existingClient = this.sessionClients.get(sessionId);
|
|
40
|
-
if (existingClient) {
|
|
41
|
-
return existingClient;
|
|
42
|
-
}
|
|
43
|
-
// Cache and return
|
|
44
|
-
this.sessionClients.set(sessionId, newClient);
|
|
45
|
-
return newClient;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get global client (throws if not initialized)
|
|
49
|
-
*/
|
|
50
|
-
getGlobalClient() {
|
|
51
|
-
if (!this.globalClient) {
|
|
52
|
-
throw new ConfigurationError('Global HTTP client not initialized');
|
|
53
|
-
}
|
|
54
|
-
return this.globalClient;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get session client (throws if not exists)
|
|
58
|
-
*/
|
|
59
|
-
getSessionClient(sessionId) {
|
|
60
|
-
const client = this.sessionClients.get(sessionId);
|
|
61
|
-
if (!client) {
|
|
62
|
-
throw new ConfigurationError(`Session HTTP client not found for session: ${sessionId}`);
|
|
63
|
-
}
|
|
64
|
-
return client;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Cleanup session client
|
|
68
|
-
*/
|
|
69
|
-
cleanupSessionClient(sessionId) {
|
|
70
|
-
return this.sessionClients.delete(sessionId);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if global client exists
|
|
74
|
-
*/
|
|
75
|
-
hasGlobalClient() {
|
|
76
|
-
return !!this.globalClient;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Check if session client exists
|
|
80
|
-
*/
|
|
81
|
-
hasSessionClient(sessionId) {
|
|
82
|
-
return this.sessionClients.has(sessionId);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get auth token for client creation
|
|
86
|
-
*/
|
|
87
|
-
getAuthToken(config) {
|
|
88
|
-
// Priority: session token > environment token
|
|
89
|
-
if (config.sessionToken) {
|
|
90
|
-
return config.sessionToken;
|
|
91
|
-
}
|
|
92
|
-
const authConfigRaw = config.profile.interceptors?.auth;
|
|
93
|
-
if (!authConfigRaw) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
// Handle multi-auth: get primary non-OAuth config
|
|
97
|
-
const authConfigs = Array.isArray(authConfigRaw) ? authConfigRaw : [authConfigRaw];
|
|
98
|
-
const sortedConfigs = authConfigs.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
99
|
-
const authConfig = sortedConfigs.find(c => c.type !== 'oauth');
|
|
100
|
-
if (authConfig && authConfig.value_from_env) {
|
|
101
|
-
return process.env[authConfig.value_from_env];
|
|
102
|
-
}
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Create interceptor chain for client
|
|
107
|
-
*/
|
|
108
|
-
createInterceptorChain(config) {
|
|
109
|
-
const token = this.getAuthToken(config);
|
|
110
|
-
return new InterceptorChain(config.profile.interceptors || {}, token);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Validate client configuration
|
|
114
|
-
*/
|
|
115
|
-
validateClientConfig(config) {
|
|
116
|
-
if (!config.baseUrl) {
|
|
117
|
-
throw new ConfigurationError('Base URL is required for HTTP client');
|
|
118
|
-
}
|
|
119
|
-
if (!config.profile) {
|
|
120
|
-
throw new ConfigurationError('Profile is required for HTTP client');
|
|
121
|
-
}
|
|
122
|
-
// Check if we have any auth token available
|
|
123
|
-
const hasToken = this.getAuthToken(config);
|
|
124
|
-
if (!hasToken && config.profile.interceptors?.auth) {
|
|
125
|
-
const authConfigRaw = config.profile.interceptors.auth;
|
|
126
|
-
const authConfigs = Array.isArray(authConfigRaw) ? authConfigRaw : [authConfigRaw];
|
|
127
|
-
const nonOAuthConfig = authConfigs.find(c => c.type !== 'oauth');
|
|
128
|
-
const envVar = nonOAuthConfig?.value_from_env || 'MCP4_API_TOKEN';
|
|
129
|
-
throw new AuthenticationError(`No auth token available. Expected token in Authorization header or ${envVar} env var`, { envVar });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=http-client-factory.js.map
|