readme updated
This commit is contained in:
parent
89ff981a0f
commit
b26cc56ec0
62
README.md
62
README.md
@ -104,6 +104,68 @@ for await (const chunk of client.chat("What's the weather like?", {
|
|||||||
|
|
||||||
Cancels all ongoing requests.
|
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<string>((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
|
## Development
|
||||||
|
|
||||||
1. Clone the repository
|
1. Clone the repository
|
||||||
|
Loading…
x
Reference in New Issue
Block a user