A Model Context Protocol (MCP) server for wallet and computation tools.
Project description
Eolas MCP Server (Python Edition)
A Model Context Protocol (MCP) server built with Python that provides tools for AI assistants to interact with external systems and perform computations. This project follows MCP best practices with comprehensive error handling, secure configuration management, and proper lifecycle management.
What is MCP?
The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect to external data sources and tools. MCP servers expose functionality through tools that language models can discover and invoke automatically.
Features
- 🔧 Extensible Tool System: Easy-to-add custom tools using FastMCP decorators
- 🐍 Python-Powered: Leverage the extensive Python ecosystem
- 🔒 Secure Wallet: Encrypted wallet management with system keyring integration
- 🛡️ Security First: Environment-based configuration, proper error handling, and secure credential storage
- 📊 Comprehensive Logging: Structured logging with proper error tracking
- ⚡ Resource Management: Proper server lifecycle with startup/shutdown handling
- 🎯 Input Validation: Pydantic-based input validation for all tools
MCP Best Practices Implemented
This server follows official MCP best practices:
- ✅ FastMCP with Context: Uses Context objects for proper logging and error handling
- ✅ Environment Configuration: Uses
.envfiles for secure configuration - ✅ Proper Error Handling: Comprehensive try-catch blocks with meaningful error messages
- ✅ Input Validation: Pydantic models for type-safe input validation
- ✅ Lifecycle Management: Proper server startup and shutdown with resource cleanup
- ✅ Security: Encrypted storage with system keyring integration
- ✅ Resources: Exposes wallet information as MCP resources
- ✅ Structured Logging: Uses Python logging instead of print statements
Getting Started
Prerequisites
- Python 3.10+
pipfor package management
Installation
-
Clone the repository:
git clone <your-repo-url> cd eolas-mech-mcp/eolas-mcp-server
-
Set up a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment (optional):
cp env.example .env # Edit .env with your preferred settings
Configuration
The server uses environment variables for configuration. Create a .env file:
# Optional: Custom file paths
WALLET_FILE_PATH=./wallet.json
PASSWORD_FILE_PATH=./password.txt
Available Tools
add
Adds two numbers and returns the result with comprehensive error handling.
Parameters:
a(int): First number to addb(int): Second number to add
Example Usage:
"Add 42 and 58"
top_up
Top up the balance of the user. Provides a deposit address or generates a new Ethereum wallet if one doesn't exist. Uses secure wallet management with encrypted storage.
Parameters:
- None
Example Usage:
"Top up my account"
Available Resources
wallet://address
Returns the current wallet address if available.
wallet://balance
Returns the current wallet balance in ETH.
Security Features
- Encrypted Private Keys: Private keys are encrypted using AES-GCM before storage
- System Keyring: Passwords are stored in the system keyring when available
- Restricted Permissions: Wallet and password files have restricted file permissions (600)
- Environment Variables: Sensitive configuration through environment variables
- Input Validation: All inputs are validated using Pydantic models
- Error Handling: Comprehensive error handling prevents information leakage
Adding New Tools
To add a new tool, simply define a function with the @mcp.tool() decorator in the server file:
@mcp.tool()
def multiply(a: int, b: int, ctx: Context) -> str:
"""
Multiplies two numbers and returns the result.
Args:
a: First number to multiply
b: Second number to multiply
ctx: MCP context for logging and error handling
Returns:
String representation of the result
"""
try:
# Validate inputs if needed
if not isinstance(a, int) or not isinstance(b, int):
ctx.error("Invalid input types")
return "Error: Both inputs must be integers"
result = a * b
ctx.info(f"Multiplication performed: {a} × {b} = {result}")
return f"The result is {result}"
except Exception as e:
ctx.error(f"Error in multiply tool: {e}")
return f"Error: Failed to perform multiplication - {str(e)}"
Adding to Cursor
To use this MCP server with Cursor:
-
Install the package from PyPI:
pip install eolas-mech-mcp
-
Open Cursor Settings:
- Press
Cmd/Ctrl + ,to open settings. - Search for "MCP" or navigate to Extensions → MCP.
- Press
-
Edit your MCP configuration by adding a new server entry. The command is now much simpler:
{ "mcpServers": { "eolas-mcp-server-python": { "command": "eolas-mech-mcp", "args": [], } } }
-
Restart Cursor: Close and reopen Cursor for the changes to take effect.
Development
Running the Server Locally
For development, you can run the server directly from the source code without installing the package.
-
Set up a virtual environment and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Run the server:
python -m src
You should see structured log output indicating the server is running.
Packaging for Distribution
To publish your server to PyPI:
-
Install build tools:
pip install build twine
-
Build the package:
python -m build
This will create
dist/directory with the package files. -
Upload to PyPI:
twine upload dist/*
You will need a PyPI account and an API token for this step.
Testing with MCP Inspector
You can test your server using the MCP Inspector tool:
npx @modelcontextprotocol/inspector eolas-mech-mcp
Project Structure
eolas-mcp-server/
├── src/
│ ├── __init__.py
│ ├── __main__.py # Entry point for `python -m src`
│ ├── server.py # Main server with tools and resources
│ └── utils/
│ ├── __init__.py
│ └── wallet.py # Secure wallet management
├── venv/ # Python virtual environment
├── requirements.txt # Python dependencies
├── pyproject.toml # Packaging configuration
└── README.md
Troubleshooting
Server not connecting
- Make sure you have activated the virtual environment (
source venv/bin/activate) - Check that the paths in your
mcp.jsonconfiguration are absolute and correct - Ensure all dependencies are installed with
pip install -r requirements.txt - Check the server logs for specific error messages
Tools not appearing
- Restart your MCP client (e.g., Cursor) after making changes
- Check the server's console output for any Python errors on startup
- Verify that your environment variables are properly set
Wallet issues
- Check file permissions on wallet.json and password.txt (should be 600)
- Verify the Ethereum RPC endpoint is accessible
- Check that the keyring system is working on your platform
Connection issues
- Verify the ETH_RPC_URL is correct and accessible
- Check your network connection
- Try using a different RPC endpoint
License
This project is licensed under the MIT License.
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eolas_mech_mcp-1.0.0.tar.gz.
File metadata
- Download URL: eolas_mech_mcp-1.0.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c62df3013162b092d06023e36ccae911b9a23ea3c5eaf4d37eaa4025a252925
|
|
| MD5 |
0d370ae93ccd54433d7a9dc66fa7fa5f
|
|
| BLAKE2b-256 |
66090823f5b30eba7285c8dac7975d06da740e2fc890b52e0c1aed987424793a
|
File details
Details for the file eolas_mech_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: eolas_mech_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7422898c680db4ecae2223cca49289472cc4be3a2a3560d99516c94df99bfd65
|
|
| MD5 |
783efa69848107774896dbc7d5f45fe7
|
|
| BLAKE2b-256 |
6ca0d8461714f98116896d4004ed1d85f4d16b2d356d00b9188c0536b473e1d5
|