Skip to content

Commit 2a829a0

Browse files
committed
feat(examples): migrate-to-2026 slice — 6 examples, all live-verified
Slice 2 of the examples disposition (review doc stamped EXECUTED). - middleware-rate-limit-server: re-keyed from session_id (always-fresh on the stateless lane → limiter silently inert) to the X-API-Key header in the pre-session phase, with a real window reset. VERIFIED: 5 pass, 6th → -32003 + retryAfter; different key unaffected. - completion-server: now serves the REAL completion/complete via a registered McpCompletion provider (code_review prompt's language argument; reference-matched, prefix-filtered). VERIFIED: "ru" → ["ruby","rust"]. Old tool kept as a deliberate surface contrast; README rewritten with working 2026 curls. - simple-{sqlite,postgres,dynamodb}-session: reframed as durable-backend wiring. On 2026 there are no client-visible sessions — the demo tools now drive the SessionStorage backend API directly against one durable record per run; storage_info counts accumulate across restarts (the observable persistence proof). VERIFIED for sqlite across an actual restart; postgres/dynamodb follow the identical pattern (compile-checked; they require live databases to run). All "session persists across restarts" claims removed from code, stdout, and READMEs. - notification-server: rewritten from 471 lines of simulated custom notification providers to the two genuine 2026 surfaces — trigger_changes broadcasts list-changed/resources-updated onto subscriptions/listen streams; long_job emits request-scoped progress+log on its own response stream (progressToken / logLevel opt-ins). VERIFIED live: listen stream received exactly its filtered subset (ack first, prompts excluded); long_job's stream carried 3 progress + 3 message frames before the result. README rewritten. Gates: scripts/ci-gates.sh all → ALL GATES PASSED (from-clean rebuild).
1 parent 800fd2c commit 2a829a0

13 files changed

Lines changed: 790 additions & 1685 deletions

File tree

docs/plans/2026-07-28-examples-review.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ own binary. The worst offenders print broken curl commands from their own stdout
5050

5151
## 🔁 Migrate to 2026 idioms (6) — valuable pattern, wrong-era demonstration
5252

53+
> **EXECUTED 2026-06-12** (slice 2, all live-verified):
54+
> `middleware-rate-limit-server` re-keyed to X-API-Key in the pre-session
55+
> phase (limiter genuinely fires now); `completion-server` serves the real
56+
> `completion/complete` via a registered provider; the storage trio drives
57+
> the backend API directly against per-run records (restart durability
58+
> observable via `storage_info` counts); `notification-server` rewritten
59+
> around the two 2026 surfaces (`subscriptions/listen` + request-scoped
60+
> progress/log).
61+
5362
| Example | Lane | Teaches | Why / required fixes | Gate-ref |
5463
|---|---|---|---|---|
5564
| `completion-server` | 2026-default | Nominally the MCP completion feature — in reality it only teaches a derive-macro tool ('ide_completion') that returns suggestion lists; it never implements the protocol's completion/complete. | Completion is current on 2026 (plan section 'Completion (draft 2026-07-28)') and the framework has first-class completion_provider support, so the teaching slot is valuable — but this example teaches the wrong thing on every axis: README advertises a protocol feature the code does not implement, claims data-file loading the code does not do, and its wire examples are pre-2026. Rewrite it to register a real McpCompletion provider answering completion/complete with 2026 _meta-bearing curls (the existing data/ files can finally be used). Referenced only by legacy scripts/verify_phase3.sh and the unwired tests/working_examples_validation.rs (not in tests/Cargo.toml [[test]] list) — no CI gate. — **Staleness:** README.md:66,115,156 give curl examples calling method 'completion/complete', but src/main.rs registers only a tool via .tool() (main.rs:117-124) and never calls McpServer::builder().completion_provider() (the real API, crates/turul-mcp-server/src/builder.rs:920) — those curls fail against the actual server; README also claims 'loads data from external JSON files at startup' and shows a data/ tree, but main.rs:32-58 hardcodes all suggestion vectors and never reads data/; README curls carry no per-request _meta and no MCP-Protocol-Version header, so they would be rejected on the 2026 enforced-_meta path; main.rs:119 .version("1.0.0") matches house style (not stale). | no |
Lines changed: 46 additions & 313 deletions
Original file line numberDiff line numberDiff line change
@@ -1,326 +1,59 @@
11
# IDE Auto-Completion Server
22

3-
A **real-world MCP completion server** that provides intelligent auto-completion suggestions for developers working in IDEs and code editors. This example demonstrates how to build production-ready completion functionality by loading data from external JSON files and providing context-aware suggestions.
3+
Demonstrates the **real MCP completion protocol**`completion/complete`
4+
served by an `McpCompletion` provider registered with
5+
`.completion_provider()`, alongside a plain tool for contrast.
46

5-
## Real-World Use Case
7+
Two different surfaces:
68

7-
This server simulates an **IDE language server or editor plugin** that helps developers with:
9+
| Surface | Method | For |
10+
|---|---|---|
11+
| Completion provider | `completion/complete` | Argument autocomplete while a user edits a prompt/template (IDE-style) |
12+
| Tool | `tools/call` (`ide_completion`) | Model-invoked suggestion lookups |
813

9-
- **🔤 Code completion** for programming languages and frameworks
10-
- **⚙️ Command suggestions** for development tools and operations
11-
- **📁 File path completion** for common project files
12-
- **🌍 Environment completion** for deployment contexts and configurations
13-
- **📦 Tool recommendations** based on project context
14+
The provider completes the `language` argument of the `code_review` prompt:
15+
the routing handler matches the request's `ref` against the provider's
16+
declared reference, prefix-filters, and the framework enforces the spec's
17+
100-item response cap.
1418

15-
### Why External Data Files?
16-
17-
Unlike hardcoded completion data, this server loads suggestions from **external JSON files** demonstrating:
18-
- **Maintainability**: Update completion data without code changes
19-
- **Customization**: Different teams can maintain their own completion databases
20-
- **Scalability**: Easy to add new languages, frameworks, and tools
21-
- **Real-world pattern**: How production completion servers manage their data
22-
23-
## Architecture
24-
25-
```
26-
completion-server/
27-
├── src/main.rs # Server implementation
28-
├── data/ # External completion data
29-
│ ├── languages.json # Programming languages with categories
30-
│ ├── frameworks.json # Web frameworks with language mappings
31-
│ └── development_commands.json # Commands with tool examples
32-
└── README.md
33-
```
34-
35-
## Features
36-
37-
### 🎯 **Context-Aware Completion**
38-
- Suggests different completions based on parameter names
39-
- Filters suggestions by current input prefix
40-
- Provides rich descriptions with categories and examples
41-
42-
### 📊 **Categorized Data**
43-
- **Programming languages** by category (systems, web, functional, etc.)
44-
- **Frameworks** by language and type (frontend, backend, fullstack)
45-
- **Commands** by operation type (build, deploy, monitoring, etc.)
46-
47-
### **Production Ready**
48-
- Loads data from external JSON files at startup
49-
- Efficient prefix filtering and result limiting
50-
- Comprehensive error handling and logging
51-
52-
## Running the Server
19+
## Run
5320

5421
```bash
55-
# Ensure you're in the completion-server directory for data/ access
56-
cd examples/completion-server
57-
58-
# Run the IDE completion server (default: 127.0.0.1:8042)
5922
cargo run -p completion-server
60-
61-
# Test language completion
62-
curl -X POST http://127.0.0.1:8042/mcp \
63-
-H "Content-Type: application/json" \
64-
-d '{
65-
"jsonrpc": "2.0",
66-
"method": "completion/complete",
67-
"params": {
68-
"argument": {
69-
"name": "language",
70-
"value": "ru"
71-
},
72-
"ref": {}
73-
},
74-
"id": 1
75-
}'
76-
```
77-
78-
## Completion Categories
79-
80-
### 1. Programming Languages
81-
82-
**Triggered by**: `language`, `lang`, `programming_language`
83-
84-
Suggests programming languages with categories and detailed descriptions loaded from `data/languages.json`.
85-
86-
**Example Response:**
87-
```json
88-
{
89-
"jsonrpc": "2.0",
90-
"result": {
91-
"completions": [
92-
{
93-
"value": "rust",
94-
"label": "Rust programming language",
95-
"description": "Systems programming language focused on safety and performance (systems)"
96-
}
97-
]
98-
},
99-
"id": 1
100-
}
101-
```
102-
103-
### 2. Web Frameworks
104-
105-
**Triggered by**: `framework`, `library`, `lib`
106-
107-
Suggests frameworks with language and category information from `data/frameworks.json`.
108-
109-
**Example Request:**
110-
```bash
111-
curl -X POST http://127.0.0.1:8042/mcp \
112-
-H "Content-Type: application/json" \
113-
-d '{
114-
"jsonrpc": "2.0",
115-
"method": "completion/complete",
116-
"params": {
117-
"argument": {
118-
"name": "framework",
119-
"value": "rea"
120-
},
121-
"ref": {}
122-
},
123-
"id": 1
124-
}'
23+
# → http://127.0.0.1:8042/mcp
12524
```
12625

127-
**Example Response:**
128-
```json
129-
{
130-
"jsonrpc": "2.0",
131-
"result": {
132-
"completions": [
133-
{
134-
"value": "react",
135-
"label": "React framework",
136-
"description": "JavaScript library for building user interfaces (javascript - frontend)"
137-
}
138-
]
139-
},
140-
"id": 1
141-
}
142-
```
143-
144-
### 3. Development Commands
145-
146-
**Triggered by**: `command`, `cmd`, `action`
147-
148-
Suggests development commands with tool examples from `data/development_commands.json`.
26+
## Try it (2026-07-28 stateless)
14927

150-
**Example Request:**
15128
```bash
152-
curl -X POST http://127.0.0.1:8042/mcp \
153-
-H "Content-Type: application/json" \
154-
-d '{
155-
"jsonrpc": "2.0",
156-
"method": "completion/complete",
157-
"params": {
158-
"argument": {
159-
"name": "command",
160-
"value": "bu"
161-
},
162-
"ref": {}
163-
},
164-
"id": 1
165-
}'
166-
```
167-
168-
**Example Response:**
169-
```json
170-
{
171-
"jsonrpc": "2.0",
172-
"result": {
173-
"completions": [
174-
{
175-
"value": "build",
176-
"label": "Build command",
177-
"description": "Compile and build the project - Tools: cargo, npm, gradle, maven, make"
178-
}
179-
]
180-
},
181-
"id": 1
182-
}
183-
```
184-
185-
### 4. File Extensions
186-
187-
**Triggered by**: `extension`, `ext`, `file_extension`
188-
189-
Suggests common file extensions with detailed descriptions for different file types.
190-
191-
### 5. File Paths
192-
193-
**Triggered by**: `filename`, `file`, `path`
194-
195-
Suggests common project files like `main.rs`, `README.md`, `Cargo.toml`, `package.json`.
196-
197-
### 6. Semantic Versions
198-
199-
**Triggered by**: `version`
200-
201-
Suggests semantic version patterns: `1.0.0`, `0.1.0`, `2.0.0-beta`.
202-
203-
### 7. Deployment Environments
204-
205-
**Triggered by**: `environment`, `env`
206-
207-
Suggests environment types: `development`, `staging`, `production`.
208-
209-
## External Data Format
210-
211-
### Languages Data (`data/languages.json`)
212-
```json
213-
{
214-
"programming_languages": [
215-
{
216-
"name": "rust",
217-
"label": "Rust programming language",
218-
"description": "Systems programming language focused on safety and performance",
219-
"category": "systems"
220-
}
221-
]
222-
}
223-
```
224-
225-
### Frameworks Data (`data/frameworks.json`)
226-
```json
227-
{
228-
"web_frameworks": [
229-
{
230-
"name": "react",
231-
"label": "React framework",
232-
"description": "JavaScript library for building user interfaces",
233-
"category": "frontend",
234-
"language": "javascript"
235-
}
236-
]
237-
}
238-
```
239-
240-
### Commands Data (`data/development_commands.json`)
241-
```json
242-
{
243-
"development_commands": [
244-
{
245-
"name": "build",
246-
"label": "Build command",
247-
"description": "Compile and build the project",
248-
"category": "compilation",
249-
"common_tools": ["cargo", "npm", "gradle", "maven", "make"]
250-
}
251-
]
252-
}
253-
```
254-
255-
## Implementation Highlights
256-
257-
### Data Loading
258-
```rust
259-
impl IdeCompletionHandler {
260-
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
261-
let data_dir = Path::new("data");
262-
263-
let languages = Self::load_languages(data_dir)?;
264-
let frameworks = Self::load_frameworks(data_dir)?;
265-
let commands = Self::load_commands(data_dir)?;
266-
267-
Ok(Self { languages, frameworks, commands, file_extensions })
268-
}
269-
}
270-
```
271-
272-
### Context-Aware Completion
273-
```rust
274-
fn get_smart_completions(&self, argument_name: &str, current_value: &str) -> Vec<CompletionSuggestion> {
275-
match argument_name.to_lowercase().as_str() {
276-
"language" | "lang" | "programming_language" => {
277-
self.get_language_completions(&prefix)
278-
},
279-
"framework" | "library" | "lib" => {
280-
self.get_framework_completions(&prefix)
281-
},
282-
"command" | "cmd" | "action" => {
283-
self.get_command_completions(&prefix)
284-
},
285-
_ => /* fallback suggestions */
286-
}
287-
}
288-
```
289-
290-
## Real-World Applications
291-
292-
### IDE Integration
293-
- **VS Code Language Server**: Provide completion for configuration files
294-
- **IntelliJ Plugin**: Framework and library suggestions
295-
- **Vim/Neovim LSP**: Command and tool completion
296-
297-
### Development Tools
298-
- **CLI Tools**: Smart completion for command-line applications
299-
- **CI/CD Pipelines**: Environment and deployment target completion
300-
- **Code Generators**: Template and framework selection
301-
302-
### Configuration Management
303-
- **Docker Compose**: Service and image completion
304-
- **Kubernetes**: Resource and namespace completion
305-
- **Terraform**: Provider and resource completion
306-
307-
## Extension Opportunities
308-
309-
### Enhanced Data Sources
310-
- **Package Registries**: npm, crates.io, PyPI integration
311-
- **Documentation APIs**: Real-time API completion
312-
- **Git Repositories**: Branch and tag completion
313-
- **Cloud Services**: AWS, GCP, Azure resource completion
314-
315-
### Advanced Features
316-
- **Fuzzy Matching**: More sophisticated search algorithms
317-
- **Machine Learning**: AI-powered suggestions based on context
318-
- **User Preferences**: Personalized completion based on usage history
319-
- **Multi-workspace**: Different completion sets per project type
320-
321-
### Performance Optimizations
322-
- **Caching**: Cache frequently accessed completion data
323-
- **Incremental Loading**: Load data on-demand for large datasets
324-
- **Background Updates**: Refresh completion data without restarts
325-
326-
This completion server demonstrates how external data files enable maintainable, scalable completion systems that can evolve with changing development ecosystems without requiring code changes.
29+
META='"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"curl","version":"1.0"},"io.modelcontextprotocol/clientCapabilities":{}}'
30+
31+
# Argument completion: "ru" → ["ruby","rust"]
32+
curl -s -X POST http://127.0.0.1:8042/mcp \
33+
-H 'Content-Type: application/json' \
34+
-H 'MCP-Protocol-Version: 2026-07-28' \
35+
-H 'Mcp-Method: completion/complete' \
36+
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"completion/complete\",\"params\":{\"ref\":{\"type\":\"ref/prompt\",\"name\":\"code_review\"},\"argument\":{\"name\":\"language\",\"value\":\"ru\"},$META}}"
37+
38+
# The prompt the completion serves
39+
curl -s -X POST http://127.0.0.1:8042/mcp \
40+
-H 'Content-Type: application/json' \
41+
-H 'MCP-Protocol-Version: 2026-07-28' \
42+
-H 'Mcp-Method: prompts/get' -H 'Mcp-Name: code_review' \
43+
-d "{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"prompts/get\",\"params\":{\"name\":\"code_review\",\"arguments\":{\"language\":\"rust\"},$META}}"
44+
45+
# The contrast tool
46+
curl -s -X POST http://127.0.0.1:8042/mcp \
47+
-H 'Content-Type: application/json' \
48+
-H 'MCP-Protocol-Version: 2026-07-28' \
49+
-H 'Mcp-Method: tools/call' -H 'Mcp-Name: ide_completion' \
50+
-d "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"ide_completion\",\"arguments\":{\"category\":\"language\",\"prefix\":\"py\"},$META}}"
51+
```
52+
53+
## Contract notes
54+
55+
- A server with completion providers advertises the `completions`
56+
capability in `server/discover`; one without answers
57+
`completion/complete` with 404 + `-32601`.
58+
- Malformed params (missing `argument`, unknown `ref` type) → `-32602`.
59+
- Provider output is capped at 100 values (`total`/`hasMore` reflect a cut).

0 commit comments

Comments
 (0)