MCP Server Demo - Learning Project

MCP Server Demo - Learning Project

A comprehensive learning project demonstrating MCP server implementation with tools for calculator operations, file management, and system information retrieval, including Google ADK integration patterns and best practices.

Category
Visit Server

README

MCP Server Demo - Learning Project

A comprehensive learning project demonstrating how to build a Model Context Protocol (MCP) server with Google ADK integration using best practices.

๐ŸŽฏ Learning Objectives

This project teaches you:

  1. MCP Server Architecture

    • How to structure an MCP server
    • Tool definitions and handlers
    • Resource management
    • Error handling patterns
  2. Best Practices

    • TypeScript for type safety
    • Separation of concerns
    • Input validation and security
    • Error handling
    • Extensible architecture
  3. Google ADK Integration

    • Integration points for Google Actions
    • Analytics and logging
    • Fulfillment handlers (placeholder)

๐Ÿ“ Project Structure

mcp-server-demo/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts              # Main server entry point
โ”‚   โ”œโ”€โ”€ tools/
โ”‚   โ”‚   โ”œโ”€โ”€ base-tool.ts      # Base tool interface
โ”‚   โ”‚   โ”œโ”€โ”€ calculator.ts     # Calculator tool example
โ”‚   โ”‚   โ”œโ”€โ”€ file-operations.ts # File operations tool
โ”‚   โ”‚   โ””โ”€โ”€ system-info.ts    # System information tool
โ”‚   โ””โ”€โ”€ integrations/
โ”‚       โ””โ”€โ”€ google-adk.ts     # Google ADK integration
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode (with auto-reload)
npm run dev

# Run the built server
npm start

๐Ÿ› ๏ธ Available Tools

1. Calculator Tool

Perform basic mathematical operations.

Example:

{
  "name": "calculator",
  "arguments": {
    "operation": "add",
    "a": 10,
    "b": 5
  }
}

2. File Operations Tool

Read, write, list, and get info about files.

Example:

{
  "name": "file_operations",
  "arguments": {
    "operation": "read",
    "path": "README.md"
  }
}

3. System Info Tool

Get system information (platform, memory, CPU, etc.).

Example:

{
  "name": "system_info",
  "arguments": {
    "detail": "full"
  }
}

๐Ÿ”Œ Google ADK Integration

The project includes a Google ADK integration module that demonstrates:

  • Analytics Logging: Track tool usage
  • Fulfillment Handlers: Process Google Assistant requests (placeholder)
  • Usage Statistics: Get insights into tool usage

Enabling Google ADK

Set the environment variable:

export GOOGLE_ADK_ENABLED=true

Next Steps for Full Integration

  1. Set up Google Actions Project

    • Create a project in Google Cloud Console
    • Enable Actions API
    • Set up OAuth credentials
  2. Implement Webhook Server

    • Use Express.js or similar
    • Handle fulfillment requests
    • Connect to MCP server tools
  3. Deploy

    • Deploy to Google Cloud Functions or Cloud Run
    • Configure webhook URL in Actions Console

๐Ÿ“š Best Practices Demonstrated

1. Type Safety

  • Full TypeScript implementation
  • Strict type checking enabled
  • Interface definitions for all tools

2. Security

  • Path validation (prevents directory traversal)
  • Input sanitization
  • Error message sanitization

3. Error Handling

  • Comprehensive try-catch blocks
  • Meaningful error messages
  • Graceful degradation

4. Code Organization

  • Separation of concerns
  • Modular tool architecture
  • Clear abstraction layers

5. Extensibility

  • Easy to add new tools (extend BaseTool)
  • Plugin-like architecture
  • Configuration-driven behavior

๐Ÿงช Testing Your MCP Server

Using Claude Desktop

  1. Add to Claude Desktop configuration:
{
  "mcpServers": {
    "demo": {
      "command": "node",
      "args": ["/path/to/mcp-server-demo/dist/index.js"]
    }
  }
}
  1. Restart Claude Desktop
  2. The tools should be available in Claude

Using MCP Client

You can also test with an MCP client library or create a simple test script.

๐ŸŽ“ Learning Path

Beginner Tasks

  1. โœ… Understand the project structure
  2. โœ… Run the server and test tools
  3. โœ… Read through the code comments
  4. โœ… Modify calculator tool to add new operations

Intermediate Tasks

  1. Add a new tool (e.g., weather tool using an API)
  2. Implement resource caching
  3. Add tool usage rate limiting
  4. Create unit tests for tools

Advanced Tasks

  1. Implement full Google ADK webhook server
  2. Add authentication/authorization
  3. Implement tool chaining
  4. Add streaming responses
  5. Create a remote MCP server (HTTP transport)

๐Ÿ“– Resources

๐Ÿค Contributing

This is a learning project! Feel free to:

  • Add more example tools
  • Improve error handling
  • Add tests
  • Enhance documentation

๐Ÿ“ License

MIT


Happy Learning! ๐Ÿš€

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured