|
8 | 8 | CallToolResult,
|
9 | 9 | Tool,
|
10 | 10 | ListResourcesRequestSchema,
|
11 |
| - ListResourceTemplatesRequestSchema |
| 11 | + ListResourceTemplatesRequestSchema, |
| 12 | + ListPromptsRequestSchema, |
| 13 | + GetPromptRequestSchema |
12 | 14 | } from "@modelcontextprotocol/sdk/types.js";
|
13 | 15 |
|
14 | 16 | import { Stagehand } from "@browserbasehq/stagehand";
|
@@ -301,6 +303,15 @@ const TOOLS: Tool[] = [
|
301 | 303 | },
|
302 | 304 | ];
|
303 | 305 |
|
| 306 | +// Define the prompts |
| 307 | +const PROMPTS = [ |
| 308 | + { |
| 309 | + name: "click_search_button", |
| 310 | + description: "A prompt template for clicking on a search button", |
| 311 | + arguments: [] // No arguments required for this specific prompt |
| 312 | + } |
| 313 | +]; |
| 314 | + |
304 | 315 | // Global state
|
305 | 316 | let stagehand: Stagehand | undefined;
|
306 | 317 | let serverInstance: Server | undefined;
|
@@ -649,6 +660,7 @@ const server = new Server(
|
649 | 660 | resources: {},
|
650 | 661 | tools: {},
|
651 | 662 | logging: {},
|
| 663 | + prompts: {} |
652 | 664 | },
|
653 | 665 | }
|
654 | 666 | );
|
@@ -742,6 +754,61 @@ server.setRequestHandler(ListResourceTemplatesRequestSchema, async (request) =>
|
742 | 754 | }
|
743 | 755 | });
|
744 | 756 |
|
| 757 | +server.setRequestHandler(ListPromptsRequestSchema, async (request) => { |
| 758 | + try { |
| 759 | + logRequest('ListPrompts', request.params); |
| 760 | + const response = { prompts: PROMPTS }; |
| 761 | + const sanitizedResponse = sanitizeMessage(response); |
| 762 | + logResponse('ListPrompts', JSON.parse(sanitizedResponse)); |
| 763 | + return JSON.parse(sanitizedResponse); |
| 764 | + } catch (error) { |
| 765 | + const errorMsg = error instanceof Error ? error.message : String(error); |
| 766 | + return { |
| 767 | + error: { |
| 768 | + code: -32603, |
| 769 | + message: `Internal error: ${errorMsg}`, |
| 770 | + }, |
| 771 | + }; |
| 772 | + } |
| 773 | +}); |
| 774 | + |
| 775 | +server.setRequestHandler(GetPromptRequestSchema, async (request) => { |
| 776 | + try { |
| 777 | + logRequest('GetPrompt', request.params); |
| 778 | + |
| 779 | + // Check if prompt name is valid |
| 780 | + if (request.params?.name !== "click_search_button") { |
| 781 | + throw new Error(`Invalid prompt name: ${request.params?.name}`); |
| 782 | + } |
| 783 | + |
| 784 | + // Return a prompt for clicking on a search button |
| 785 | + const response = { |
| 786 | + description: "This prompt provides instructions for clicking on a search button", |
| 787 | + messages: [ |
| 788 | + { |
| 789 | + role: "user", |
| 790 | + content: { |
| 791 | + type: "text", |
| 792 | + text: "Please click on the search button" |
| 793 | + } |
| 794 | + } |
| 795 | + ] |
| 796 | + }; |
| 797 | + |
| 798 | + const sanitizedResponse = sanitizeMessage(response); |
| 799 | + logResponse('GetPrompt', JSON.parse(sanitizedResponse)); |
| 800 | + return JSON.parse(sanitizedResponse); |
| 801 | + } catch (error) { |
| 802 | + const errorMsg = error instanceof Error ? error.message : String(error); |
| 803 | + return { |
| 804 | + error: { |
| 805 | + code: -32603, |
| 806 | + message: `Internal error: ${errorMsg}`, |
| 807 | + }, |
| 808 | + }; |
| 809 | + } |
| 810 | +}); |
| 811 | + |
745 | 812 | // Run the server
|
746 | 813 | async function runServer() {
|
747 | 814 | const transport = new StdioServerTransport();
|
|
0 commit comments