get-market-prices
Retrieve real-time market prices for all items in EVE Online using the EVE Swagger Interface (ESI) API.
Instructions
Get market prices for all items in EVE Online
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:263-284 (handler)The handler function for the "get-market-prices" tool. It fetches market prices data from the EVE Online ESI API endpoint "/markets/prices/" using the makeESIRequest helper, formats the prices by ensuring non-null values, and returns the data as a formatted JSON string in a text content block.
async () => { const prices = await makeESIRequest<Array<{ type_id: number; adjusted_price?: number; average_price?: number; }>>("/markets/prices/"); const formattedPrices = prices.map((price) => ({ type_id: price.type_id, adjusted_price: price.adjusted_price || 0, average_price: price.average_price || 0, })); return { content: [ { type: "text", text: JSON.stringify(formattedPrices, null, 2), }, ], }; } - src/index.ts:259-285 (registration)The server.tool call that registers the "get-market-prices" tool, including its name, description, empty input schema (no parameters), and inline handler function.
server.tool( "get-market-prices", "Get market prices for all items in EVE Online", {}, async () => { const prices = await makeESIRequest<Array<{ type_id: number; adjusted_price?: number; average_price?: number; }>>("/markets/prices/"); const formattedPrices = prices.map((price) => ({ type_id: price.type_id, adjusted_price: price.adjusted_price || 0, average_price: price.average_price || 0, })); return { content: [ { type: "text", text: JSON.stringify(formattedPrices, null, 2), }, ], }; } ); - src/index.ts:222-256 (helper)The makeESIRequest helper function used by the handler to perform API requests to the EVE Online ESI endpoints, handling rate limiting, authentication, error handling, and response parsing.
async function makeESIRequest<T>(endpoint: string, token?: string): Promise<T> { if (!checkRateLimit(endpoint)) { throw new Error("Rate limit exceeded. Please try again later."); } const headers: Record<string, string> = { "User-Agent": USER_AGENT, "Accept": "application/json", }; if (token) { headers["Authorization"] = `Bearer ${token}`; } const response = await fetch(`${ESI_BASE_URL}${endpoint}`, { headers }); updateRateLimit(endpoint, response.headers); if (!response.ok) { let errorMessage = `HTTP error! status: ${response.status}`; try { const errorData = await response.json() as ESIError; if (errorData.error) { errorMessage = `ESI Error: ${errorData.error}`; if (errorData.error_description) { errorMessage += ` - ${errorData.error_description}`; } } } catch { // エラーJSONのパースに失敗した場合は、デフォルトのエラーメッセージを使用 } throw new Error(errorMessage); } return response.json() as Promise<T>; } - src/index.ts:74-79 (schema)TypeScript interface defining the structure of market price data returned from the ESI API, matching the types used in the handler.
interface MarketPrice { adjusted_price?: number; average_price?: number; type_id: number; }