Merge 22b1bcceda95bd393324930fbcfe53aeabadf0ff into 4f7417890f8b5e7f441239ed79c2c5091d43c267
This commit is contained in:
commit
5a86b900fa
6
package-lock.json
generated
6
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "openapi-mcp-generator",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "openapi-mcp-generator",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apidevtools/swagger-parser": "^10.1.1",
|
||||
@ -14,7 +14,7 @@
|
||||
"openapi-types": "^12.1.3"
|
||||
},
|
||||
"bin": {
|
||||
"openapi-mcp-generator": "dist/index.js"
|
||||
"openapi-mcp-generator": "bin/openapi-mcp-generator.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.15.2",
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import SwaggerParser from '@apidevtools/swagger-parser';
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
import { extractToolsFromApi } from './parser/extract-tools.js';
|
||||
import { McpToolDefinition } from './types/index.js';
|
||||
import type { McpToolDefinition } from './types/index.js';
|
||||
import { determineBaseUrl } from './utils/url.js';
|
||||
|
||||
/**
|
||||
|
||||
@ -32,7 +32,8 @@ import {
|
||||
import { CliOptions, TransportType } from './types/index.js';
|
||||
|
||||
// Export programmatic API
|
||||
export { getToolsFromOpenApi, McpToolDefinition, GetToolsOptions } from './api.js';
|
||||
export { getToolsFromOpenApi } from './api.js';
|
||||
export type { McpToolDefinition, GetToolsOptions } from './api.js';
|
||||
|
||||
// Configure CLI
|
||||
const program = new Command();
|
||||
@ -84,6 +85,11 @@ program
|
||||
// Export the program object for use in bin stub
|
||||
export { program };
|
||||
|
||||
// Run the program if this file is executed directly
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
program.parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to run the generator
|
||||
*/
|
||||
|
||||
@ -22,6 +22,8 @@ export function extractToolsFromApi(api: OpenAPIV3.Document): McpToolDefinition[
|
||||
for (const [path, pathItem] of Object.entries(api.paths)) {
|
||||
if (!pathItem) continue;
|
||||
|
||||
const pathParameters = pathItem.parameters;
|
||||
|
||||
for (const method of Object.values(OpenAPIV3.HttpMethods)) {
|
||||
const operation = pathItem[method];
|
||||
if (!operation) continue;
|
||||
@ -48,8 +50,10 @@ export function extractToolsFromApi(api: OpenAPIV3.Document): McpToolDefinition[
|
||||
operation.description || operation.summary || `Executes ${method.toUpperCase()} ${path}`;
|
||||
|
||||
// Generate input schema and extract parameters
|
||||
const { inputSchema, parameters, requestBodyContentType } =
|
||||
generateInputSchemaAndDetails(operation);
|
||||
const { inputSchema, parameters, requestBodyContentType } = generateInputSchemaAndDetails(
|
||||
operation,
|
||||
pathParameters
|
||||
);
|
||||
|
||||
// Extract parameter details for execution
|
||||
const executionParameters = parameters.map((p) => ({ name: p.name, in: p.in }));
|
||||
@ -83,7 +87,10 @@ export function extractToolsFromApi(api: OpenAPIV3.Document): McpToolDefinition[
|
||||
* @param operation OpenAPI operation object
|
||||
* @returns Input schema, parameters, and request body content type
|
||||
*/
|
||||
export function generateInputSchemaAndDetails(operation: OpenAPIV3.OperationObject): {
|
||||
export function generateInputSchemaAndDetails(
|
||||
operation: OpenAPIV3.OperationObject,
|
||||
pathParameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
|
||||
): {
|
||||
inputSchema: JSONSchema7 | boolean;
|
||||
parameters: OpenAPIV3.ParameterObject[];
|
||||
requestBodyContentType?: string;
|
||||
@ -91,10 +98,17 @@ export function generateInputSchemaAndDetails(operation: OpenAPIV3.OperationObje
|
||||
const properties: { [key: string]: JSONSchema7 | boolean } = {};
|
||||
const required: string[] = [];
|
||||
|
||||
// Process parameters
|
||||
const allParameters: OpenAPIV3.ParameterObject[] = Array.isArray(operation.parameters)
|
||||
? operation.parameters.map((p) => p as OpenAPIV3.ParameterObject)
|
||||
: [];
|
||||
const allParameters: OpenAPIV3.ParameterObject[] = [];
|
||||
|
||||
// Add Path Item-level params first so that if an Operation-level param with the same name
|
||||
// exists, the Operation-level param overrides the Path Item-level param.
|
||||
if (Array.isArray(pathParameters)) {
|
||||
allParameters.push(...pathParameters.map((p) => p as OpenAPIV3.ParameterObject));
|
||||
}
|
||||
|
||||
if (Array.isArray(operation.parameters)) {
|
||||
allParameters.push(...operation.parameters.map((p) => p as OpenAPIV3.ParameterObject));
|
||||
}
|
||||
|
||||
allParameters.forEach((param) => {
|
||||
if (!param.name || !param.schema) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user