Sometimes we have longer prompts that we write repeatedly. Maybe it is to add specific constraints or to reference specific resources or tools. In these cases, we can add prompts to the MCP server that then will be available for the end user to use in order to speed up the process of creating a prompt.
We start by creating a method that accepts the MCPServer as input and that we will use to register all the prompts.
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import z from "zod";
function registerPrompts(server: McpServer) {
server.registerPrompt(
"deliver-package", // Unique identifier for the prompt
{
title: "Deliver Package", // Title of the prompt
description: "A prompt for delivering a package using a drone", // Description of the prompt
argsSchema: {
numberOfPackages: z.string().describe("The number of packages to be delivered"),
packageWeight: z.string().describe("The weight of each package in kg"),
}
},
({ numberOfPackages, packageWeight }) => {
// The function that gets executed when the prompt is called
return {
messages: [
{
role: "user",
content: {
type: "text",
text: `
Your task is to deliver packages using drones.
Use the tools #list-drones-requirements and #list-drones to find the most suitable drones for the delivery
You have to deliver ${numberOfPackages} packages, each weighing ${packageWeight} kg.`
}
}
]
}
}
);
}
// Export the registerPrompts function
export { registerPrompts }We can then use this function in our server setup to register the prompts. After adding the prompts the server setup file will look like this:
// Importing the MCP Server class from the SDK
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
// Importing the function for registrering resources
import { addResources } from "./resources.js";
// Import the function to register tools
import { registerTools } from "./tools.js";
import { registerPrompts } from "./prompts.js";
// Creating the MCP server instance with a name and version
const server = new McpServer({
name: "My MCP Server",
version: "1.0.0",
});
// Use the function to register the resources.
addResources(server);
// Use the function to register the tools.
registerTools(server);
// Use the function to register the prompts.
registerPrompts(server);
// Exporting the server so that we can use it in other parts of our application
export { server };Running the server again we should be able to see the prompts in the mcp.json file where the connection is defined.
We can use the prompt feature in GitHub Copilot by referencing the prompt by its unique identifier. The naming convention is /mcp.<server-name>.<prompt-id>.
After filling in the parameters we should see the prompt being used in the response. We can then shape or edit the prompt as we like.


