@mcp-apps/api-tools-mcp-server
Version:
MCP server for interacting with APIs and web services
62 lines (51 loc) • 2.46 kB
text/typescript
console.log('Starting OpenAPI auth auto-discovery test...');
import { fetchOpenApiSchemaTool } from '../dist/tools/fetch-openapi-schema';
// Public OpenAPI API for testing that requires a token
// This example demonstrates schema auto-discovery with auth
const MOCK_PROTECTED_API = 'https://example-api.com';
const MOCK_TOKEN = 'demo-token-12345';
async function testAutoDiscoveryWithAuth() {
console.log('\n--- Testing OpenAPI Schema Auto-Discovery with Auth ---');
// This test is a simulation only - we're not actually making a network call since
// we don't have a real protected API to test against. In a real environment,
// replace the mock values with actual API URL and token.
console.log('NOTE: This is a simulated test for demonstration purposes.');
console.log('For actual authentication testing, provide a real API URL and token.');
// To test with a real API, uncomment the following code and provide valid credentials:
/*
try {
console.log('Testing auto-discovery with authentication...');
const result = await fetchOpenApiSchemaTool.handler({
schemaUrl: MOCK_PROTECTED_API,
authType: 'bearer',
authConfig: {
token: MOCK_TOKEN
}
});
if (result.isError) {
console.error('❌ Test failed: Schema auto-discovery with auth failed');
console.error('Error:', result.content[0].text);
return;
}
try {
const parsedResult = JSON.parse(result.content[0].text);
console.log('Schema auto-discovery with auth successful!');
console.log('Schema info:', parsedResult.info);
console.log('Schema contains', parsedResult.endpoints.length, 'endpoints');
console.log('✅ Test passed!');
} catch (parseError) {
console.error('❌ Test failed: Could not parse result as JSON');
console.error('Error:', parseError);
}
} catch (error) {
console.error('❌ Test failed:', error);
}
*/
console.log('✅ Simulated auth test complete');
}
async function runTests() {
console.log('Running OpenAPI Auth Auto-Discovery Tests...');
await testAutoDiscoveryWithAuth();
console.log('\nAll auth auto-discovery tests completed!');
}
runTests().catch(console.error);