๐๐๐ถ๐น๐ฑ ๐ ๐ง๐ถ๐ป๐ ๐ ๐๐ฃ ๐ฆ๐ฒ๐ฟ๐๐ฒ๐ฟ ๐๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐
LLMs often hallucinate. You stop this with the Model Context Protocol (MCP). MCP lets models use real tools. Your models get live data from GitHub or databases.
Follow these steps to start:
- Use Node 18 or newer.
- Install @modelcontextprotocol/sdk and zod.
- Set type to module in your package.json.
Build your server:
- Create an McpServer instance.
- Define a tool with a name and description.
- Use zod to validate inputs.
- Connect using StdioServerTransport for local use.
Connect to your favorite AI:
- Claude Desktop: Add the server path to your config.
- Codex: Run the codex mcp add command.
- Gemini: Use HTTP transport for cloud setups.
Avoid these mistakes:
- Do not use deep imports. Use the .js extension.
- Use absolute paths in your config files.
- Store API keys in environment variables.
- Use node --trace-warnings to find import errors.
Source: https://dev.to/gaurav101/build-a-tiny-mcp-server-in-javascript-claude-codex-friendly-pbh Example code: https://github.com/gaurav101/ai-experiment Optional learning community: https://t.me/GyaanSetuAi