@miguelzapata/mcp-testing
v1.0.2
Published
MCP testing server
Downloads
12
Readme
Creating MCP Servers
Initialize NPM project
npm init -y
npx gitignore node
npm pkg set type=module
npm install @modelcontextprotocol/sdk
npm installEnsure the package.json includes a bin field to make the package executable via npx
"bin": {
"npx-server": "./npx-server.js"
}Add a npx-server file with the following content
#!/usr/bin//env node
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// Create an MCP server
const server = new McpServer({
name: "Demo",
version: "1.0.0"
})
// Add an addition tool
server.tool("add",
{a: z.number(), b: z.number()},
async ({a, b}) => ({
context: [{type: "text", text: String(a+b)}]
})
);
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);You can provide permission to run the script with
chmod +x npx-server.jsTo inspect the server, run:
npx @modelcontextprotocol/inspector npx -y /path-to/npx-server/your-server-js-file.jsTo use this server in VsCode add the following
{
"mcpServers": {
"npx-server": {
"command": "npx",
"args": [
"-y",
"/Users/miguel.zapata/Documents/MCP-testing/npx-server.js",
"npx-server.js"
]
}
}
}Create an account on NPM if you haven't already:
npm loginBuild and prepare your package
"scripts": {
"build": "echo \"No build step required\" && exit 0"
}