This is a basic implementation of a Model Context Protocol (MCP) server built with the official @modelcontextprotocol/sdk, TypeScript, and Node.js. The server communicates over standard input/output (stdio) and provides a set of demo tools.
- Official SDK: Built using the official
@modelcontextprotocol/sdkfor robust MCP compliance. - Stdio Transport: Communicates using StdioServerTransport, receiving requests on stdin and sending responses on stdout.
- Demo Tools:
add: Adds two numbers together.get_city_weather_forecast: Provides a dummy weather forecast for a specified city.
- Analytics Integration: Includes a modular system to send analytics pings using the Google Analytics Measurement Protocol API whenever a tool is called.
- Secure Secret Management: Uses a
.envfile to manage sensitive API keys and measurement IDs, keeping them out of version control.
.
├── .env.example
├── .gitignore
├── .idx
│ └── dev.nix
├── node_modules
├── package-lock.json
├── package.json
├── src
│ ├── analytics.ts # Handles Google Analytics pings
│ └── index.ts # Main server logic and MCP implementation
└── tsconfig.json
Setup and Installation Follow these steps to get the server running locally.
- Install Dependencies Navigate to the project directory and install the required npm packages:
npm install
- Configure Environment Variables This project uses a .env file to store your Google Analytics credentials.
Create your local environment file by copying the example file:
cp .env.example .env
Open the newly created .env file and replace the placeholder values with your actual GA4 api_secret and measurement_id.
Note: The server will run without these credentials, but the analytics pings will be skipped. The .env file is included in .gitignore to prevent committing secrets.
The recommended way to interact with this server is by connecting it to the Gemini CLI.
- Build the Project
Before the server can be used, you must compile the TypeScript source code into JavaScript. This command creates a
dist/index.jsfile that the CLI will execute.
npm run build
- Configure Gemini CLI
Open the Gemini CLI settings file in your editor. It is located at
~/.gemini/settings.json.
Add an mcpServers configuration block to the JSON file.
{
"mcpServers": [
{
"name": "My Local Demo Server",
"command": ["node", "dist/index.js"],
"workingDirectory": "/path/to/your/mcp-sdk-demo-server"
}
]
}