mcp
Copilot instructions65 starsChanged 2 months agoMITView on GitHub
mcp is a Rust CLI that turns MCP (Model Context Protocol) servers into terminal commands. It supports stdio and HTTP transports, a proxy/gateway mode, server registry, audit logging, and ACL-based auth. The project uses ChronDB as its single persistent key-value store. All state manipulation follows these rules: All keys use a prefixed namespace pattern to avoid collisions: New consumers must define a unique prefix and
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
16 rules. About 0 are common, 9 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
No unnecessary abstractions — solve the actual problem, not a hypothetical one.
- Very specific: line 27
All functions return anyhow::Result<T>.
- Very specific: line 28
Use .context("msg")? or .with_context(|| format!("msg {var}"))?
- Very specific: line 29
Use bail!("msg") for early returns with error.
- Very specific: line 30
Use .map_err(|e| anyhow::anyhow!("msg: {e:?}")) only when wrapping external library errors that don't implement std::error::Error.
- Very specific: line 31
Never silently swallow errors — at minimum log with eprintln!
- Very specific: line 35
All async via Tokio. Entry point is #[tokio::main].
- Distinctive: line 65
No dotenv or external config library.
- Distinctive: line 79
All keys use a prefixed namespace pattern to avoid collisions:
- Very specific: line 99
Always acquire the db handle via pool.acquire() — never hold Arc<ChronDB> across await points.
- Distinctive: line 103
When reviewing code that touches ChronDB:
- Distinctive: line 123
Always validate locally before submitting a PR.
- Distinctive: line 137
Keep PRs focused — one concern per PR.
- Distinctive: line 138
If a PR touches auth/ACL, include the full security test battery described above.
- Distinctive: line 139
Don't add features or refactoring beyond what was asked.
- Distinctive: line 140
Test behavior, not implementation details.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions
Project Overview
mcp is a Rust CLI that turns MCP (Model Context Protocol) servers into terminal commands. It supports stdio and HTTP transports, a proxy/gateway mode, server registry, audit logging, and ACL-based auth.
Tech Stack
- Language: Rust (edition 2021)
- Async runtime: Tokio (full features)
- HTTP: Axum (server), Reqwest with rustls-tls (client)
- Serialization: Serde + serde_json
- Error handling:
anyhow::Resultthroughout - Storage: chrondb for persistent state
- Tests: built-in
#[cfg(test)]modules,tempfilefor test fixtures
Code Style & Conventions
- No
#[allow(dead_code)]— wire it up or delete it. - Functions do one thing. Max ~50 lines. Max 3 levels of nesting.
- Comments explain why, not what.
- No unnecessary abstractions — solve the actual problem, not a hypothetical one.
- Zero
unsafecode — all concurrency through safe abstractions.
Error Handling
- All functions return
anyhow::Result<T>. No custom error types. - Use
.context("msg")?or.with_context(|| format!("msg {var}"))?to add context on propagation. - Use
bail!("msg")for early returns with error. - Use
.map_err(|e| anyhow::anyhow!("msg: {e:?}"))only when wrapping external library errors that don't implementstd::error::Error. - Never silently swallow errors — at minimum log with
eprintln!.
Async Patterns
- All async via Tokio. Entry point is
#[tokio::main]. - Interior mutability with
Arc<Mutex<T>>orArc<RwLock<T>>for shared state across tasks. - Bounded
mpsc::channelfor task communication,oneshotfor request-response matching. tokio::spawnfor background tasks (readers, writers).spawn_blockingfor sync-heavy work (db writes).- Timeouts via
tokio::time::timeout(Duration, future)— never block indefinitely.
Serialization
- Derive order:
#[derive(Debug, Serialize, Deserialize, Clone)]. #[serde(rename = "camelCase")]for protocol fields matching JSON-RPC/MCP spec.#[serde(skip_serializing_if = "Option::is_none")]on allOptionfields for compact JSON.#[serde(default)]on optional deserialization fields.#[serde(untagged)]for config enums with variant ordering (serde tries in declaration order).
Module Organization
- Binary crate (
main.rs), nolib.rs. - Private submodules with selective re-exports:
mod foo; pub use foo::handle_foo;. - Trait objects (
Arc<dyn Trait>) over generics for polymorphism (e.g.,Arc<dyn Transport>). #[async_trait]withSend + Syncbounds on all trait definitions.
Logging & Output
- Debug/diagnostic output to stderr via
eprintln!("[prefix] message")with component prefix:[db],[cache],[server stderr]. - User-facing output through
OutputFormatenum — auto-detects JSON (piped) vs Text (TTY). - Results always to stdout, diagnostics always to stderr.
Environment Variables
- Pattern:
std::env::var("MCP_*").ok().and_then(|v| v.parse().ok()).unwrap_or(default). - No dotenv or external config library. Pure JSON config files + env var overrides.
State & Persistence (ChronDB)
The project uses ChronDB as its single persistent key-value store. All state manipulation follows these rules:
Architecture
DbPool(src/db.rs) wrapsChronDBwithOption<Arc<ChronDB>>— supports adisabled()state for environments without writable filesystem (containers, CI).- A single
Arc<DbPool>is created at startup viacreate_pool()and shared across all consumers. - ChronDB manages its own GraalVM isolate lifecycle with idle timeout (120s default) — no external GC thread needed.
Key Schema
All keys use a prefixed namespace pattern to avoid collisions:
| Consumer | Key pattern | Value |
| Audit log | audit:{timestamp_ms}-{uuid} | Serialized AuditEntry |
| Tool cache | cache:tools:{server_name} | Serialized BackendToolCache |
New consumers must define a unique prefix and document it in this table.
Read/Write Patterns
- Read:
db.get(&key, None)returnsserde_json::Value. Deserialize withserde_json::from_value. Always handleOk/Err— missing keys return error, notNone. - Write: Serialize to
serde_json::Valuefirst, thendb.put(&key, &value, None). The third parameter is reserved (passNone). - List:
db.list_by_prefix("prefix:", None)for range queries (e.g., audit log retrieval). - No delete API is used — data is append-only or overwritten by key.
Concurrency Rules
- Audit writes go through an unbounded mpsc channel →
spawn_blockingwriter thread. This decouples hot paths from db latency. - Cache reads/writes are synchronous on the caller (blocking the async task briefly). Acceptable because cache ops are fast and infrequent.
- Always acquire the db handle via
pool.acquire()— never holdArc<ChronDB>across await points.
Review Checklist for DB Changes
When reviewing code that touches ChronDB:
- Key prefix is unique and documented in the table above
- Serialization round-trips correctly (write + read produces identical struct)
- Errors on
acquire(),put(),get()are handled — at minimum logged, never silently ignored - No
Arc<ChronDB>held across.await— acquire, use, drop - High-throughput writes use a channel +
spawn_blocking, not inlineput() DbPool::disabled()path is respected — code must not panic when db is unavailable- New keys don't collide with existing prefixes
CI Requirements
CI runs these three checks in order — all must pass before merging:
cargo fmt --check
cargo clippy -- -D warnings
cargo testAlways validate locally before submitting a PR.
Security & ACL
Any change touching src/server_auth/, ACL logic, auth providers, or credential parsing must include tests for:
- Bypass: invalid/malformed/absent tokens, wrong auth scheme, malformed JSON
- Privilege escalation: role leaking between identities, legacy tokens never returning roles, injection in trusted headers
- Backwards compatibility: legacy auth forms continue working without changes
- Parsing edge cases: CSV with spaces, empty entries, unicode, case-sensitivity
- Deny tests ≥ allow tests — happy path alone is not sufficient security coverage
Guidelines for PRs
- Keep PRs focused — one concern per PR.
- If a PR touches auth/ACL, include the full security test battery described above.
- Don't add features or refactoring beyond what was asked.
- Test behavior, not implementation details.
- Integration tests over excessive unit tests for glue code.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

