home / mcp / learn mcp by building mcp server
Provides a framework to build MCP-compatible servers and clients for tool interaction.
Configuration
View docs{
"mcpServers": {
"ashiknesin-learn-mcp-by-building": {
"url": "http://localhost:5000/sse"
}
}
}Model Context Protocol (MCP) lets your AI tools connect to external data sources and perform actions through a standardized, extensible interface. With MCP, you can list available tools, invoke them with parameters, and receive structured results and errors in a consistent format, enabling rich tool integration for AI assistants.
You use MCP by running an MCP-compatible server locally or remotely and then connecting with an MCP client. Depending on how you prefer to run it, you can operate through a local STDIO server for direct process I/O interactions or through an HTTP+SSE server for network-based access. Once connected, you can list available tools, call tools with the required arguments, and view results and logs in real time.
Prerequisites: install Node.js 20.x or later and a package manager such as npm or pnpm.
1) Clone the project and navigate into it.
2) Install dependencies.
STDIO Server and Client; run the STDIO server with a local process and test with a local client.
npm run server:stdio
# or
node src/examples/stdio-server.jsHTTP+SSE server exposes an MCP endpoint over HTTP; test with the corresponding client. The web-based client interface is available when the server is running.
npm run server:sse
# or
node src/examples/http-sse-server.js --port 5000
```
Available options:
- `--port` to specify the listening port (default: 5000)
- `--host` to bind to a host (default: localhost)
- `--path` endpoint path (default: /sse)
- `--cors` enable CORS (default: true)
- `--serve-static` serve static files from src/examples/public (default: true)Use the MCP Inspector to debug and visualize server activity. Start the inspector, then connect your MCP server to gain a visual interface for monitoring messages and tool interactions.
npm run debug
```
The MCP Inspector provides a visual interface for monitoring and debugging MCP servers.The Calculator tool supports basic arithmetic operations and exposes the following parameters and error cases.
Operations: add, subtract, multiply, divide.
Parameters: operation, a, b.
Error Handling: division by zero, invalid operations, type validation, missing parameters.
A calculator tool that performs add, subtract, multiply, and divide operations with parameters a, b, and operation. It includes error handling for division by zero, invalid operations, type validation, and missing parameters.