mcp4openapi 0.1.0 → 0.2.1
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 +137 -95
- package/dist/scripts/validate-profile.js +3 -3
- package/dist/scripts/validate-profile.js.map +1 -1
- package/dist/src/composite-executor.d.ts +3 -1
- package/dist/src/composite-executor.d.ts.map +1 -1
- package/dist/src/composite-executor.js +16 -5
- package/dist/src/composite-executor.js.map +1 -1
- package/dist/src/constants.d.ts +49 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +49 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +13 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/generated-schemas.d.ts +832 -52
- package/dist/src/generated-schemas.d.ts.map +1 -1
- package/dist/src/generated-schemas.js +31 -8
- package/dist/src/generated-schemas.js.map +1 -1
- package/dist/src/http-client-factory.d.ts.map +1 -1
- package/dist/src/http-client-factory.js +14 -3
- package/dist/src/http-client-factory.js.map +1 -1
- package/dist/src/http-transport.d.ts +65 -0
- package/dist/src/http-transport.d.ts.map +1 -1
- package/dist/src/http-transport.js +921 -77
- package/dist/src/http-transport.js.map +1 -1
- package/dist/src/index.js +108 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/interceptors.d.ts +3 -0
- package/dist/src/interceptors.d.ts.map +1 -1
- package/dist/src/interceptors.js +76 -8
- package/dist/src/interceptors.js.map +1 -1
- package/dist/src/logger.d.ts +1 -1
- package/dist/src/logger.js +3 -3
- package/dist/src/logger.js.map +1 -1
- package/dist/src/mcp-server.d.ts +33 -0
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +263 -54
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/oauth-provider.d.ts +92 -0
- package/dist/src/oauth-provider.d.ts.map +1 -0
- package/dist/src/oauth-provider.js +588 -0
- package/dist/src/oauth-provider.js.map +1 -0
- package/dist/src/openapi-parser.d.ts +16 -0
- package/dist/src/openapi-parser.d.ts.map +1 -1
- package/dist/src/openapi-parser.js +141 -6
- package/dist/src/openapi-parser.js.map +1 -1
- package/dist/src/profile-loader.d.ts +2 -2
- package/dist/src/profile-loader.d.ts.map +1 -1
- package/dist/src/profile-loader.js +45 -24
- package/dist/src/profile-loader.js.map +1 -1
- package/dist/src/testing/fixtures.d.ts +189 -0
- package/dist/src/testing/fixtures.d.ts.map +1 -1
- package/dist/src/testing/fixtures.js +144 -0
- package/dist/src/testing/fixtures.js.map +1 -1
- package/dist/src/testing/mock-gitlab-server.d.ts +26 -17
- package/dist/src/testing/mock-gitlab-server.d.ts.map +1 -1
- package/dist/src/testing/mock-gitlab-server.js +567 -304
- package/dist/src/testing/mock-gitlab-server.js.map +1 -1
- package/dist/src/types/http-transport.d.ts +16 -0
- package/dist/src/types/http-transport.d.ts.map +1 -1
- package/dist/src/types/openapi.d.ts +5 -0
- package/dist/src/types/openapi.d.ts.map +1 -1
- package/dist/src/types/profile.d.ts +112 -3
- package/dist/src/types/profile.d.ts.map +1 -1
- package/dist/src/validation-utils.d.ts +12 -0
- package/dist/src/validation-utils.d.ts.map +1 -1
- package/dist/src/validation-utils.js +17 -0
- package/dist/src/validation-utils.js.map +1 -1
- package/package.json +12 -3
- package/profile-schema.json +169 -7
- package/dist/composite-executor.d.ts +0 -65
- package/dist/composite-executor.d.ts.map +0 -1
- package/dist/composite-executor.js +0 -147
- package/dist/composite-executor.js.map +0 -1
- package/dist/constants.d.ts +0 -36
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -36
- package/dist/constants.js.map +0 -1
- package/dist/http-transport.d.ts +0 -195
- package/dist/http-transport.d.ts.map +0 -1
- package/dist/http-transport.js +0 -760
- package/dist/http-transport.js.map +0 -1
- package/dist/interceptors.d.ts +0 -74
- package/dist/interceptors.d.ts.map +0 -1
- package/dist/interceptors.js +0 -220
- package/dist/interceptors.js.map +0 -1
- package/dist/logger.d.ts +0 -81
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -264
- package/dist/logger.js.map +0 -1
- package/dist/mcp-server.d.ts +0 -110
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -568
- package/dist/mcp-server.js.map +0 -1
- package/dist/metrics.d.ts +0 -86
- package/dist/metrics.d.ts.map +0 -1
- package/dist/metrics.js +0 -229
- package/dist/metrics.js.map +0 -1
- package/dist/openapi-parser.d.ts +0 -35
- package/dist/openapi-parser.d.ts.map +0 -1
- package/dist/openapi-parser.js +0 -160
- package/dist/openapi-parser.js.map +0 -1
- package/dist/profile-loader.d.ts +0 -25
- package/dist/profile-loader.d.ts.map +0 -1
- package/dist/profile-loader.js +0 -134
- package/dist/profile-loader.js.map +0 -1
- package/dist/schema-validator.d.ts +0 -32
- package/dist/schema-validator.d.ts.map +0 -1
- package/dist/schema-validator.js +0 -126
- package/dist/schema-validator.js.map +0 -1
- package/dist/testing/fixtures.d.ts +0 -186
- package/dist/testing/fixtures.d.ts.map +0 -1
- package/dist/testing/fixtures.js +0 -135
- package/dist/testing/fixtures.js.map +0 -1
- package/dist/testing/http-integration.test.d.ts +0 -7
- package/dist/testing/http-integration.test.d.ts.map +0 -1
- package/dist/testing/http-integration.test.js +0 -383
- package/dist/testing/http-integration.test.js.map +0 -1
- package/dist/testing/http-multiuser.test.d.ts +0 -10
- package/dist/testing/http-multiuser.test.d.ts.map +0 -1
- package/dist/testing/http-multiuser.test.js +0 -255
- package/dist/testing/http-multiuser.test.js.map +0 -1
- package/dist/testing/integration.test.d.ts +0 -8
- package/dist/testing/integration.test.d.ts.map +0 -1
- package/dist/testing/integration.test.js +0 -247
- package/dist/testing/integration.test.js.map +0 -1
- package/dist/testing/mock-gitlab-server.d.ts +0 -34
- package/dist/testing/mock-gitlab-server.d.ts.map +0 -1
- package/dist/testing/mock-gitlab-server.js +0 -224
- package/dist/testing/mock-gitlab-server.js.map +0 -1
- package/dist/testing/test-types.d.ts +0 -59
- package/dist/testing/test-types.d.ts.map +0 -1
- package/dist/testing/test-types.js +0 -7
- package/dist/testing/test-types.js.map +0 -1
- package/dist/tool-generator.d.ts +0 -43
- package/dist/tool-generator.d.ts.map +0 -1
- package/dist/tool-generator.js +0 -123
- package/dist/tool-generator.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/http-transport.d.ts +0 -39
- package/dist/types/http-transport.d.ts.map +0 -1
- package/dist/types/http-transport.js +0 -8
- package/dist/types/http-transport.js.map +0 -1
- package/dist/types/openapi.d.ts +0 -50
- package/dist/types/openapi.d.ts.map +0 -1
- package/dist/types/openapi.js +0 -9
- package/dist/types/openapi.js.map +0 -1
- package/dist/types/profile.d.ts +0 -76
- package/dist/types/profile.d.ts.map +0 -1
- package/dist/types/profile.js +0 -9
- package/dist/types/profile.js.map +0 -1
package/dist/mcp-server.js
DELETED
|
@@ -1,568 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main MCP server implementation
|
|
3
|
-
*
|
|
4
|
-
* Why: Coordinates OpenAPI parser, profile loader, tool generator, and request execution.
|
|
5
|
-
* Single entry point for tool registration and invocation.
|
|
6
|
-
*/
|
|
7
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
-
import { OpenAPIParser } from './openapi-parser.js';
|
|
11
|
-
import { ProfileLoader } from './profile-loader.js';
|
|
12
|
-
import { ToolGenerator } from './tool-generator.js';
|
|
13
|
-
import { CompositeExecutor } from './composite-executor.js';
|
|
14
|
-
import { InterceptorChain, HttpClient } from './interceptors.js';
|
|
15
|
-
import { SchemaValidator } from './schema-validator.js';
|
|
16
|
-
import { ConsoleLogger, JsonLogger } from './logger.js';
|
|
17
|
-
export class MCPServer {
|
|
18
|
-
server;
|
|
19
|
-
parser;
|
|
20
|
-
profile;
|
|
21
|
-
toolGenerator;
|
|
22
|
-
httpClient;
|
|
23
|
-
compositeExecutor;
|
|
24
|
-
schemaValidator;
|
|
25
|
-
logger;
|
|
26
|
-
httpTransport = null;
|
|
27
|
-
sessionHttpClients = new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Filter response object to include only specified fields
|
|
30
|
-
* Supports nested objects but keeps first level of arrays
|
|
31
|
-
*/
|
|
32
|
-
filterFields(data, fields) {
|
|
33
|
-
if (!data || typeof data !== 'object') {
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(data)) {
|
|
37
|
-
return data.map(item => this.filterFields(item, fields));
|
|
38
|
-
}
|
|
39
|
-
const filtered = {};
|
|
40
|
-
for (const field of fields) {
|
|
41
|
-
if (field in data) {
|
|
42
|
-
filtered[field] = data[field];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return filtered;
|
|
46
|
-
}
|
|
47
|
-
constructor(logger) {
|
|
48
|
-
this.logger = logger || new ConsoleLogger();
|
|
49
|
-
this.schemaValidator = new SchemaValidator();
|
|
50
|
-
this.server = new Server({
|
|
51
|
-
name: 'mcp-from-openapi',
|
|
52
|
-
version: '0.1.0',
|
|
53
|
-
}, {
|
|
54
|
-
capabilities: {
|
|
55
|
-
tools: {},
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
this.parser = new OpenAPIParser();
|
|
59
|
-
this.toolGenerator = new ToolGenerator(this.parser);
|
|
60
|
-
this.setupHandlers();
|
|
61
|
-
}
|
|
62
|
-
async initialize(specPath, profilePath) {
|
|
63
|
-
// Load OpenAPI spec
|
|
64
|
-
await this.parser.load(specPath);
|
|
65
|
-
this.logger.info('Loaded OpenAPI spec', { specPath });
|
|
66
|
-
// Load profile
|
|
67
|
-
if (profilePath) {
|
|
68
|
-
const loader = new ProfileLoader();
|
|
69
|
-
this.profile = await loader.load(profilePath);
|
|
70
|
-
this.logger.info('Loaded profile', {
|
|
71
|
-
profile: this.profile.profile_name,
|
|
72
|
-
toolCount: this.profile.tools.length,
|
|
73
|
-
});
|
|
74
|
-
// DEBUG: Check response_fields
|
|
75
|
-
const groupsTool = this.profile.tools.find(t => t.name === 'manage_groups');
|
|
76
|
-
this.logger.info('[DEBUG] manage_groups tool', {
|
|
77
|
-
hasResponseFields: !!groupsTool?.response_fields,
|
|
78
|
-
responseFields: groupsTool?.response_fields
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this.profile = ProfileLoader.createDefaultProfile('default');
|
|
83
|
-
this.logger.warn('Using default profile (no profile specified)');
|
|
84
|
-
}
|
|
85
|
-
// Re-create logger with auth config for token redaction
|
|
86
|
-
if (this.profile.interceptors?.auth) {
|
|
87
|
-
this.logger = this.createLoggerWithAuth(this.profile.interceptors.auth);
|
|
88
|
-
this.logger.info('Logger re-configured with auth token redaction');
|
|
89
|
-
}
|
|
90
|
-
// Setup HTTP client with interceptors
|
|
91
|
-
// For stdio transport, create client with env token
|
|
92
|
-
// For HTTP transport, clients are created per-session with user's token
|
|
93
|
-
const baseUrl = this.getBaseUrl();
|
|
94
|
-
if (this.profile.interceptors?.auth) {
|
|
95
|
-
const envToken = process.env[this.profile.interceptors.auth.value_from_env];
|
|
96
|
-
if (envToken) {
|
|
97
|
-
// Token available in env - create global client (stdio transport)
|
|
98
|
-
const interceptors = new InterceptorChain(this.profile.interceptors);
|
|
99
|
-
this.httpClient = new HttpClient(baseUrl, interceptors);
|
|
100
|
-
this.compositeExecutor = new CompositeExecutor(this.parser, this.httpClient);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
// No env token - will use per-session clients (HTTP transport)
|
|
104
|
-
this.compositeExecutor = new CompositeExecutor(this.parser);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
// No auth configured
|
|
109
|
-
const interceptors = new InterceptorChain(this.profile.interceptors || {});
|
|
110
|
-
this.httpClient = new HttpClient(baseUrl, interceptors);
|
|
111
|
-
this.compositeExecutor = new CompositeExecutor(this.parser, this.httpClient);
|
|
112
|
-
}
|
|
113
|
-
this.logger.info('MCP server initialized', {
|
|
114
|
-
baseUrl,
|
|
115
|
-
toolCount: this.profile.tools.length,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Create logger with auth configuration for token redaction
|
|
120
|
-
*
|
|
121
|
-
* Why: Prevents sensitive tokens from appearing in logs
|
|
122
|
-
*/
|
|
123
|
-
createLoggerWithAuth(authConfig) {
|
|
124
|
-
const logFormat = process.env.LOG_FORMAT || 'console';
|
|
125
|
-
const logLevel = this.logger instanceof ConsoleLogger || this.logger instanceof JsonLogger
|
|
126
|
-
? this.logger.level
|
|
127
|
-
: undefined;
|
|
128
|
-
return logFormat === 'json'
|
|
129
|
-
? new JsonLogger(logLevel, authConfig)
|
|
130
|
-
: new ConsoleLogger(logLevel, authConfig);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get base URL from profile config or OpenAPI spec
|
|
134
|
-
*/
|
|
135
|
-
getBaseUrl() {
|
|
136
|
-
const baseUrlConfig = this.profile?.interceptors?.base_url;
|
|
137
|
-
if (baseUrlConfig) {
|
|
138
|
-
const envValue = process.env[baseUrlConfig.value_from_env];
|
|
139
|
-
if (envValue)
|
|
140
|
-
return envValue;
|
|
141
|
-
if (baseUrlConfig.default)
|
|
142
|
-
return baseUrlConfig.default;
|
|
143
|
-
}
|
|
144
|
-
return this.parser.getBaseUrl();
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Get or create HTTP client for session
|
|
148
|
-
*/
|
|
149
|
-
getHttpClientForSession(sessionId) {
|
|
150
|
-
if (!sessionId) {
|
|
151
|
-
// Fallback to global client for stdio transport
|
|
152
|
-
if (!this.httpClient) {
|
|
153
|
-
const hasHttpTransport = !!this.httpTransport;
|
|
154
|
-
const transport = hasHttpTransport ? 'http' : 'stdio';
|
|
155
|
-
const authConfig = this.profile?.interceptors?.auth;
|
|
156
|
-
const envVarName = authConfig?.value_from_env || 'API_TOKEN';
|
|
157
|
-
const hasEnvToken = !!process.env[envVarName];
|
|
158
|
-
throw new Error(`HTTP client not initialized. ` +
|
|
159
|
-
`Transport: ${transport}, ` +
|
|
160
|
-
`HasEnvToken(${envVarName}): ${hasEnvToken}, ` +
|
|
161
|
-
`Suggestion: ${hasHttpTransport
|
|
162
|
-
? 'Send token in Authorization header during initialization'
|
|
163
|
-
: `Set ${envVarName} environment variable`}`);
|
|
164
|
-
}
|
|
165
|
-
return this.httpClient;
|
|
166
|
-
}
|
|
167
|
-
// Check cache first
|
|
168
|
-
let client = this.sessionHttpClients.get(sessionId);
|
|
169
|
-
if (client) {
|
|
170
|
-
return client;
|
|
171
|
-
}
|
|
172
|
-
// Get auth token from session or env
|
|
173
|
-
const authToken = this.getAuthTokenFromSession(sessionId);
|
|
174
|
-
const envToken = this.profile?.interceptors?.auth
|
|
175
|
-
? process.env[this.profile.interceptors.auth.value_from_env]
|
|
176
|
-
: undefined;
|
|
177
|
-
if (!authToken && !envToken) {
|
|
178
|
-
const authConfig = this.profile?.interceptors?.auth;
|
|
179
|
-
const expectedEnvVar = authConfig?.value_from_env || 'API_TOKEN';
|
|
180
|
-
throw new Error(`No auth token found for session ${sessionId}. ` +
|
|
181
|
-
`Expected token in Authorization/X-API-Token header or ${expectedEnvVar} env var`);
|
|
182
|
-
}
|
|
183
|
-
// Create new client with session-specific interceptor
|
|
184
|
-
if (!this.profile) {
|
|
185
|
-
throw new Error('Profile not initialized');
|
|
186
|
-
}
|
|
187
|
-
const baseUrl = this.getBaseUrl();
|
|
188
|
-
const tokenToUse = authToken || envToken;
|
|
189
|
-
const interceptors = new InterceptorChain(this.profile.interceptors || {}, tokenToUse);
|
|
190
|
-
const newClient = new HttpClient(baseUrl, interceptors);
|
|
191
|
-
// Double-check: Another concurrent request might have created client
|
|
192
|
-
// Race condition prevention: Use first client that was set
|
|
193
|
-
const existingClient = this.sessionHttpClients.get(sessionId);
|
|
194
|
-
if (existingClient) {
|
|
195
|
-
// Another request won the race, use its client
|
|
196
|
-
return existingClient;
|
|
197
|
-
}
|
|
198
|
-
// We won the race, cache our client
|
|
199
|
-
this.sessionHttpClients.set(sessionId, newClient);
|
|
200
|
-
return newClient;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Get auth token from HTTP transport session
|
|
204
|
-
*/
|
|
205
|
-
getAuthTokenFromSession(sessionId) {
|
|
206
|
-
if (!this.httpTransport) {
|
|
207
|
-
return undefined;
|
|
208
|
-
}
|
|
209
|
-
// Use public API instead of type casting
|
|
210
|
-
return this.httpTransport.getSessionToken(sessionId);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Cleanup HTTP client for destroyed session
|
|
214
|
-
*
|
|
215
|
-
* Why: Prevent memory leak - sessions expire but cached clients stay forever
|
|
216
|
-
*/
|
|
217
|
-
cleanupSessionClient(sessionId) {
|
|
218
|
-
const removed = this.sessionHttpClients.delete(sessionId);
|
|
219
|
-
if (removed) {
|
|
220
|
-
this.logger.info('Cleaned up session HTTP client', { sessionId });
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Setup MCP request handlers
|
|
225
|
-
*/
|
|
226
|
-
setupHandlers() {
|
|
227
|
-
// List available tools
|
|
228
|
-
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
229
|
-
if (!this.profile) {
|
|
230
|
-
throw new Error('Server not initialized');
|
|
231
|
-
}
|
|
232
|
-
const tools = this.profile.tools.map(toolDef => this.toolGenerator.generateTool(toolDef));
|
|
233
|
-
return { tools };
|
|
234
|
-
});
|
|
235
|
-
// Execute tool
|
|
236
|
-
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
237
|
-
if (!this.profile || !this.httpClient || !this.compositeExecutor) {
|
|
238
|
-
throw new Error('Server not initialized');
|
|
239
|
-
}
|
|
240
|
-
const toolDef = this.profile.tools.find(t => t.name === request.params.name);
|
|
241
|
-
if (!toolDef) {
|
|
242
|
-
throw new Error(`Tool not found: ${request.params.name}`);
|
|
243
|
-
}
|
|
244
|
-
const args = request.params.arguments || {};
|
|
245
|
-
// Validate arguments
|
|
246
|
-
this.toolGenerator.validateArguments(toolDef, args);
|
|
247
|
-
// Execute composite or simple tool
|
|
248
|
-
let result;
|
|
249
|
-
if (toolDef.composite && toolDef.steps) {
|
|
250
|
-
const compositeResult = await this.compositeExecutor.execute(toolDef.steps, args, toolDef.partial_results || false);
|
|
251
|
-
// Include metadata about completion
|
|
252
|
-
result = {
|
|
253
|
-
...compositeResult.data,
|
|
254
|
-
_metadata: {
|
|
255
|
-
completed_steps: compositeResult.completed_steps,
|
|
256
|
-
total_steps: compositeResult.total_steps,
|
|
257
|
-
success: compositeResult.completed_steps === compositeResult.total_steps,
|
|
258
|
-
errors: compositeResult.errors,
|
|
259
|
-
},
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
result = await this.executeSimpleTool(toolDef, args);
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
content: [
|
|
267
|
-
{
|
|
268
|
-
type: 'text',
|
|
269
|
-
text: JSON.stringify(result, null, 2),
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
};
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Execute simple (non-composite) tool
|
|
277
|
-
*
|
|
278
|
-
* Why separate: Simple tools map directly to single OpenAPI operation.
|
|
279
|
-
* No result aggregation needed.
|
|
280
|
-
*/
|
|
281
|
-
async executeSimpleTool(toolDef, args, sessionId) {
|
|
282
|
-
// DEBUG: Check if response_fields is present
|
|
283
|
-
this.logger.info('[DEBUG] executeSimpleTool', {
|
|
284
|
-
toolName: toolDef.name,
|
|
285
|
-
action: args.action,
|
|
286
|
-
hasResponseFields: !!toolDef.response_fields,
|
|
287
|
-
responseFields: toolDef.response_fields
|
|
288
|
-
});
|
|
289
|
-
const operationId = this.toolGenerator.mapActionToOperation(toolDef, args);
|
|
290
|
-
if (!operationId) {
|
|
291
|
-
throw new Error(`Could not map tool action to operation`);
|
|
292
|
-
}
|
|
293
|
-
const operation = this.parser.getOperation(operationId);
|
|
294
|
-
if (!operation) {
|
|
295
|
-
throw new Error(`Operation not found: ${operationId}`);
|
|
296
|
-
}
|
|
297
|
-
// Build request
|
|
298
|
-
const path = this.resolvePath(operation.path, args);
|
|
299
|
-
const queryParams = this.extractQueryParams(operation, args);
|
|
300
|
-
const body = this.extractBody(operation, args, toolDef);
|
|
301
|
-
// Validate request body against schema
|
|
302
|
-
if (body && operation.requestBody) {
|
|
303
|
-
const validationResult = this.schemaValidator.validateRequestBody(operation, body);
|
|
304
|
-
if (!validationResult.valid && validationResult.errors) {
|
|
305
|
-
const errorDetails = validationResult.errors
|
|
306
|
-
.map(e => ` - ${e.path}: ${e.message}`)
|
|
307
|
-
.join('\n');
|
|
308
|
-
throw new Error(`Request body validation failed:\n${errorDetails}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// Execute with session-specific client
|
|
312
|
-
const httpClient = this.getHttpClientForSession(sessionId);
|
|
313
|
-
const response = await httpClient.request(operation.method, path, {
|
|
314
|
-
params: queryParams,
|
|
315
|
-
body,
|
|
316
|
-
});
|
|
317
|
-
// Apply response field filtering if configured
|
|
318
|
-
let result = response.body;
|
|
319
|
-
if (toolDef.response_fields) {
|
|
320
|
-
const action = args.action;
|
|
321
|
-
if (action && toolDef.response_fields[action]) {
|
|
322
|
-
const fields = toolDef.response_fields[action];
|
|
323
|
-
result = this.filterFields(result, fields);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Resolve path parameters using profile aliases
|
|
330
|
-
*
|
|
331
|
-
* Why aliases: Different tools may use different parameter names for same path param.
|
|
332
|
-
* Example: GitLab uses "resource_id", "project_id", "group_id" all mapping to "{id}"
|
|
333
|
-
*/
|
|
334
|
-
resolvePath(template, args) {
|
|
335
|
-
const aliases = this.profile?.parameter_aliases || {};
|
|
336
|
-
return template.replace(/\{(\w+)\}/g, (_, key) => {
|
|
337
|
-
// Try direct match first
|
|
338
|
-
if (args[key] !== undefined) {
|
|
339
|
-
return String(args[key]);
|
|
340
|
-
}
|
|
341
|
-
// Try aliases from profile
|
|
342
|
-
const possibleAliases = aliases[key] || [];
|
|
343
|
-
for (const alias of possibleAliases) {
|
|
344
|
-
if (args[alias] !== undefined) {
|
|
345
|
-
return String(args[alias]);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
throw new Error(`Missing path parameter: ${key}` +
|
|
349
|
-
(possibleAliases.length > 0 ? `. Tried aliases: ${possibleAliases.join(', ')}` : ''));
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Extract query parameters from args
|
|
354
|
-
*
|
|
355
|
-
* Why: Separate query params from body params. Array handling is done by HttpClient
|
|
356
|
-
* based on profile's array_format setting.
|
|
357
|
-
*/
|
|
358
|
-
extractQueryParams(operation, args) {
|
|
359
|
-
const params = {};
|
|
360
|
-
for (const param of operation.parameters) {
|
|
361
|
-
if (param.in === 'query' && args[param.name] !== undefined) {
|
|
362
|
-
const value = args[param.name];
|
|
363
|
-
// Pass arrays as-is, HttpClient will serialize based on array_format
|
|
364
|
-
if (Array.isArray(value)) {
|
|
365
|
-
params[param.name] = value.map(String);
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
params[param.name] = String(value);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return params;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Extract request body from args
|
|
376
|
-
*
|
|
377
|
-
* Why: For create/update operations, collect non-metadata fields into body.
|
|
378
|
-
* Metadata (action, resource_type, etc.) are not sent to API.
|
|
379
|
-
* Path/query parameters are also excluded from body.
|
|
380
|
-
*
|
|
381
|
-
* Uses metadata_params from tool definition, defaults to ['action', 'resource_type']
|
|
382
|
-
*/
|
|
383
|
-
extractBody(operation, args, toolDef) {
|
|
384
|
-
// Metadata fields from tool definition (or defaults)
|
|
385
|
-
const metadataList = toolDef.metadata_params || ['action', 'resource_type'];
|
|
386
|
-
const metadata = new Set(metadataList);
|
|
387
|
-
// Collect parameter names that go in path or query
|
|
388
|
-
const pathOrQuery = new Set();
|
|
389
|
-
for (const param of operation.parameters) {
|
|
390
|
-
if (param.in === 'path' || param.in === 'query') {
|
|
391
|
-
pathOrQuery.add(param.name);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
const body = {};
|
|
395
|
-
let hasBody = false;
|
|
396
|
-
for (const [key, value] of Object.entries(args)) {
|
|
397
|
-
if (!metadata.has(key) && !pathOrQuery.has(key) && value !== undefined) {
|
|
398
|
-
body[key] = value;
|
|
399
|
-
hasBody = true;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return hasBody ? body : undefined;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Start server with stdio transport
|
|
406
|
-
*/
|
|
407
|
-
async runStdio() {
|
|
408
|
-
const transport = new StdioServerTransport();
|
|
409
|
-
await this.server.connect(transport);
|
|
410
|
-
this.logger.info('MCP server running on stdio');
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Start server with HTTP transport
|
|
414
|
-
*
|
|
415
|
-
* Implements MCP Specification 2025-03-26 Streamable HTTP transport
|
|
416
|
-
*
|
|
417
|
-
* Why: Enables remote MCP server access with SSE streaming, session management,
|
|
418
|
-
* and resumability for reliable communication over HTTP.
|
|
419
|
-
*/
|
|
420
|
-
async runHttp(host, port) {
|
|
421
|
-
const { HttpTransport } = await import('./http-transport.js');
|
|
422
|
-
const config = {
|
|
423
|
-
host,
|
|
424
|
-
port,
|
|
425
|
-
sessionTimeoutMs: parseInt(process.env.SESSION_TIMEOUT_MS || '1800000', 10),
|
|
426
|
-
heartbeatEnabled: process.env.HEARTBEAT_ENABLED === 'true',
|
|
427
|
-
heartbeatIntervalMs: parseInt(process.env.HEARTBEAT_INTERVAL_MS || '30000', 10),
|
|
428
|
-
metricsEnabled: process.env.METRICS_ENABLED === 'true',
|
|
429
|
-
metricsPath: process.env.METRICS_PATH || '/metrics',
|
|
430
|
-
allowedOrigins: process.env.ALLOWED_ORIGINS
|
|
431
|
-
? process.env.ALLOWED_ORIGINS.split(',').map(o => o.trim())
|
|
432
|
-
: undefined,
|
|
433
|
-
};
|
|
434
|
-
this.httpTransport = new HttpTransport(config, this.logger);
|
|
435
|
-
// Set message handler to process JSON-RPC messages
|
|
436
|
-
this.httpTransport.setMessageHandler(async (message, sessionId) => {
|
|
437
|
-
return await this.handleJsonRpcMessage(message, sessionId);
|
|
438
|
-
});
|
|
439
|
-
// Register cleanup listener for session destruction (memory leak prevention)
|
|
440
|
-
this.httpTransport.onSessionDestroyed((sessionId) => {
|
|
441
|
-
this.cleanupSessionClient(sessionId);
|
|
442
|
-
});
|
|
443
|
-
await this.httpTransport.start();
|
|
444
|
-
this.logger.info('MCP server running on HTTP', { host, port });
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Handle JSON-RPC message from HTTP transport
|
|
448
|
-
*
|
|
449
|
-
* Why: Unified message handling for both stdio and HTTP transports
|
|
450
|
-
*/
|
|
451
|
-
async handleJsonRpcMessage(message, sessionId) {
|
|
452
|
-
// Handle initialize
|
|
453
|
-
if (this.isInitializeRequest(message)) {
|
|
454
|
-
return this.handleInitialize(message);
|
|
455
|
-
}
|
|
456
|
-
// Handle tool calls
|
|
457
|
-
if (this.isToolCallRequest(message)) {
|
|
458
|
-
return await this.handleToolCall(message, sessionId);
|
|
459
|
-
}
|
|
460
|
-
// Handle other JSON-RPC requests
|
|
461
|
-
// (tools/list, prompts/list, etc.)
|
|
462
|
-
return this.handleOtherRequest(message);
|
|
463
|
-
}
|
|
464
|
-
isInitializeRequest(message) {
|
|
465
|
-
if (typeof message !== 'object' || message === null)
|
|
466
|
-
return false;
|
|
467
|
-
const req = message;
|
|
468
|
-
return req.method === 'initialize';
|
|
469
|
-
}
|
|
470
|
-
isToolCallRequest(message) {
|
|
471
|
-
if (typeof message !== 'object' || message === null)
|
|
472
|
-
return false;
|
|
473
|
-
const req = message;
|
|
474
|
-
return req.method === 'tools/call';
|
|
475
|
-
}
|
|
476
|
-
handleInitialize(message) {
|
|
477
|
-
const req = message;
|
|
478
|
-
return {
|
|
479
|
-
jsonrpc: '2.0',
|
|
480
|
-
id: req.id,
|
|
481
|
-
result: {
|
|
482
|
-
protocolVersion: '2025-03-26',
|
|
483
|
-
serverInfo: {
|
|
484
|
-
name: 'mcp-from-openapi',
|
|
485
|
-
version: '0.1.0',
|
|
486
|
-
},
|
|
487
|
-
capabilities: {
|
|
488
|
-
tools: {},
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
async handleToolCall(message, sessionId) {
|
|
494
|
-
const req = message;
|
|
495
|
-
const params = req.params;
|
|
496
|
-
const toolName = params.name;
|
|
497
|
-
const args = params.arguments;
|
|
498
|
-
try {
|
|
499
|
-
// Find tool definition
|
|
500
|
-
const toolDef = this.profile?.tools.find(t => t.name === toolName);
|
|
501
|
-
if (!toolDef) {
|
|
502
|
-
throw new Error(`Tool not found: ${toolName}`);
|
|
503
|
-
}
|
|
504
|
-
// Execute tool (reuse existing execution logic)
|
|
505
|
-
let result;
|
|
506
|
-
if (toolDef.composite && toolDef.steps) {
|
|
507
|
-
const httpClient = this.getHttpClientForSession(sessionId);
|
|
508
|
-
const compositeResult = await this.compositeExecutor.execute(toolDef.steps, args, toolDef.partial_results || false, httpClient);
|
|
509
|
-
result = {
|
|
510
|
-
data: compositeResult.data,
|
|
511
|
-
completed_steps: compositeResult.completed_steps,
|
|
512
|
-
total_steps: compositeResult.total_steps,
|
|
513
|
-
success: compositeResult.completed_steps === compositeResult.total_steps,
|
|
514
|
-
errors: compositeResult.errors,
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
result = await this.executeSimpleTool(toolDef, args, sessionId);
|
|
519
|
-
}
|
|
520
|
-
return {
|
|
521
|
-
jsonrpc: '2.0',
|
|
522
|
-
id: req.id,
|
|
523
|
-
result: {
|
|
524
|
-
content: [
|
|
525
|
-
{
|
|
526
|
-
type: 'text',
|
|
527
|
-
text: JSON.stringify(result, null, 2),
|
|
528
|
-
},
|
|
529
|
-
],
|
|
530
|
-
},
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
catch (error) {
|
|
534
|
-
return {
|
|
535
|
-
jsonrpc: '2.0',
|
|
536
|
-
id: req.id,
|
|
537
|
-
error: {
|
|
538
|
-
code: -32603,
|
|
539
|
-
message: error.message,
|
|
540
|
-
},
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
handleOtherRequest(message) {
|
|
545
|
-
const req = message;
|
|
546
|
-
// Handle tools/list
|
|
547
|
-
if (req.method === 'tools/list') {
|
|
548
|
-
const tools = this.profile?.tools.map(toolDef => this.toolGenerator.generateTool(toolDef)) || [];
|
|
549
|
-
return {
|
|
550
|
-
jsonrpc: '2.0',
|
|
551
|
-
id: req.id,
|
|
552
|
-
result: {
|
|
553
|
-
tools,
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
// Unknown method
|
|
558
|
-
return {
|
|
559
|
-
jsonrpc: '2.0',
|
|
560
|
-
id: req.id,
|
|
561
|
-
error: {
|
|
562
|
-
code: -32601,
|
|
563
|
-
message: `Method not found: ${req.method}`,
|
|
564
|
-
},
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
//# sourceMappingURL=mcp-server.js.map
|
package/dist/mcp-server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;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AC,CAC1C,IAAI,EAAE,CAAC;YAER,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,MAAM,EAAE;oBACN,KAAK;iBACN;aACF,CAAC;QACJ,CAAC;QAED,iBAAiB;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,CAAC,KAAK;gBACZ,OAAO,EAAE,qBAAqB,GAAG,CAAC,MAAM,EAAE;aAC3C;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/metrics.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prometheus Metrics Collector
|
|
3
|
-
*
|
|
4
|
-
* Why: Observability for production deployments
|
|
5
|
-
*
|
|
6
|
-
* Tracks:
|
|
7
|
-
* - HTTP requests (status, method, path)
|
|
8
|
-
* - Session lifecycle (active, created, destroyed)
|
|
9
|
-
* - MCP operations (tool calls, duration, errors)
|
|
10
|
-
* - API calls to backend (operation, status, duration)
|
|
11
|
-
*/
|
|
12
|
-
import { Registry } from 'prom-client';
|
|
13
|
-
export interface MetricsCollectorConfig {
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
prefix?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare class MetricsCollector {
|
|
18
|
-
private registry;
|
|
19
|
-
private enabled;
|
|
20
|
-
private httpRequestsTotal;
|
|
21
|
-
private httpRequestDuration;
|
|
22
|
-
private sessionsActive;
|
|
23
|
-
private sessionsCreatedTotal;
|
|
24
|
-
private sessionsDestroyedTotal;
|
|
25
|
-
private mcpToolCallsTotal;
|
|
26
|
-
private mcpToolCallDuration;
|
|
27
|
-
private mcpToolCallErrors;
|
|
28
|
-
private apiCallsTotal;
|
|
29
|
-
private apiCallDuration;
|
|
30
|
-
private apiCallErrors;
|
|
31
|
-
constructor(config: MetricsCollectorConfig);
|
|
32
|
-
/**
|
|
33
|
-
* Record HTTP request
|
|
34
|
-
*/
|
|
35
|
-
recordHttpRequest(method: string, path: string, status: number, durationSeconds: number): void;
|
|
36
|
-
/**
|
|
37
|
-
* Record session created
|
|
38
|
-
*/
|
|
39
|
-
recordSessionCreated(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Record session destroyed
|
|
42
|
-
*/
|
|
43
|
-
recordSessionDestroyed(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Record MCP tool call
|
|
46
|
-
*/
|
|
47
|
-
recordToolCall(tool: string, status: 'success' | 'error', durationSeconds: number): void;
|
|
48
|
-
/**
|
|
49
|
-
* Record MCP tool call error
|
|
50
|
-
*/
|
|
51
|
-
recordToolCallError(tool: string, errorType: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Record API call to backend
|
|
54
|
-
*/
|
|
55
|
-
recordApiCall(operation: string, status: number, durationSeconds: number): void;
|
|
56
|
-
/**
|
|
57
|
-
* Record API call error
|
|
58
|
-
*/
|
|
59
|
-
recordApiCallError(operation: string, errorType: string): void;
|
|
60
|
-
/**
|
|
61
|
-
* Get metrics in Prometheus format
|
|
62
|
-
*/
|
|
63
|
-
getMetrics(): Promise<string>;
|
|
64
|
-
/**
|
|
65
|
-
* Get registry (for testing)
|
|
66
|
-
*/
|
|
67
|
-
getRegistry(): Registry;
|
|
68
|
-
/**
|
|
69
|
-
* Normalize path for metrics (remove dynamic segments)
|
|
70
|
-
*
|
|
71
|
-
* Why: Avoid high cardinality in metrics labels
|
|
72
|
-
*
|
|
73
|
-
* Examples:
|
|
74
|
-
* - /mcp?sessionId=abc123 -> /mcp
|
|
75
|
-
* - /metrics -> /metrics
|
|
76
|
-
* - /health -> /health
|
|
77
|
-
*/
|
|
78
|
-
private normalizePath;
|
|
79
|
-
/**
|
|
80
|
-
* Get status label (2xx, 4xx, 5xx)
|
|
81
|
-
*
|
|
82
|
-
* Why: Group similar statuses to reduce cardinality
|
|
83
|
-
*/
|
|
84
|
-
private getStatusLabel;
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=metrics.d.ts.map
|