dinek-k/MCP-Server-Example-1
If you are the rightful owner of MCP-Server-Example-1 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 is a Model Context Protocol (MCP) server that provides database and calculator tools.
query_database
Execute custom SQL queries.
get_all_users
Retrieve all users with optional limit.
get_user_by_id
Get a specific user by ID.
add_user
Add a new user to the database.
calculate
Perform basic mathematical operations.
MCP Example Server
This is a Model Context Protocol (MCP) server that provides two main categories of tools:
- Database Tools - For interacting with a SQLite database
- Calculator Tools - For performing mathematical calculations
Features
Database Tools
query_database
- Execute custom SQL queriesget_all_users
- Retrieve all users with optional limitget_user_by_id
- Get a specific user by IDadd_user
- Add a new user to the databaseupdate_user
- Update an existing userdelete_user
- Delete a user from the database
Calculator Tools
calculate
- Perform basic mathematical operations (add, subtract, multiply, divide, power, sqrt, sin, cos, tan, log, abs, round, floor, ceil)calculate_expression
- Evaluate mathematical expressionscalculate_stats
- Calculate statistical measures (mean, median, variance, standard deviation, etc.)
Installation
- Install dependencies:
npm install
- The database will be automatically created when you first run the server.
Usage
Starting the Server
npm start
Or for development with auto-restart:
npm run dev
Database Schema
The server creates a SQLite database with the following schema:
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
age INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
Sample data is automatically inserted when the database is first created.
Tool Examples
Database Operations
- Get all users:
{
"name": "get_all_users",
"arguments": {}
}
- Get user by ID:
{
"name": "get_user_by_id",
"arguments": {
"id": 1
}
}
- Add a new user:
{
"name": "add_user",
"arguments": {
"name": "John Doe",
"email": "john@example.com",
"age": 30
}
}
- Execute custom query:
{
"name": "query_database",
"arguments": {
"query": "SELECT * FROM users WHERE age > 25"
}
}
Calculator Operations
- Basic calculation:
{
"name": "calculate",
"arguments": {
"operation": "add",
"numbers": [5, 3]
}
}
- Evaluate expression:
{
"name": "calculate_expression",
"arguments": {
"expression": "2 + 3 * 4"
}
}
- Statistical analysis:
{
"name": "calculate_stats",
"arguments": {
"numbers": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
}
Available Calculator Operations
add
- Additionsubtract
- Subtractionmultiply
- Multiplicationdivide
- Division (with zero check)power
- Exponentiationsqrt
- Square rootsin
- Sine functioncos
- Cosine functiontan
- Tangent functionlog
- Natural logarithmabs
- Absolute valueround
- Round to nearest integerfloor
- Floor functionceil
- Ceiling function
Project Structure
āāā package.json
āāā README.md
āāā src/
ā āāā server.js # Main MCP server
ā āāā database.js # Database operations
ā āāā calculator.js # Calculator operations
āāā data/
āāā example.db # SQLite database (created automatically)
Error Handling
The server includes comprehensive error handling for:
- Invalid SQL queries
- Database connection issues
- Mathematical operation errors (division by zero, invalid inputs)
- Missing required parameters
- Unknown tool names
Development
To modify or extend the server:
- Add new tools in the
setupTools()
method inserver.js
- Implement corresponding handler methods
- Update the tools list in the
tools/list
handler - Add any necessary database operations in
database.js
- Add calculator functions in
calculator.js
Dependencies
@modelcontextprotocol/sdk
- MCP SDK for Node.jssqlite3
- SQLite database driverexpress
- Web framework (for potential future HTTP transport)
License
MIT