nascoder-azure-ai-mcp-server
Version:
Professional Azure AI Foundry MCP Server - Developed by Freelancer Nasim with comprehensive testing and security best practices.
185 lines • 7.34 kB
JavaScript
import axios from 'axios';
export class AzureAIDiscovery {
inferenceEndpoint;
apiKey;
servicesEndpoint;
speechSTTEndpoint;
speechTTSEndpoint;
region;
services = new Map();
healthChecks = new Map();
constructor(inferenceEndpoint, apiKey, servicesEndpoint, speechSTTEndpoint, speechTTSEndpoint, region) {
this.inferenceEndpoint = inferenceEndpoint;
this.apiKey = apiKey;
this.servicesEndpoint = servicesEndpoint;
this.speechSTTEndpoint = speechSTTEndpoint;
this.speechTTSEndpoint = speechTTSEndpoint;
this.region = region;
}
async discoverServices() {
console.log('🔍 Discovering Azure AI services...');
// Define available services based on your setup
const serviceDefinitions = [
{
name: 'Azure AI Speech',
endpoint: this.speechSTTEndpoint,
capabilities: ['speech-to-text', 'text-to-speech', 'speech-translation'],
type: 'speech'
},
{
name: 'Azure AI Vision',
endpoint: this.servicesEndpoint,
capabilities: ['image-analysis', 'ocr', 'object-detection'],
type: 'vision'
},
{
name: 'Azure AI Document Intelligence',
endpoint: this.servicesEndpoint,
capabilities: ['document-analysis', 'form-recognition', 'table-extraction'],
type: 'document'
},
{
name: 'Azure AI Language',
endpoint: this.servicesEndpoint,
capabilities: ['text-analysis', 'sentiment-analysis', 'entity-recognition'],
type: 'language'
},
{
name: 'Azure AI Translator',
endpoint: this.servicesEndpoint,
capabilities: ['text-translation', 'language-detection'],
type: 'translation'
},
{
name: 'Azure AI Content Safety',
endpoint: this.servicesEndpoint,
capabilities: ['content-moderation', 'harmful-content-detection'],
type: 'safety'
},
{
name: 'Azure AI Content Understanding',
endpoint: this.servicesEndpoint,
capabilities: ['content-analysis', 'content-classification'],
type: 'understanding'
},
{
name: 'Azure AI Model Router',
endpoint: this.inferenceEndpoint,
capabilities: ['chat-completion', 'text-generation', 'function-calling'],
type: 'models'
}
];
// Check each service
for (const serviceDef of serviceDefinitions) {
try {
const healthCheck = await this.checkServiceHealth(serviceDef.name, serviceDef.endpoint);
const service = {
name: serviceDef.name,
endpoint: serviceDef.endpoint,
apiKey: this.apiKey,
region: this.region,
capabilities: serviceDef.capabilities,
status: healthCheck.status === 'healthy' ? 'available' : 'unavailable'
};
this.services.set(serviceDef.type, service);
this.healthChecks.set(serviceDef.name, healthCheck);
console.log(`✅ ${serviceDef.name}: ${service.status}`);
}
catch (error) {
console.log(`❌ ${serviceDef.name}: unavailable`);
const service = {
name: serviceDef.name,
endpoint: serviceDef.endpoint,
region: this.region,
capabilities: serviceDef.capabilities,
status: 'unavailable'
};
this.services.set(serviceDef.type, service);
}
}
return Array.from(this.services.values());
}
async discoverModels() {
console.log('🔍 Discovering deployed models...');
try {
// For now, we know about model-router deployment
// In a full implementation, this would query the Azure AI Foundry API
const models = [
{
name: 'model-router',
modelName: 'model-router',
version: '2025-05-19',
endpoint: this.inferenceEndpoint,
capabilities: [
{ type: 'chat', description: 'Chat completion with various models' },
{ type: 'text-generation', description: 'Text generation capabilities' },
{ type: 'function-calling', description: 'Function calling support' }
],
status: 'ready'
}
];
console.log(`✅ Found ${models.length} deployed model(s)`);
return models;
}
catch (error) {
console.error('❌ Failed to discover models:', error);
return [];
}
}
async checkServiceHealth(serviceName, endpoint) {
const startTime = Date.now();
try {
// Simple health check - try to reach the endpoint
const response = await axios.get(endpoint, {
timeout: 5000,
headers: {
'Ocp-Apim-Subscription-Key': this.apiKey,
'Content-Type': 'application/json'
},
validateStatus: (status) => status < 500 // Accept 4xx as "healthy" (auth issues are expected)
});
const responseTime = Date.now() - startTime;
return {
service: serviceName,
status: 'healthy',
responseTime,
lastChecked: new Date()
};
}
catch (error) {
const responseTime = Date.now() - startTime;
return {
service: serviceName,
status: 'unhealthy',
responseTime,
lastChecked: new Date(),
error: error instanceof Error ? error.message : 'Unknown error'
};
}
}
getService(type) {
return this.services.get(type);
}
getAllServices() {
return Array.from(this.services.values());
}
getHealthChecks() {
return Array.from(this.healthChecks.values());
}
async refreshHealthChecks() {
console.log('🔄 Refreshing service health checks...');
for (const [type, service] of this.services.entries()) {
try {
const healthCheck = await this.checkServiceHealth(service.name, service.endpoint);
this.healthChecks.set(service.name, healthCheck);
// Update service status
service.status = healthCheck.status === 'healthy' ? 'available' : 'unavailable';
this.services.set(type, service);
}
catch (error) {
console.error(`Failed to check health for ${service.name}:`, error);
}
}
}
}
//# sourceMappingURL=discovery.js.map