You can also make use of @modelcontextprotocol/sdk/client in order to interact with the euler mcp server. This particular client provides a convenient way to establish a connection and communicate with the euler mcp server, enabling you to perform various operations and access the services offered by the server.
```typescript
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
import dotenv from "dotenv";
import OpenAI from "openai";
dotenv.config();
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
if (!OPENAI_API_KEY) {
throw new Error("OPENAI_API_KEY is not set");
}
const OPENAI_BASE_URL = process.env.OPENAI_BASE_URL || "https://api.openai.com/v1";
const MCP_SERVER_URL = process.env.MCP_SERVER_URL || "https://dev.euler.ai/mcp/sse";
function openAiToolAdapter(tool: {
name: string;
Run the client.ts
tsx src/client.ts "Check the current ETH balance of vitalik.eth"
Calling tool resolve_ens with args "{\"ensName\":\"vitalik.eth\"}"
Final result: [Calling tool resolve_ens with args "{\"ensName\":\"vitalik.eth\"}"]
The Tool Response indicates that the resolved address of vitalik.eth is 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045. To check the current ETH balance of this address, it is recommended to use a blockchain explorer or a cryptocurrency wallet that supports querying account balances. You can input this address (0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045) in the search bar of a reliable blockchain explorer such as Etherscan to view the current ETH balance associated with vitalik.eth.
description?: string;
input_schema: any;
}) {
return {
type: "function",
function: {
name: tool.name,
description: tool.description,
parameters: {
type: "object",
properties: tool.input_schema.properties,
required: tool.input_schema.required,
},
},
};
}
class MCPClient {
private mcp: Client;
private openai: OpenAI;
private tools: Array<any> = [];
private transport: Transport | null = null;
constructor() {
this.openai = new OpenAI({
apiKey: OPENAI_API_KEY,
baseURL: OPENAI_BASE_URL,
});
this.mcp = new Client({ name: "mcp-client", version: "1.0.0" });
}
async connectToServer(serverUrl: string) {
try {
this.transport = new SSEClientTransport(new URL(serverUrl));
await this.mcp.connect(this.transport);
const toolsResult = await this.mcp.listTools();
this.tools = toolsResult.tools.map((tool) => {
return openAiToolAdapter({
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema,
});
});
} catch (e) {
console.log("Failed to connect to MCP server: ", e);