A complete implementation of the Model Context Protocol (MCP) demonstrating a bidirectional server-client architecture with AI integration. This project showcases how to build scalable, protocol-based communication systems with tool invocation, resource management, and prompt handling.
This repository contains two main components:
- MCP Server: Exposes tools, resources, and prompts via the Model Context Protocol
- MCP Client: Interactive CLI client that communicates with the server and integrates Google Gemini for intelligent query handling
The project demonstrates practical patterns for building AI-augmented applications using standardized protocols.
-
Tools: Callable functions that perform specific operations
create-user: Create users with name, email, address, and phoneget_github_repos: Fetch public repositories from a GitHub usercreate-random-user: Generate random user data using AI
-
Resources: Queryable data sources with support for templated URIs
expenses://all: Access all expenses dataexpenses://daily-total/{month}/{day}: Query daily expense totals by month and day
-
Prompts: Pre-configured AI prompts for common tasks
explain_sql_query: Generate detailed explanations of SQL queries
-
Bidirectional Communication: Server can send sampling requests back to the client
- Interactive CLI Menu: Navigate tools, resources, and prompts easily
- AI Integration: Google Gemini API integration for intelligent responses
- Dynamic Input Handling: Automatically generates input prompts based on tool/resource requirements
- Query System: Submit natural language queries that leverage server tools
- Node.js 18+
- npm or yarn
- Google Gemini API key
# Clone the repository
git clone https://github.com/surojcodes/mcp-server-client.git
cd mcp-server-client
# Install dependencies
npm installCreate a .env file in the root directory:
GEMINI_API_KEY=your_gemini_api_key_here# Build the TypeScript files
npm run server:build
# Or watch for changes during development
npm run server:build:watch# Start the server (in one terminal)
npm run server:inspect
# Start the client in another terminal
npm run client:devOnce the client connects to the server, you'll see an interactive menu:
What do you want to do?
β― Query
Tools
Prompts
Resources
Resource Templates
- Select "Tools" from the menu
- Choose a tool from the list
- Provide input values as prompted
- View the tool's response
- Select "Resources" from the menu
- Choose a resource or resource template
- For templated resources, provide parameter values
- View the resource data (formatted as JSON)
- Select "Prompts" from the menu
- Choose a prompt
- Provide any required arguments
- Review the prompt and confirm to run it with Gemini
- Select "Query" from the menu
- Enter a natural language question
- The AI model processes your query using available tools
- View the generated response
mcp-server-client/
βββ src/
β βββ server.ts # MCP Server implementation
β βββ client.ts # MCP Client implementation
β βββ data/
β βββ users.json # User data storage
β βββ expenses.json # Expense data storage
βββ dist/ # Compiled JavaScript output
βββ package.json
βββ tsconfig.json
βββ README.md
npm run server:build- Compile TypeScript to JavaScriptnpm run server:build:watch- Watch TypeScript files and recompile on changesnpm run server:inspect- Run server with MCP Inspector for debuggingnpm run client:dev- Run the client CLI
Use the MCP Inspector to debug the server:
npm run server:inspectThis opens a browser interface to inspect server state and test tools/resources.
@modelcontextprotocol/sdk- MCP protocol implementation@ai-sdk/google- Google Generative AI integrationai- AI utilities and text generation@inquirer/prompts- Interactive CLI promptsdotenv- Environment variable managementzod- TypeScript-first schema validation
typescript- TypeScript compilertsx- TypeScript executor for Node.js@types/node- Node.js type definitions@modelcontextprotocol/inspector- MCP Inspector tool
The client uses Google's Gemini API for:
- Processing natural language queries
- Generating random user data for testing
- Explaining SQL queries through prompts
- Intelligent context-aware responses
Stores created users with:
id: Unique identifiername: User's full nameemail: User's email addressaddress: User's physical addressphone: User's phone number
Stores expenses organized by month with:
date: Day of the monthdescription: Expense descriptionamount: Expense amount
- The
DANGEROUSLY_OMIT_AUTH=trueflag in the inspector command disables authentication for development only - Never use this flag in production
- Always protect your Gemini API key
- Validate and sanitize all user inputs
This project demonstrates:
- Protocol-based client-server architecture
- Tool invocation and resource management
- AI model integration with TypeScript
- Interactive CLI design patterns
- Bidirectional RPC communication
MIT
Contributions are welcome! Feel free to submit issues or pull requests.
Happy coding! π