@mcp-apps/api-tools-mcp-server
Version:
MCP server for interacting with APIs and web services
75 lines (73 loc) • 3.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOpenApiEndpointsTool = void 0;
const zod_1 = require("zod");
const openapi_service_1 = require("../services/openapi-service");
const json_utils_1 = require("../utils/json-utils");
exports.getOpenApiEndpointsTool = {
name: 'get_openapi_endpoints',
description: `Lists all available endpoints from an OpenAPI schema.
This tool extracts and returns all paths/endpoints defined in an OpenAPI schema,
grouped by path with their associated HTTP methods.
## Parameters:
- schemaUrl: [Required] URL where the OpenAPI schema is published or the API base URL (will auto-discover the schema)
- authType: [Optional] Authentication method if the schema requires auth: 'bearer', 'basic', 'interactive', or 'none'
- authConfig: [Optional] Authentication configuration object (required if authType is not 'none')
- token: Bearer token (required for authType='bearer')
- username: Username (required for authType='basic')
- password: Password (optional for authType='basic')
- clientId: Client ID (required for authType='interactive')
- tenantId: Tenant ID (optional for authType='interactive', defaults to 'common')
## Example usage:
- get_openapi_endpoints({schemaUrl: "https://petstore.swagger.io/v2/swagger.json"})
`,
parameters: {
schemaUrl: zod_1.z.string().describe('URL where the OpenAPI schema is published'),
authType: zod_1.z.enum(['bearer', 'basic', 'interactive', 'none']).default('none').describe('Authentication method if the schema requires auth'),
authConfig: zod_1.z.object({
token: zod_1.z.string().optional().describe('Bearer token for token-based authentication'),
username: zod_1.z.string().optional().describe('Username for basic authentication'),
password: zod_1.z.string().optional().describe('Password for basic authentication'),
// For interactive auth
clientId: zod_1.z.string().optional().describe('Client ID for interactive authentication'),
tenantId: zod_1.z.string().optional().describe('Tenant ID for interactive authentication (defaults to "common")'),
authority: zod_1.z.string().optional().describe('Authority URL for authentication'),
scopes: zod_1.z.array(zod_1.z.string()).optional().describe('Scopes required for API access'),
redirectUri: zod_1.z.string().optional().describe('Redirect URI for authentication callback')
}).optional().describe('Authentication configuration')
},
handler: async ({ schemaUrl, authType, authConfig }) => {
try {
const endpoints = await openapi_service_1.OpenApiService.getEndpoints(schemaUrl, authType, authConfig);
// Format the endpoints for better readability
const formattedEndpoints = endpoints.map(endpoint => {
return {
path: endpoint.path,
methods: endpoint.operations.map(op => ({
method: op.method,
operationId: op.operationId || '',
summary: op.summary || '',
tags: op.tags || []
}))
};
});
return {
content: [{
type: 'text',
text: (0, json_utils_1.safeStringify)(formattedEndpoints)
}]
};
}
catch (error) {
console.error('Error fetching OpenAPI endpoints:', error);
return {
content: [{
type: 'text',
text: `Error fetching OpenAPI endpoints: ${error.message || 'Unknown error'}`
}],
isError: true
};
}
}
};
//# sourceMappingURL=get-openapi-endpoints.js.map