A template repository for creating Model Context Protocol (MCP) servers using the PulseEngine MCP framework in Rust.
-
Use this template by clicking the "Use this template" button on GitHub
-
Clone your new repository:
git clone https://github.com/yourusername/your-mcp-server.git cd your-mcp-server
-
Customize the server:
- Update
Cargo.toml
with your project details - Modify
src/lib.rs
to implement your tools and resources - Update this README with your project information
- Update
-
Build and test:
cargo build # Test tools echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | ./target/debug/template-mcp-server # Test resources echo '{"jsonrpc":"2.0","id":2,"method":"resources/list","params":{}}' | ./target/debug/template-mcp-server
This template provides:
- Complete MCP server setup using PulseEngine MCP framework
- Automatic tool & resource discovery with
#[mcp_tools]
and#[mcp_resource]
macros - Example tools demonstrating different parameter types:
- Simple status check (no parameters)
- Echo with optional parameters
- Numeric calculations
- Structured data creation
- List processing
- Error handling examples
- Example resources for read-only data access:
- Server status information (
template://server-status
) - Server configuration (
template://server-config
) - Parameterized data lookup (
template://example-data/{id}
)
- Server status information (
- URI template support for parameterized resources
- STDIO transport for integration with MCP clients
- Proper logging configuration for debugging
template-mcp-server/
βββ Cargo.toml # Workspace configuration
βββ template-mcp-server/
β βββ Cargo.toml # Package configuration
β βββ src/
β β βββ main.rs # Server entry point
β β βββ lib.rs # Server implementation & tools
βββ README.md # This file
βββ LICENSE # MIT License
βββ .github/ # GitHub templates
βββ ISSUE_TEMPLATE/
βββ PULL_REQUEST_TEMPLATE.md
βββ dependabot.yml
Install globally to use with any MCP client:
npm install -g @yourusername/template-mcp-server
Or use directly with npx:
npx @yourusername/template-mcp-server
-
Prerequisites
- Rust 1.75.0 or later
- Git
- Node.js 16+ (for npm distribution)
-
Clone and Build
git clone https://github.com/yourusername/template-mcp-server.git cd template-mcp-server cargo build --release
-
Run the Server
./target/release/template-mcp-server
Pre-built binaries are available for:
- macOS (x64, arm64)
- Linux (x64, arm64)
- Windows (x64)
Download from GitHub Releases
cargo build
cargo run
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector
# Test your server
npx @modelcontextprotocol/inspector ./target/debug/template-mcp-server
# List available tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | ./target/debug/template-mcp-server
# Call a tool
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_status","arguments":{}}}' | ./target/debug/template-mcp-server
# List available resources
echo '{"jsonrpc":"2.0","id":3,"method":"resources/list","params":{}}' | ./target/debug/template-mcp-server
# Read a resource
echo '{"jsonrpc":"2.0","id":4,"method":"resources/read","params":{"uri":"template://server-status"}}' | ./target/debug/template-mcp-server
This template demonstrates both MCP Tools and MCP Resources:
Tools are functions that perform operations or modify state. They:
- Take parameters as input
- Can have side effects (create, update, delete)
- Return results from their execution
- Are called via
tools/call
method
Examples in template:
get_status()
- Checks server statusecho(message, prefix)
- Transforms inputadd_numbers(a, b)
- Performs calculationscreate_data(...)
- Creates new data
Resources provide read-only access to data. They:
- Use URI templates for identification
- Cannot modify state (read-only)
- Are accessed via
resources/read
method - Perfect for configuration, status, or reference data
Examples in template:
template://server-status
- Current server statustemplate://server-config
- Server configurationtemplate://example-data/{id}
- Data lookup by ID
Use Tools For | Use Resources For |
---|---|
Operations & actions | Read-only data access |
Data modification | Configuration settings |
Calculations | Status information |
API calls | Reference data |
File operations | Cached data |
Dynamic processing | Static information |
Edit template-mcp-server/Cargo.toml
:
[package]
name = "your-mcp-server"
description = "Your server description"
authors = ["Your Name <your.email@example.com>"]
repository = "https://github.com/yourusername/your-mcp-server"
In src/lib.rs
, modify the #[mcp_tools]
impl block:
#[mcp_tools]
impl YourMcpServer {
/// Your custom tool
pub async fn your_tool(&self, param: String) -> anyhow::Result<String> {
// Your implementation here
Ok(format!("Result: {}", param))
}
}
Add fields to your server struct:
#[mcp_server(name = "Your Server")]
#[derive(Clone)]
pub struct YourMcpServer {
data: Arc<RwLock<HashMap<String, String>>>,
config: YourConfig,
}
Modify the #[mcp_server]
attributes:
#[mcp_server(
name = "Your Amazing MCP Server",
version = "1.0.0",
description = "Does amazing things",
auth = "file" // or "memory", "disabled"
)]
Using npm installation:
{
"servers": {
"your-server": {
"command": "npx",
"args": ["@yourusername/template-mcp-server"]
}
}
}
Using local binary:
{
"servers": {
"your-server": {
"command": "/path/to/your-mcp-server",
"args": []
}
}
}
Using npm installation:
{
"mcpServers": {
"your-server": {
"command": "npx",
"args": ["@yourusername/template-mcp-server"]
}
}
}
Using local binary:
{
"mcpServers": {
"your-server": {
"command": "/path/to/your-mcp-server"
}
}
}
This template uses the PulseEngine MCP framework which provides:
- Automatic tool discovery - Public methods become MCP tools
- Type-safe parameter handling - Automatic JSON deserialization
- Error handling - Proper MCP error responses
- Authentication - Optional auth with multiple backends
- Transport support - STDIO, HTTP, WebSocket
- Monitoring - Built-in metrics and tracing
- Validation - Request/response validation
The template includes authentication support:
auth = "disabled"
- No authentication (development)auth = "memory"
- In-memory auth (testing)auth = "file"
- File-based auth (production)
For production use, configure file-based auth:
#[mcp_server(auth = "file")]
The server includes comprehensive logging. Set log levels:
RUST_LOG=debug ./target/debug/template-mcp-server
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This template is licensed under the MIT License. See LICENSE for details.
When using this template:
- Click "Use this template" on GitHub
- Create your repository with a descriptive name
- Clone and customize as described above
- Delete this section from your README
- Update all placeholder information with your project details
Happy building! π