mcp-from-scratch
A complete hands-on guide to mastering Model Context Protocol (MCP) from scratch — covering fundamentals, tool building, security, and real-world DevOps use cases.
claude mcp add --transport stdio bhuvan-raj-mcp-from-scratch node server.js \ --env PORT="3000" \ --env MCP_ENV="production"
How to use
This MCP server provides a foundational implementation of the Model Context Protocol (MCP) designed for learning and experimentation. It supports standard MCP tooling concepts such as tool registration, structured input/output according to JSON schemas, and both STDIO and HTTP/S transports for communication between the client (LLM) and the server. You can run the server locally and use its tooling surface to discover registered tools, invoke them through the MCP protocol, and observe how responses are shaped by explicit input/output schemas and error models. The included setup is geared toward exploring safe and scalable tool integrations, permission boundaries, and the flow of structured data between AI models and external utilities.
To interact, start the server with the provided command and connect a client (such as an MCP-aware LLM or a CLI tool) over HTTP or STDIO. Use the discovery mechanism to enumerate available tools, send tool invocation requests with the required input, and receive validated, schema-driven outputs. The server is designed to illustrate common MCP patterns: stateless request handling, clear tool definitions, transport-appropriate message framing, and structured error handling that helps prevent hallucinations during tool calls.
How to install
Prerequisites:
- Node.js (14.x or newer) installed on your machine
- Basic familiarity with running Node.js applications
Installation steps:
-
Clone the repository: git clone https://github.com/bhuvan-raj/mcp-from-scratch.git cd mcp-from-scratch
-
Install dependencies: npm install
-
Configure environment (optional):
- Create a .env file or export variables as needed
- Example: export MCP_ENV=production export PORT=3000
-
Start the MCP server: npm run start or if a direct node script is provided: node server.js
-
Verify the server is running (default port 3000): curl http://localhost:3000/health
Notes:
- If your setup uses a different entry point or custom scripts, adjust the start command accordingly.
- Ensure any required tool definitions are registered before attempting tool invocations.
Additional notes
Tips and common considerations:
- Transport choices: The server supports STDIO and HTTP transports; choose based on your client integration needs.
- Schema-driven safety: Rely on the defined input/output schemas to prevent invalid data or unsafe tool usage.
- Environment variables: Use MCP_ENV to switch between environments (development, staging, production) and PORT to expose the correct endpoint.
- Troubleshooting: If tool discovery fails, verify the tool registration phase and confirm the server is reachable on the configured port. Check logs for schema validation errors or permission-related messages.
- Extensibility: This setup is intended as a learning scaffold; you can extend it by adding new tools, richer error models, and additional transports to reflect real-world MCP deployments.
Related MCP Servers
code-mode
🔌 Plug-and-play library to enable agents to call MCP and UTCP tools via code execution.
crawlbase
Crawlbase MCP Server connects AI agents and LLMs with real-time web data. It powers Claude, Cursor, and Windsurf integrations with battle-tested web scraping, JavaScript rendering, and anti-bot protection enabling structured, live data inside your AI workflows.
shellguard
MCP server that gives LLM agents read-only shell access over SSH
xcatcher -manifest
Agent-first Remote MCP for X (Twitter) batch crawling with x402 USDC top-up (Base/Solana). Includes OpenAPI + copy-paste ADK/curl E2E examples.
mcp-datadog
A Datadog MCP implemented in C# that exposes logs, metrics, traces, and monitors as structured context for AI agents, enabling automated observability analysis, test validation, incident investigation, and operational insights.
jenkins
MCP server for Jenkins CI/CD - Intelligent automation server integration for GenAI