@railblocks/npx-server
v1.0.0
Published
## Creating MCP Servers
Readme
MCP (Model Context Protocol)
Creating MCP Servers
A Simple npx-based MCP Server
This project provides a simple MCP server that can be executed via npx. The server includes an "add" tool that performs addition of two numbers.
chmod +x npx-server.jsTo inspect the server, run:
npx @modelcontextprotocol/inspector npx -y /path-to/npx-server/your-server-js-file.jse.g.
npx @modelcontextprotocol/inspector npx -y /Users/flo/Builds/learning/npx-server.jsUsage
Running the Server
You can run this MCP server in several ways:
Via npx (recommended):
npx learningDirect execution:
./npx-server.jsWith Node.js:
node npx-server.js
Available Tools
- add: Adds two numbers together
- Parameters:
a(number),b(number) - Returns: The sum as a text string
- Parameters:
Testing with MCP Inspector
The MCP Inspector provides a web interface to test your server:
npx @modelcontextprotocol/inspector npx -y learningThis will:
- Start the MCP Inspector
- Launch your server via npx
- Open a web interface where you can test the "add" tool
MCP Client Configuration
Using with Claude Desktop, Cursor, or Windsurf
To use this server in Claude Desktop, Cursor, or Windsurf, add the following configuration:
{
"mcpServers": {
"npx-server": {
"command": "npx",
"args": [
"-y",
"/Users/flo/Builds/learning/npx-server.js"
]
}
}
}Note: Replace /Users/flo/Builds/learning/npx-server.js with the actual path to your npx-server.js file.
Configuration File Locations:
- Claude Desktop (macOS):
~/Library/Application Support/Claude/claude_desktop_config.json - Claude Desktop (Windows):
%APPDATA%\Claude\claude_desktop_config.json - Cursor: Add to your Cursor MCP settings
- Windsurf: Add to your Windsurf MCP settings
Alternative: Using the published package
If you publish this package to npm, you can use a simpler configuration:
{
"mcpServers": {
"npx-server": {
"command": "npx",
"args": ["-y", "learning"]
}
}
}Installation
npm installDependencies
@modelcontextprotocol/sdk: MCP SDK for creating serverszod: Schema validation for tool parameters
Publish an MCP service to the NPM Registry
You'll also need to update the package name to start with your org, e.g. "@trelis/npx-server"
npm install
npm run build # Ensures build script exists, even if no compilation is needed. You don't need this if it's a simple javascript MCP.- Build and prepare your package:
- For simple JavaScript projects, the build script might just be a placeholder
- Add a minimal build script to
package.jsonif missing:
"scripts": {
"build": "echo \"No build step required\" && exit 0"
}- Publish the package:
npm publish --access public # Use --access public for open-source packages