We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/skynet-base/taksi-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
McpError,
ErrorCode,
} from '@modelcontextprotocol/sdk/types.js';
import { v4 as uuidv4 } from 'uuid';
import dotenv from 'dotenv';
// .env dosyasını yükle
dotenv.config();
// Taksi sağlayıcı türleri
type TaksiSaglayici = 'bitaksi' | 'itaksi' | 'uber' | 'genel';
// Konum veri yapısı
interface Konum {
enlem: number; // latitude
boylam: number; // longitude
adres?: string;
sehir?: string;
}
// Taksi türleri
interface TaksiTuru {
id: string;
ad: string;
aciklama: string;
fiyatCarpani: number;
kapasiteYolcu: number;
ozellikler: string[];
}
// Ücret tahmini
interface UcretTahmini {
minFiyat: number;
maxFiyat: number;
parabirimi: string;
tahminiSure: number; // dakika cinsinden
mesafe: number; // kilometre cinsinden
taksiTuru: string;
}
// Taksi durumu
type TaksiDurumu = 'aranıyor' | 'bulundu' | 'yolda' | 'geldi' | 'yolculukta' | 'tamamlandı' | 'iptal';
// Yolculuk bilgileri
interface Yolculuk {
id: string;
saglayici: TaksiSaglayici;
durum: TaksiDurumu;
baslangic: Konum;
hedef: Konum;
taksiTuru: string;
surucu?: {
ad: string;
telefon: string;
puan: number;
aracPlaka: string;
aracModel: string;
};
ucret?: number;
parabirimi: string;
olusturulma: Date;
guncelleme: Date;
tahminiVarisSaati?: Date;
}
// Taksi sağlayıcı sınıfı
class TaksiSaglayiciServisi {
private testModu: boolean;
private cache: Map<string, any>;
private readonly cacheSuresi: number;
constructor() {
this.testModu = process.env.TEST_MODE === 'true';
this.cache = new Map();
this.cacheSuresi = parseInt(process.env.CACHE_DURATION_MINUTES || '5') * 60 * 1000;
this.logBilgi('Taksi sağlayıcı servisi başlatıldı', { testModu: this.testModu });
}
private logBilgi(mesaj: string, ekstra?: any) {
if (process.env.DEBUG === 'true') {
console.log(`[TaksiMCP] ${mesaj}`, ekstra || '');
}
}
private cacheKontrolu(anahtar: string): any | null {
const veri = this.cache.get(anahtar);
if (veri && (Date.now() - veri.zaman) < this.cacheSuresi) {
return veri.deger;
}
this.cache.delete(anahtar);
return null;
}
private cacheKaydet(anahtar: string, deger: any) {
this.cache.set(anahtar, { deger, zaman: Date.now() });
}
// Mevcut taksi türlerini getir
async getTaksiTurleri(saglayici: TaksiSaglayici): Promise<TaksiTuru[]> {
const cacheAnahtar = `taksi_turleri_${saglayici}`;
const cachedVeri = this.cacheKontrolu(cacheAnahtar);
if (cachedVeri) {
return cachedVeri;
}
this.logBilgi('Taksi türleri getiriliyor', { saglayici });
let turler: TaksiTuru[];
if (this.testModu) {
turler = this.getMockTaksiTurleri();
} else {
switch (saglayici) {
case 'bitaksi':
turler = await this.getBiTaksiTurleri();
break;
case 'itaksi':
turler = await this.getITaksiTurleri();
break;
case 'uber':
turler = await this.getUberTurleri();
break;
default:
turler = this.getGenelTaksiTurleri();
}
}
this.cacheKaydet(cacheAnahtar, turler);
return turler;
}
private getMockTaksiTurleri(): TaksiTuru[] {
return [
{
id: 'standart',
ad: 'Standart Taksi',
aciklama: 'Normal şehir taksisi',
fiyatCarpani: 1.0,
kapasiteYolcu: 4,
ozellikler: ['klima', 'kartla_odeme']
},
{
id: 'luks',
ad: 'Lüks Taksi',
aciklama: 'Konforlu ve geniş araç',
fiyatCarpani: 1.5,
kapasiteYolcu: 4,
ozellikler: ['klima', 'kartla_odeme', 'wifi', 'deri_koltuk']
},
{
id: 'buyuk',
ad: 'Büyük Taksi',
aciklama: '8 kişilik geniş araç',
fiyatCarpani: 1.8,
kapasiteYolcu: 8,
ozellikler: ['klima', 'kartla_odeme', 'genis_bagaj']
},
{
id: 'pati',
ad: 'Pati Taksi',
aciklama: 'Evcil hayvan dostu taksi',
fiyatCarpani: 1.2,
kapasiteYolcu: 4,
ozellikler: ['klima', 'kartla_odeme', 'evcil_hayvan']
}
];
}
private async getBiTaksiTurleri(): Promise<TaksiTuru[]> {
// BiTaksi API entegrasyonu (gelecekte)
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async getITaksiTurleri(): Promise<TaksiTuru[]> {
// iTaksi API entegrasyonu (gelecekte)
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async getUberTurleri(): Promise<TaksiTuru[]> {
// Uber API entegrasyonu (gelecekte)
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private getGenelTaksiTurleri(): TaksiTuru[] {
return this.getMockTaksiTurleri();
}
// Ücret tahmini hesapla
async getUcretTahmini(
saglayici: TaksiSaglayici,
baslangic: Konum,
hedef: Konum,
taksiTuru: string = 'standart'
): Promise<UcretTahmini> {
this.logBilgi('Ücret tahmini hesaplanıyor', { saglayici, taksiTuru });
if (this.testModu) {
return this.getMockUcretTahmini(baslangic, hedef, taksiTuru);
}
switch (saglayici) {
case 'bitaksi':
return this.getBiTaksiUcretTahmini(baslangic, hedef, taksiTuru);
case 'itaksi':
return this.getITaksiUcretTahmini(baslangic, hedef, taksiTuru);
case 'uber':
return this.getUberUcretTahmini(baslangic, hedef, taksiTuru);
default:
return this.getGenelUcretTahmini(baslangic, hedef, taksiTuru);
}
}
private getMockUcretTahmini(baslangic: Konum, hedef: Konum, taksiTuru: string): UcretTahmini {
// Basit mesafe hesaplama (haversine formülü yaklaşımı)
const mesafe = this.mesafeHesapla(baslangic, hedef);
const taksiTurleri = this.getMockTaksiTurleri();
const tur = taksiTurleri.find(t => t.id === taksiTuru) || taksiTurleri[0];
const temelFiyat = 15; // TL
const kmBasiFiyat = 8; // TL/km
const hesaplananFiyat = (temelFiyat + (mesafe * kmBasiFiyat)) * tur.fiyatCarpani;
return {
minFiyat: Math.round(hesaplananFiyat * 0.9),
maxFiyat: Math.round(hesaplananFiyat * 1.1),
parabirimi: 'TRY',
tahminiSure: Math.round(mesafe * 3), // 3 dakika/km varsayımı
mesafe: Math.round(mesafe * 10) / 10,
taksiTuru
};
}
private async getBiTaksiUcretTahmini(baslangic: Konum, hedef: Konum, taksiTuru: string): Promise<UcretTahmini> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async getITaksiUcretTahmini(baslangic: Konum, hedef: Konum, taksiTuru: string): Promise<UcretTahmini> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async getUberUcretTahmini(baslangic: Konum, hedef: Konum, taksiTuru: string): Promise<UcretTahmini> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private getGenelUcretTahmini(baslangic: Konum, hedef: Konum, taksiTuru: string): UcretTahmini {
return this.getMockUcretTahmini(baslangic, hedef, taksiTuru);
}
// Mesafe hesaplama (haversine formülü)
private mesafeHesapla(konum1: Konum, konum2: Konum): number {
const R = 6371; // Dünya yarıçapı (km)
const dLat = this.radyanaConvert(konum2.enlem - konum1.enlem);
const dLon = this.radyanaConvert(konum2.boylam - konum1.boylam);
const a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(this.radyanaConvert(konum1.enlem)) * Math.cos(this.radyanaConvert(konum2.enlem)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
private radyanaConvert(derece: number): number {
return derece * (Math.PI / 180);
}
// Taksi çağır
async taksiCagir(
saglayici: TaksiSaglayici,
baslangic: Konum,
hedef: Konum,
taksiTuru: string = 'standart',
ekstraOzellikler?: string[]
): Promise<Yolculuk> {
this.logBilgi('Taksi çağırılıyor', { saglayici, taksiTuru });
const yolculukId = uuidv4();
if (this.testModu) {
return this.getMockYolculuk(yolculukId, saglayici, baslangic, hedef, taksiTuru);
}
switch (saglayici) {
case 'bitaksi':
return this.biTaksiCagir(yolculukId, baslangic, hedef, taksiTuru, ekstraOzellikler);
case 'itaksi':
return this.iTaksiCagir(yolculukId, baslangic, hedef, taksiTuru, ekstraOzellikler);
case 'uber':
return this.uberCagir(yolculukId, baslangic, hedef, taksiTuru, ekstraOzellikler);
default:
return this.genelTaksiCagir(yolculukId, baslangic, hedef, taksiTuru, ekstraOzellikler);
}
}
private getMockYolculuk(id: string, saglayici: TaksiSaglayici, baslangic: Konum, hedef: Konum, taksiTuru: string): Yolculuk {
return {
id,
saglayici,
durum: 'aranıyor',
baslangic,
hedef,
taksiTuru,
parabirimi: 'TRY',
olusturulma: new Date(),
guncelleme: new Date()
};
}
private async biTaksiCagir(id: string, baslangic: Konum, hedef: Konum, taksiTuru: string, ekstraOzellikler?: string[]): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async iTaksiCagir(id: string, baslangic: Konum, hedef: Konum, taksiTuru: string, ekstraOzellikler?: string[]): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async uberCagir(id: string, baslangic: Konum, hedef: Konum, taksiTuru: string, ekstraOzellikler?: string[]): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private genelTaksiCagir(id: string, baslangic: Konum, hedef: Konum, taksiTuru: string, ekstraOzellikler?: string[]): Yolculuk {
return this.getMockYolculuk(id, 'genel', baslangic, hedef, taksiTuru);
}
// Yolculuk durumu sorgula
async yolculukDurumu(yolculukId: string, saglayici: TaksiSaglayici): Promise<Yolculuk> {
this.logBilgi('Yolculuk durumu sorgulanıyor', { yolculukId, saglayici });
if (this.testModu) {
return this.getMockYolculukDurumu(yolculukId, saglayici);
}
switch (saglayici) {
case 'bitaksi':
return this.getBiTaksiYolculukDurumu(yolculukId);
case 'itaksi':
return this.getITaksiYolculukDurumu(yolculukId);
case 'uber':
return this.getUberYolculukDurumu(yolculukId);
default:
return this.getGenelYolculukDurumu(yolculukId);
}
}
private getMockYolculukDurumu(yolculukId: string, saglayici: TaksiSaglayici): Yolculuk {
const durumlar: TaksiDurumu[] = ['aranıyor', 'bulundu', 'yolda', 'geldi'];
const rastgeleDurum = durumlar[Math.floor(Math.random() * durumlar.length)];
const yolculuk: Yolculuk = {
id: yolculukId,
saglayici,
durum: rastgeleDurum,
baslangic: { enlem: 41.0362, boylam: 28.9841, adres: 'Taksim, İstanbul' },
hedef: { enlem: 41.0082, boylam: 28.9784, adres: 'Sultanahmet, İstanbul' },
taksiTuru: 'standart',
parabirimi: 'TRY',
olusturulma: new Date(Date.now() - 10 * 60 * 1000), // 10 dakika önce
guncelleme: new Date(),
};
if (rastgeleDurum !== 'aranıyor') {
yolculuk.surucu = {
ad: 'Mehmet Yılmaz',
telefon: '+905551234567',
puan: 4.8,
aracPlaka: '34ABC123',
aracModel: 'Toyota Corolla'
};
}
if (rastgeleDurum === 'yolda') {
yolculuk.tahminiVarisSaati = new Date(Date.now() + 5 * 60 * 1000);
}
return yolculuk;
}
private async getBiTaksiYolculukDurumu(yolculukId: string): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async getITaksiYolculukDurumu(yolculukId: string): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async getUberYolculukDurumu(yolculukId: string): Promise<Yolculuk> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private getGenelYolculukDurumu(yolculukId: string): Yolculuk {
return this.getMockYolculukDurumu(yolculukId, 'genel');
}
// Yolculuk iptal et
async yolculukIptal(yolculukId: string, saglayici: TaksiSaglayici, neden?: string): Promise<boolean> {
this.logBilgi('Yolculuk iptal ediliyor', { yolculukId, saglayici, neden });
if (this.testModu) {
return true;
}
switch (saglayici) {
case 'bitaksi':
return this.biTaksiIptal(yolculukId, neden);
case 'itaksi':
return this.iTaksiIptal(yolculukId, neden);
case 'uber':
return this.uberIptal(yolculukId, neden);
default:
return this.genelTaksiIptal(yolculukId, neden);
}
}
private async biTaksiIptal(yolculukId: string, neden?: string): Promise<boolean> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async iTaksiIptal(yolculukId: string, neden?: string): Promise<boolean> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async uberIptal(yolculukId: string, neden?: string): Promise<boolean> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private genelTaksiIptal(yolculukId: string, neden?: string): boolean {
return true;
}
// Geçmiş yolculukları getir
async getYolculukGecmisi(saglayici: TaksiSaglayici, limit: number = 10): Promise<Yolculuk[]> {
this.logBilgi('Yolculuk geçmişi getiriliyor', { saglayici, limit });
if (this.testModu) {
return this.getMockYolculukGecmisi(limit);
}
switch (saglayici) {
case 'bitaksi':
return this.getBiTaksiGecmis(limit);
case 'itaksi':
return this.getITaksiGecmis(limit);
case 'uber':
return this.getUberGecmis(limit);
default:
return this.getGenelGecmis(limit);
}
}
private getMockYolculukGecmisi(limit: number): Yolculuk[] {
const gecmis: Yolculuk[] = [];
for (let i = 0; i < limit; i++) {
gecmis.push({
id: `yolculuk_${i + 1}`,
saglayici: 'genel',
durum: 'tamamlandı',
baslangic: { enlem: 41.0362, boylam: 28.9841, adres: 'Taksim, İstanbul' },
hedef: { enlem: 41.0082, boylam: 28.9784, adres: 'Sultanahmet, İstanbul' },
taksiTuru: 'standart',
surucu: {
ad: `Şoför ${i + 1}`,
telefon: `+90555123456${i}`,
puan: 4.5 + (Math.random() * 0.5),
aracPlaka: `34XYZ${100 + i}`,
aracModel: 'Toyota Corolla'
},
ucret: 45 + (Math.random() * 25),
parabirimi: 'TRY',
olusturulma: new Date(Date.now() - (i + 1) * 24 * 60 * 60 * 1000),
guncelleme: new Date(Date.now() - (i + 1) * 24 * 60 * 60 * 1000)
});
}
return gecmis;
}
private async getBiTaksiGecmis(limit: number): Promise<Yolculuk[]> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async getITaksiGecmis(limit: number): Promise<Yolculuk[]> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async getUberGecmis(limit: number): Promise<Yolculuk[]> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private getGenelGecmis(limit: number): Yolculuk[] {
return this.getMockYolculukGecmisi(limit);
}
// Şoförle iletişim
async surucuIletisim(yolculukId: string, saglayici: TaksiSaglayici, mesajTuru: 'arama' | 'sms', mesaj?: string): Promise<string> {
this.logBilgi('Şoför iletişimi', { yolculukId, saglayici, mesajTuru });
if (this.testModu) {
return mesajTuru === 'arama' ?
'Şoför arandı. Telefon: +905551234567' :
'SMS gönderildi: ' + (mesaj || 'Konumunuzu paylaşın lütfen');
}
switch (saglayici) {
case 'bitaksi':
return this.biTaksiSurucuIletisim(yolculukId, mesajTuru, mesaj);
case 'itaksi':
return this.iTaksiSurucuIletisim(yolculukId, mesajTuru, mesaj);
case 'uber':
return this.uberSurucuIletisim(yolculukId, mesajTuru, mesaj);
default:
return this.genelSurucuIletisim(yolculukId, mesajTuru, mesaj);
}
}
private async biTaksiSurucuIletisim(yolculukId: string, mesajTuru: 'arama' | 'sms', mesaj?: string): Promise<string> {
throw new McpError(ErrorCode.MethodNotFound, 'BiTaksi API henüz mevcut değil');
}
private async iTaksiSurucuIletisim(yolculukId: string, mesajTuru: 'arama' | 'sms', mesaj?: string): Promise<string> {
throw new McpError(ErrorCode.MethodNotFound, 'iTaksi API henüz mevcut değil');
}
private async uberSurucuIletisim(yolculukId: string, mesajTuru: 'arama' | 'sms', mesaj?: string): Promise<string> {
throw new McpError(ErrorCode.MethodNotFound, 'Uber API henüz mevcut değil');
}
private genelSurucuIletisim(yolculukId: string, mesajTuru: 'arama' | 'sms', mesaj?: string): string {
return mesajTuru === 'arama' ?
'Şoför arandı. Telefon: +905551234567' :
'SMS gönderildi: ' + (mesaj || 'Konumunuzu paylaşın lütfen');
}
}
// MCP Server sınıfı
class TaksiMCPServer {
private server: Server;
private taksiServisi: TaksiSaglayiciServisi;
constructor() {
this.taksiServisi = new TaksiSaglayiciServisi();
this.server = new Server(
{
name: 'taksi-mcp-server',
version: '1.0.0',
}
);
this.setupToolHandlers();
}
private setupToolHandlers() {
// Araçları listele
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'taksi_turleri_getir',
description: 'Mevcut taksi türlerini ve özelliklerini listele',
inputSchema: {
type: 'object',
properties: {
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
description: 'Taksi sağlayıcısı (varsayılan: genel)',
default: 'genel'
}
}
}
},
{
name: 'ucret_tahmini',
description: 'İki konum arası taksi ücreti tahmini hesapla',
inputSchema: {
type: 'object',
properties: {
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
},
baslangic_enlem: { type: 'number', description: 'Başlangıç konumu enlemi' },
baslangic_boylam: { type: 'number', description: 'Başlangıç konumu boylamı' },
baslangic_adres: { type: 'string', description: 'Başlangıç adresi (opsiyonel)' },
hedef_enlem: { type: 'number', description: 'Hedef konumu enlemi' },
hedef_boylam: { type: 'number', description: 'Hedef konumu boylamı' },
hedef_adres: { type: 'string', description: 'Hedef adresi (opsiyonel)' },
taksi_turu: {
type: 'string',
default: 'standart',
description: 'Taksi türü (standart, luks, buyuk, pati)'
}
},
required: ['baslangic_enlem', 'baslangic_boylam', 'hedef_enlem', 'hedef_boylam']
}
},
{
name: 'taksi_cagir',
description: 'Belirtilen konumlar arası taksi çağır',
inputSchema: {
type: 'object',
properties: {
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
},
baslangic_enlem: { type: 'number', description: 'Başlangıç konumu enlemi' },
baslangic_boylam: { type: 'number', description: 'Başlangıç konumu boylamı' },
baslangic_adres: { type: 'string', description: 'Başlangıç adresi (opsiyonel)' },
hedef_enlem: { type: 'number', description: 'Hedef konumu enlemi' },
hedef_boylam: { type: 'number', description: 'Hedef konumu boylamı' },
hedef_adres: { type: 'string', description: 'Hedef adresi (opsiyonel)' },
taksi_turu: {
type: 'string',
default: 'standart',
description: 'Taksi türü (standart, luks, buyuk, pati)'
},
ekstra_ozellikler: {
type: 'array',
items: { type: 'string' },
description: 'Ekstra özellikler (evcil_hayvan, klima, vb.)'
}
},
required: ['baslangic_enlem', 'baslangic_boylam', 'hedef_enlem', 'hedef_boylam']
}
},
{
name: 'yolculuk_durumu',
description: 'Aktif yolculuğun durumunu ve şoför bilgilerini sorgula',
inputSchema: {
type: 'object',
properties: {
yolculuk_id: { type: 'string', description: 'Yolculuk kimlik numarası' },
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
}
},
required: ['yolculuk_id']
}
},
{
name: 'yolculuk_iptal',
description: 'Aktif yolculuğu iptal et',
inputSchema: {
type: 'object',
properties: {
yolculuk_id: { type: 'string', description: 'Yolculuk kimlik numarası' },
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
},
iptal_nedeni: { type: 'string', description: 'İptal nedeni (opsiyonel)' }
},
required: ['yolculuk_id']
}
},
{
name: 'yolculuk_gecmisi',
description: 'Geçmiş yolculukları listele',
inputSchema: {
type: 'object',
properties: {
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
},
limit: {
type: 'number',
default: 10,
minimum: 1,
maximum: 50,
description: 'Getirilecek yolculuk sayısı'
}
}
}
},
{
name: 'surucu_iletisim',
description: 'Aktif yolculukta şoförle iletişime geç (ara/mesaj)',
inputSchema: {
type: 'object',
properties: {
yolculuk_id: { type: 'string', description: 'Yolculuk kimlik numarası' },
saglayici: {
type: 'string',
enum: ['bitaksi', 'itaksi', 'uber', 'genel'],
default: 'genel'
},
iletisim_turu: {
type: 'string',
enum: ['arama', 'sms'],
description: 'İletişim türü'
},
mesaj: {
type: 'string',
description: 'SMS için mesaj metni (opsiyonel)'
}
},
required: ['yolculuk_id', 'iletisim_turu']
}
}
]
};
});
// Araç çağırma işleyicileri
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
switch (request.params.name) {
case 'taksi_turleri_getir':
return this.handleTaksiTurleriGetir(request.params.arguments);
case 'ucret_tahmini':
return this.handleUcretTahmini(request.params.arguments);
case 'taksi_cagir':
return this.handleTaksiCagir(request.params.arguments);
case 'yolculuk_durumu':
return this.handleYolculukDurumu(request.params.arguments);
case 'yolculuk_iptal':
return this.handleYolculukIptal(request.params.arguments);
case 'yolculuk_gecmisi':
return this.handleYolculukGecmisi(request.params.arguments);
case 'surucu_iletisim':
return this.handleSurucuIletisim(request.params.arguments);
default:
throw new McpError(ErrorCode.MethodNotFound, `Bilinmeyen araç: ${request.params.name}`);
}
});
}
private async handleTaksiTurleriGetir(args: any) {
try {
const saglayici = args?.saglayici || 'genel';
const turler = await this.taksiServisi.getTaksiTurleri(saglayici as TaksiSaglayici);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: turler,
mesaj: `${saglayici} için ${turler.length} taksi türü bulundu`
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleUcretTahmini(args: any) {
try {
const { saglayici = 'genel', baslangic_enlem, baslangic_boylam, baslangic_adres, hedef_enlem, hedef_boylam, hedef_adres, taksi_turu = 'standart' } = args;
if (!baslangic_enlem || !baslangic_boylam || !hedef_enlem || !hedef_boylam) {
throw new Error('Başlangıç ve hedef koordinatları gerekli');
}
const baslangic: Konum = {
enlem: baslangic_enlem,
boylam: baslangic_boylam,
adres: baslangic_adres
};
const hedef: Konum = {
enlem: hedef_enlem,
boylam: hedef_boylam,
adres: hedef_adres
};
const tahmin = await this.taksiServisi.getUcretTahmini(saglayici, baslangic, hedef, taksi_turu);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: tahmin,
mesaj: 'Ücret tahmini hesaplandı'
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleTaksiCagir(args: any) {
try {
const { saglayici = 'genel', baslangic_enlem, baslangic_boylam, baslangic_adres, hedef_enlem, hedef_boylam, hedef_adres, taksi_turu = 'standart', ekstra_ozellikler } = args;
if (!baslangic_enlem || !baslangic_boylam || !hedef_enlem || !hedef_boylam) {
throw new Error('Başlangıç ve hedef koordinatları gerekli');
}
const baslangic: Konum = {
enlem: baslangic_enlem,
boylam: baslangic_boylam,
adres: baslangic_adres
};
const hedef: Konum = {
enlem: hedef_enlem,
boylam: hedef_boylam,
adres: hedef_adres
};
const yolculuk = await this.taksiServisi.taksiCagir(saglayici, baslangic, hedef, taksi_turu, ekstra_ozellikler);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: yolculuk,
mesaj: `Taksi çağrıldı. Yolculuk ID: ${yolculuk.id}`
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleYolculukDurumu(args: any) {
try {
const { yolculuk_id, saglayici = 'genel' } = args;
if (!yolculuk_id) {
throw new Error('Yolculuk ID gerekli');
}
const yolculuk = await this.taksiServisi.yolculukDurumu(yolculuk_id, saglayici);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: yolculuk,
mesaj: `Yolculuk durumu: ${yolculuk.durum}`
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleYolculukIptal(args: any) {
try {
const { yolculuk_id, saglayici = 'genel', iptal_nedeni } = args;
if (!yolculuk_id) {
throw new Error('Yolculuk ID gerekli');
}
const sonuc = await this.taksiServisi.yolculukIptal(yolculuk_id, saglayici, iptal_nedeni);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: { iptal_edildi: sonuc },
mesaj: sonuc ? 'Yolculuk başarıyla iptal edildi' : 'Yolculuk iptal edilemedi'
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleYolculukGecmisi(args: any) {
try {
const { saglayici = 'genel', limit = 10 } = args;
const gecmis = await this.taksiServisi.getYolculukGecmisi(saglayici, limit);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: gecmis,
mesaj: `${gecmis.length} yolculuk geçmişi getirildi`
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
private async handleSurucuIletisim(args: any) {
try {
const { yolculuk_id, saglayici = 'genel', iletisim_turu, mesaj } = args;
if (!yolculuk_id || !iletisim_turu) {
throw new Error('Yolculuk ID ve iletişim türü gerekli');
}
const sonuc = await this.taksiServisi.surucuIletisim(yolculuk_id, saglayici, iletisim_turu, mesaj);
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'basarili',
veri: { sonuc },
mesaj: 'Şoför ile iletişim kuruldu'
}, null, 2)
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
durum: 'hata',
hata: error instanceof Error ? error.message : 'Bilinmeyen hata'
}, null, 2)
}]
};
}
}
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error('Taksi MCP Server başlatıldı...');
}
}
// Ana uygulama
async function main() {
try {
const server = new TaksiMCPServer();
await server.run();
} catch (error) {
console.error('Taksi MCP Server başlatılırken hata:', error);
process.exit(1);
}
}
// Process event handlers
process.on('SIGINT', () => {
console.error('\nTaksi MCP Server kapatılıyor...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.error('\nTaksi MCP Server sonlandırılıyor...');
process.exit(0);
});
// Ana fonksiyonu çalıştır
main().catch((error) => {
console.error('Başlatma hatası:', error);
process.exit(1);
});