I am trying to create a greet mcp server and it simply does not work when I try to connect.
cursor version
Version: 0.46.11
VSCode Version: 1.96.2
Commit: ae378be9dc2f5f1a6a1a220c6e25f9f03c8d4e10
Date: 2025-03-07T06:43:50.208Z (1 mo ago)
Electron: 32.2.6
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 23.5.0
name: echo
type: command
command: node /Users/luisvalgoi/Development/.../src/index.js
package.json
{
"name": "echo-mcp",
"version": "1.0.0",
"description": "Echo MCP Server Example",
"type": "module",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js"
},
"dependencies": {
"@modelcontextprotocol/sdk": "1.9.0",
"zod": "3.22.4"
}
}
MCP Server
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// Initialize the MCP server
const server = new McpServer({
name: "Echo",
version: "1.0.0"
});
server.resource(
"echo",
new ResourceTemplate("echo://{message}", { list: undefined }),
async (uri, { message }) => ({
contents: [{
uri: uri.href,
text: `Resource echo: ${message}`
}]
})
);
server.tool(
"echo",
{ message: z.string() },
async ({ message }) => ({
content: [{ type: "text", text: `Tool echo: ${message}` }]
})
);
// Function to start the server
async function startServer() {
try {
// Start the server with stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);
} catch (error) {
process.stderr.write(`Failed to start server: ${error.message}\n`);
process.exit(1);
}
}
// Start the server
startServer();