Create Your First MCP Server (Non-Engineer Track)

Goal

Add a greeting tool to your MCP server.

Prompt

Copy and paste this entire prompt into Cursor:

1Update my MCP server to include a greeting tool.
2
3File to modify: `my-mcp-server/src/index.ts`
4
5Replace the entire contents with:
6
7```typescript
8import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10import { z } from 'zod';
11
12const server = new McpServer({
13    name: 'my-mcp-server',
14    version: '1.0.0'
15});
16
17// Greeting tool
18server.registerTool(
19    'greet',
20    {
21        title: 'Greet',
22        description: 'Greet someone by name',
23        inputSchema: {
24            name: z.string().describe('The name of the person to greet')
25        },
26        outputSchema: {
27            greeting: z.string()
28        }
29    },
30    async ({ name }) => {
31        const output = { greeting: `Hello, ${name}! Welcome to MCP.` };
32        return {
33            content: [{ type: 'text', text: output.greeting }],
34            structuredContent: output
35        };
36    }
37);
38
39const transport = new StdioServerTransport();
40await server.connect(transport);
41```
42
43What this tool does:
44- Tool name: greet
45- Input: Takes a name parameter (text)
46- Output: Returns a greeting like "Hello, Alice! Welcome to MCP."
47
48Success criteria:
49- The file is saved without errors
50- No red underlines in the editor (after a moment for TypeScript to check)

Expected Outcome

After running this prompt, your server will have a greet tool that:

  • Accepts a name
  • Returns a personalized greeting

Understanding What Changed

Part What it does
import { z } from 'zod' Imports the schema library
server.registerTool(...) Adds a new tool to the server
inputSchema: { name: z.string() } Defines that the tool needs a "name" text input
outputSchema: { greeting: z.string() } Defines that the tool returns a "greeting" text
async ({ name }) => { ... } The function that runs when the tool is called

Troubleshooting

Red underlines in the editor?

  • Wait a few seconds for TypeScript to process
  • If they persist, make sure npm install was run in the project folder

File not found?

  • Make sure you created the project in step 02
  • Check that you're in the right workspace