Pvbhat123/mcp_demonstration
If you are the rightful owner of mcp_demonstration and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive overview of a Model Context Protocol (MCP) server implementation using JSON-RPC 2.0.
Standard MCP Implementation with JSON-RPC
This is a standard-compliant Model Context Protocol (MCP) implementation using JSON-RPC 2.0 protocol.
Architecture
1. MCP Server (Port 4001)
- Implements MongoDB operations as MCP tools
- Uses JSON-RPC 2.0 protocol
- Supports standard MCP methods:
initialize,tools/list,tools/call - Proper error handling with standard error codes
2. MCP Client (Port 4002)
- Acts as orchestrator between Host and Server
- Maintains tool registry from multiple servers
- Routes tool calls using JSON-RPC protocol
- Supports server initialization handshake
3. MCP Host (Interactive CLI)
- User interface with Gemini AI integration
- Communicates via JSON-RPC with the Client
- Processes natural language queries
- Formats results for user consumption
Key Differences from REST Implementation
- Protocol: Uses JSON-RPC 2.0 instead of REST
- Message Format: All requests/responses follow JSON-RPC envelope:
{ "jsonrpc": "2.0", "method": "method_name", "params": {}, "id": "unique_id" } - Error Handling: Standard JSON-RPC error codes
- Single Endpoint: All communication through
/rpcendpoint - Request Correlation: Uses request IDs for tracking
- Initialization: Proper protocol handshake between components
Setup Instructions
Prerequisites
- Node.js installed
- MongoDB running on localhost:27017
- Gemini API key
Installation
-
Install dependencies for each component:
cd mcp_standard/mcp_server npm install cd ../mcp_client npm install cd ../mcp_host npm install -
Set up environment variables: Create a
.envfile inmcp_standard/mcp_host/:GEMINI_API_KEY=your-gemini-api-key
Running the System
Start each component in separate terminals:
-
Start MCP Server:
cd mcp_standard/mcp_server npm start -
Start MCP Client:
cd mcp_standard/mcp_client npm start -
Start MCP Host (Interactive CLI):
cd mcp_standard/mcp_host npm start
Testing the Implementation
Once all components are running, you can interact with the system through the Host CLI:
👤 Your question: list all databases
🤖 Processing...
📋 Response:
============================================================
I found 3 databases in your MongoDB instance:
1. **admin** - System database (320 KB)
2. **config** - Configuration database (192 KB)
3. **local** - Local database (256 KB)
All databases are currently active and not empty.
============================================================
Verifying MCP Compliance
This implementation follows the MCP standard by:
- Using JSON-RPC 2.0 protocol for all communications
- Implementing required methods:
initialize,tools/list,tools/call - Following standard error codes (-32700 to -32603)
- Supporting protocol version negotiation
- Using proper request/response correlation with IDs
- Implementing tool discovery with JSON Schema for parameters
API Examples
Initialize Request
{
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"protocolVersion": "1.0",
"clientInfo": {
"name": "mcp-client",
"version": "1.0.0"
}
},
"id": "init_1"
}
Tool Call Request
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "list_collections",
"arguments": {
"database_name": "mydb"
}
},
"id": "call_1"
}
Monitoring and Logging
JSON-RPC Message Logs
The implementation includes comprehensive JSON-RPC message logging. Each component logs all requests and responses in a formatted manner:
Log Files:
logs/mcp-server-jsonrpc.log- Server incoming/outgoing messageslogs/mcp-client-jsonrpc.log- Client incoming messages from hostlogs/mcp-client-outgoing-jsonrpc.log- Client outgoing messages to serverlogs/mcp-host-jsonrpc.log- Host outgoing messages to client
Log Format Example:
============================================================
Timestamp: 2024-01-20T10:30:45.123Z
Component: mcp-server
Direction: INCOMING
Type: REQUEST
============================================================
{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"id": "req_1234567890_1"
}
============================================================
============================================================
Timestamp: 2024-01-20T10:30:45.125Z
Component: mcp-server
Direction: OUTGOING
Type: RESPONSE
============================================================
{
"jsonrpc": "2.0",
"result": {
"tools": [
{
"name": "list_databases",
"description": "List all databases in MongoDB instance",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
}
}
]
},
"id": "req_1234567890_1"
}
============================================================
Viewing Logs
Use the included log viewer for real-time monitoring:
cd mcp_standard
node view-logs.js
This provides:
- Real-time log tailing
- Color-coded output
- Combined view of all components
- Log clearing functionality
Standard Log Files
Each component also maintains standard operation logs:
mcp-server-standard.logmcp-client-standard.logmcp-host-standard.log