Skip to content

Commit e8f8cad

Browse files
committed
initial version
0 parents  commit e8f8cad

14 files changed

+1063
-0
lines changed

.gitignore

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode,jetbrains+all
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,visualstudiocode,jetbrains+all
3+
4+
### JetBrains+all ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/**/usage.statistics.xml
12+
.idea/**/dictionaries
13+
.idea/**/shelf
14+
15+
# AWS User-specific
16+
.idea/**/aws.xml
17+
18+
# Generated files
19+
.idea/**/contentModel.xml
20+
21+
# Sensitive or high-churn files
22+
.idea/**/dataSources/
23+
.idea/**/dataSources.ids
24+
.idea/**/dataSources.local.xml
25+
.idea/**/sqlDataSources.xml
26+
.idea/**/dynamic.xml
27+
.idea/**/uiDesigner.xml
28+
.idea/**/dbnavigator.xml
29+
30+
# Gradle
31+
.idea/**/gradle.xml
32+
.idea/**/libraries
33+
34+
# Gradle and Maven with auto-import
35+
# When using Gradle or Maven with auto-import, you should exclude module files,
36+
# since they will be recreated, and may cause churn. Uncomment if using
37+
# auto-import.
38+
# .idea/artifacts
39+
# .idea/compiler.xml
40+
# .idea/jarRepositories.xml
41+
# .idea/modules.xml
42+
# .idea/*.iml
43+
# .idea/modules
44+
# *.iml
45+
# *.ipr
46+
47+
# CMake
48+
cmake-build-*/
49+
50+
# Mongo Explorer plugin
51+
.idea/**/mongoSettings.xml
52+
53+
# File-based project format
54+
*.iws
55+
56+
# IntelliJ
57+
out/
58+
59+
# mpeltonen/sbt-idea plugin
60+
.idea_modules/
61+
62+
# JIRA plugin
63+
atlassian-ide-plugin.xml
64+
65+
# Cursive Clojure plugin
66+
.idea/replstate.xml
67+
68+
# SonarLint plugin
69+
.idea/sonarlint/
70+
71+
# Crashlytics plugin (for Android Studio and IntelliJ)
72+
com_crashlytics_export_strings.xml
73+
crashlytics.properties
74+
crashlytics-build.properties
75+
fabric.properties
76+
77+
# Editor-based Rest Client
78+
.idea/httpRequests
79+
80+
# Android studio 3.1+ serialized cache file
81+
.idea/caches/build_file_checksums.ser
82+
83+
### JetBrains+all Patch ###
84+
# Ignore everything but code style settings and run configurations
85+
# that are supposed to be shared within teams.
86+
87+
.idea/*
88+
89+
!.idea/codeStyles
90+
!.idea/runConfigurations
91+
92+
### Rust ###
93+
# Generated by Cargo
94+
# will have compiled files and executables
95+
debug/
96+
target/
97+
98+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
99+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
100+
Cargo.lock
101+
102+
# These are backup files generated by rustfmt
103+
**/*.rs.bk
104+
105+
# MSVC Windows builds of rustc generate these, which store debugging information
106+
*.pdb
107+
108+
### VisualStudioCode ###
109+
.vscode/*
110+
!.vscode/settings.json
111+
!.vscode/tasks.json
112+
!.vscode/launch.json
113+
!.vscode/extensions.json
114+
!.vscode/*.code-snippets
115+
116+
# Local History for Visual Studio Code
117+
.history/
118+
119+
# Built Visual Studio Code Extensions
120+
*.vsix
121+
122+
### VisualStudioCode Patch ###
123+
# Ignore all local history of files
124+
.history
125+
.ionide
126+
127+
# End of https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode,jetbrains+all
128+

Cargo.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "mcp-rs-template"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["your name <[email protected]>"]
6+
description = "Model Context Protocol (MCP) Rust CLI server template"
7+
keywords = ["rust", "ai", "mcp", "cli"]
8+
categories = ["command-line-utilities"]
9+
readme = "README.md"
10+
license = "Apache-2.0"
11+
12+
[dependencies]
13+
tokio = { version = "1.0", features = ["full"] }
14+
serde = "1"
15+
serde_json = { version = "1", features = ["preserve_order"] }
16+
url = { version = "2.5", features = ["serde"] }
17+
rpc-router = "0.1.3"
18+
maplit = "1"
19+
clap = { version = "4.5", features = ["derive"] }
20+
chrono = "0.4.38"
21+
signal-hook = "0.3"
22+
23+
[profile.dev]
24+
opt-level = 1
25+
26+
[profile.dev.package."*"]
27+
opt-level = 3
28+
29+
[profile.release]
30+
strip = true
31+
lto = true
32+
opt-level = "z"
33+
codegen-units = 1

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
MCP Rust CLI server template
2+
=============================
3+
4+
Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications
5+
and external data sources and tools. Whether you’re building an AI-powered IDE, enhancing a chat interface,
6+
or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.
7+
8+
mcp-rs-template is a simple application template that demonstrates how to implement MCP CLI server in Rust.
9+
10+
# How to use template?
11+
12+
1. Clone the repository
13+
2. Modify project information in `Cargo.toml` and `src/mcp/mod.rs`
14+
3. Modify server handlers:
15+
- `src/mcp/prompts.rs`: prompts handlers
16+
- `src/mcp/resources.rs`: resources handlers
17+
- `src/mcp/tools.rs`: tools handlers
18+
4. Modify `src/mcp/templates/*.json` if you prefer to use json files for prompts, resources, and tools
19+
20+
mcp-rs-template is based on [rust-rpc-router](https://github.com/jeremychone/rust-rpc-router), a JSON-RPC routing
21+
library for Rust.
22+
23+
# CLI options
24+
25+
* `--mcp`: Enable MCP server
26+
* `--resources`: display resources
27+
* `--prompts`: display prompts
28+
* `--tools`: display tools
29+
30+
# How to use MCP CLI server in Claude Desktop?
31+
32+
1. Edit `claude_desktop_config.json`: Claude Desktop -> `Settings` -> `Developer` -> `Edit Config`
33+
2. Add the following configuration to the `servers` section:
34+
35+
```json
36+
{
37+
"mcpServers": {
38+
"current-time": {
39+
"command": "mcp-rs-template",
40+
"args": [
41+
"--mcp"
42+
],
43+
"env": {
44+
"API_KEY": "xxxx"
45+
}
46+
}
47+
}
48+
}
49+
```
50+
51+
# References
52+
53+
* MCP Specification: https://spec.modelcontextprotocol.io/
54+
* Model Context Protocol (MCP): https://modelcontextprotocol.io/introduction
55+
* rpc-router: json-rpc routing library - https://github.com/jeremychone/rust-rpc-router/
56+
* Zed context_server: https://github.com/zed-industries/zed/tree/main/crates/context_server

justfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ping:
2+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "ping" }' | ./target/debug/mcp-rs-demo --mcp
3+
4+
prompts-list:
5+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "prompts/list" }' | ./target/debug/mcp-rs-demo --mcp
6+
7+
prompt-get:
8+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "prompts/get", "params": {"name":"current_time","arguments": {"city": "hangzhou"} } }' | ./target/debug/mcp-rs-demo --mcp
9+
10+
tools-list:
11+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }' | ./target/debug/mcp-rs-demo --mcp
12+
13+
resources-list:
14+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "resources/list" }' | ./target/debug/mcp-rs-demo --mcp
15+
16+
current-time:
17+
echo '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_current_time_in_city", "arguments": {"city":"Hangzhou" } } }' | ./target/debug/mcp-rs-demo --mcp

0 commit comments

Comments
 (0)