From b26cc56ec0f25690380ab6c819f56b5b933199bf Mon Sep 17 00:00:00 2001 From: Koushik Roy Date: Mon, 16 Jun 2025 16:39:57 +0530 Subject: [PATCH] readme updated --- README.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/README.md b/README.md index b64f327..74f0996 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,68 @@ for await (const chunk of client.chat("What's the weather like?", { Cancels all ongoing requests. +## Examples +```typescript +import ClientMCP from 'client-mcp'; +import { v4 as uuidv4 } from 'uuid'; + +const serverId = uuidv4(); + +async function main() { + const mcpClient = new ClientMCP({ + apiKey: "AIzaSyBS0xT1myuCfMfdNvA9FgVZm258PBoM4hY", + model: "gemini-2.0-flash", + baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai/", + debug: true + }); + // MCPClientList.push(mcpClient) + try { + // const serverPath = "/Users/koushikroy/Documents/temp_projects/mcp_server/dist/index.js"; + const serverPath = new URL("/mcp", "http://localhost:3003"); + serverPath.searchParams.set("email", "kroy963@gmail.com"); + serverPath.searchParams.set("teamSlug", "mcp"); + serverPath.searchParams.set("apiKey", "es-AghrcEgk0G2cFvFqlZSNSG1EPrXb"); + await mcpClient.connectToServer(serverPath, serverId); + await chatLoop(mcpClient); + } finally { + console.log("MCP Client Closed!"); + process.exit(0); + } +} + + +// chat loop +async function chatLoop(mcpClient: ClientMCP) { + while (true) { + const userMessage = await new Promise((resolve) => { + const readline = require('readline'); + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + rl.question('Q: ', (message: string) => { + rl.close(); + resolve(message); + }); + }); + + if (userMessage.trim().toLowerCase() === 'quit') { + console.log('Goodbye!'); + process.exit(0); + } + const response = mcpClient.chat(userMessage); + for await (const chunk of response) { + console.log(chunk.choices[0].delta.content); + } + + } +} + + + +main(); +``` + ## Development 1. Clone the repository