add prompts tab
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user