add prompts tab

This commit is contained in:
Ashwin Bhat
2024-10-07 17:09:13 -07:00
parent af16a53842
commit 0a7f5f9f22
5 changed files with 198 additions and 28 deletions

View File

@@ -6,6 +6,10 @@ import {
ReadResourceResult,
ListResourcesResultSchema,
ReadResourceResultSchema,
ListPromptsResult,
ListPromptsResultSchema,
GetPromptResult,
GetPromptResultSchema,
} from "mcp-typescript/types.js";
export class McpClient {
@@ -62,6 +66,26 @@ export class McpClient {
);
}
// Prompt Operations
async listPrompts(): Promise<ListPromptsResult> {
return await this.client.request(
{
method: "prompts/list",
},
ListPromptsResultSchema,
);
}
async getPrompt(name: string): Promise<GetPromptResult> {
return await this.client.request(
{
method: "prompts/get",
params: { name },
},
GetPromptResultSchema,
);
}
getServerCapabilities() {
return this.client.getServerCapabilities();
}

View File

@@ -7,7 +7,6 @@ const app = express();
const server = http.createServer(app);
const wss = new WebSocketServer({ server });
// Create and connect the MCP client
const mcpClient = new McpClient("MyApp", "1.0.0");
await mcpClient.connectStdio(
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node",
@@ -25,6 +24,12 @@ wss.on("connection", (ws: WebSocket) => {
} else if (command.type === "readResource" && command.uri) {
const resource = await mcpClient.readResource(command.uri);
ws.send(JSON.stringify({ type: "resource", data: resource }));
} else if (command.type === "listPrompts") {
const prompts = await mcpClient.listPrompts();
ws.send(JSON.stringify({ type: "prompts", data: prompts }));
} else if (command.type === "getPrompt" && command.name) {
const prompt = await mcpClient.getPrompt(command.name);
ws.send(JSON.stringify({ type: "prompt", data: prompt }));
}
} catch (error) {
console.error("Error:", error);