Skip to main content
Glama
http.ts1.79 kB
import axios, { AxiosInstance } from 'axios'; import { ITransport } from './ITransport.js'; /** * HTTP transport for Unity Editor communication * Uses axios to make REST API calls to Unity's HTTP server */ export class HttpTransport implements ITransport { private client: AxiosInstance; private baseUrl: string; private timeout: number; constructor(port: number = 8080, timeout: number = 30000) { this.baseUrl = `http://localhost:${port}`; this.timeout = timeout; this.client = axios.create({ baseURL: this.baseUrl, timeout: this.timeout, headers: { 'Content-Type': 'application/json', }, }); } async request<T = any>(endpoint: string, data: any): Promise<T> { try { const response = await this.client.post(endpoint, data); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error( `HTTP request failed: ${error.message}${ error.response ? ` (Status: ${error.response.status})` : '' }` ); } throw error; } } async isConnected(): Promise<boolean> { try { const response = await this.client.get('/health', { timeout: 2000 }); return response.data.status === 'ok'; } catch { return false; } } async connect(): Promise<void> { // HTTP doesn't require explicit connection // Verify server is reachable const connected = await this.isConnected(); if (!connected) { throw new Error('Unity Editor HTTP server not reachable'); } } async disconnect(): Promise<void> { // HTTP doesn't require explicit disconnection } getType(): 'http' { return 'http'; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/muammar-yacoob/unity-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server