Skip to main content
Glama

Currency Converter MCP

by wesbos
index.ts1.52 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { McpAgent } from "agents/mcp"; import { convertCurrency, convertCurrencySchema, } from "./tools/convert_currency"; import { getCurrencies, getCurrenciesSchema } from "./tools/get_currencies"; import { getHistoricalRates, getHistoricalRatesSchema, } from "./tools/get_historical_rates"; import { getLatestRates, getLatestRatesSchema, } from "./tools/get_latest_rates"; export class MyMCP extends McpAgent { server = new McpServer({ name: "Currency Converter", version: "1.0.0", }); async init() { this.server.tool("convert_currency", convertCurrencySchema, async (input) => convertCurrency(input), ); this.server.tool("get_latest_rates", getLatestRatesSchema, async (input) => getLatestRates(input), ); this.server.tool("get_currencies", getCurrenciesSchema, async (input) => getCurrencies(input), ); this.server.tool( "get_historical_rates", getHistoricalRatesSchema, async (input) => getHistoricalRates(input), ); } } export default { fetch(request: Request, env: Env, ctx: ExecutionContext) { const url = new URL(request.url); if (url.pathname === "/sse" || url.pathname === "/sse/message") { return MyMCP.serveSSE("/sse").fetch(request, env, ctx); } if (url.pathname === "/mcp") { return MyMCP.serve("/mcp").fetch(request, env, ctx); } return new Response("Not found", { status: 404 }); }, };

Implementation Reference

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/wesbos/currency-conversion-mcp'

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