Guide to building a minimal JavaScript MCP server that registers versioned prompts, forwards prompt text to a local Ollama instance, and demonstrates testing with an MCP Inspector
This lesson walks through building a minimal MCP (Model Context Protocol) server in JavaScript that:
Stores prompts as JSON files (trackable in Git)
Registers prompts with an MCP server
Forwards prompt text to a local Ollama instance via its HTTP API
Provides a lightweight demo harness and shows how to test with the MCP Inspector
Store each prompt as a separate JSON file under a prompts/ directory. This makes prompts easy to version and reuse.Summary of the example prompts:
Prompt ID
Title
Purpose
greeting
Personalized Greeting
Produces a simple personalized message
explain-concept
Concept Explainer
Explains concepts for a specified audience
code-review
Code Review
Reviews code and provides suggestions
Example: greetings.json
{ "id": "greeting", "title": "Personalized Greeting", "description": "Creates a greeting using the user's name.", "template": "Hello, {{name}}! Welcome to our MCP prompt demo.", "variables": [ { "name": "name", "description": "The recipient's name" } ]}
Example: explain-concept.json
{ "id": "explain-concept", "title": "Concept Explainer", "description": "Explains complex concepts in simple terms.", "template": "Please explain {{concept}} in simple terms that a {{audience}} could understand. Use examples and analogies where appropriate.", "variables": [ { "name": "concept", "description": "The concept to be explained" }, { "name": "audience", "description": "The target audience (e.g., 'beginner', '10-year-old', 'college student')" } ]}
Example: code-review.json
{ "id": "code-review", "title": "Code Review", "description": "Reviews code and suggests improvements.", "template": "Please review the following JavaScript code and provide suggestions for improvement:\n\n```javascript\n{{code}}\n```\n\nPlease focus on:\n- Code quality and best practices\n- Performance optimizations\n- Security considerations\n- Readability and maintainability", "variables": [ { "name": "code", "description": "The JavaScript code to review" } ]}
If you see a warning about “Module type of file … is not specified”, add "type": "module" to your package.json to explicitly enable ESM and avoid reparsing warnings.
Starting MCP inspector...🔑 Proxy server listening on localhost:6277🔑 Session token: <token>Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable authAll prompts registeredServer ready
Once connected, the Inspector UI will list your greeting, explain-concept, and code-review prompts. You can invoke them interactively.
This demo script spawns server.js, watches stdout until it sees Server ready, and then demonstrates how you might invoke prompts. The actual MCP invocation is left to the Inspector or an MCP client; this harness focuses on starting and verifying the server.Save as simple-demo.js:
#!/usr/bin/env nodeimport { spawn } from 'child_process';console.log('=== MCP Ollama Demo ===\nTesting multiple prompts with Ollama integration...\n');async function startServer() { const serverProcess = spawn('node', ['server.js'], { cwd: process.cwd(), stdio: ['pipe', 'pipe', 'inherit'] }); return new Promise((resolve, reject) => { serverProcess.stdout.setEncoding('utf8'); serverProcess.stdout.on('data', (chunk) => { const output = chunk.toString(); process.stdout.write(output); if (output.includes('Server ready')) { resolve(serverProcess); } }); serverProcess.on('error', (err) => reject(err)); serverProcess.on('exit', (code) => { if (code !== 0) { reject(new Error(`Server exited with code ${code}`)); } }); });}(async () => { try { const serverProcess = await startServer(); console.log('✓ Server initialized'); // At this point you can use the MCP Inspector or an MCP client to call prompts. // This harness intentionally leaves actual MCP calls out to avoid duplicating // a full JSON-RPC-over-stdio implementation here. // Cleanup: stop the server after a short delay (for demo purposes) setTimeout(() => { serverProcess.kill(); console.log('\n=== Demo completed ==='); }, 3000); } catch (err) { console.error('Demo error:', err); }})();
✅ All prompts registeredServer ready✓ Server initialized→ Sending prompt to Ollama...✔ Got response from OllamaRENDERED PROMPT:Hello, Alice! Welcome to our MCP prompt demo.OLLAMA RESPONSE:*awkward smile* Oh, hi there... I'm not really sure what's going on or who you are, but I suppose I'll play along. What kind of demo is this? Is it some sort of... alternate history simulation? *nervous laugh*
This tutorial demonstrates registering reusable prompt definitions in an MCP server, forwarding prompt text to a local Ollama instance, and validating behavior with the MCP Inspector and a small demo harness. The approach enables shared, version-controlled prompt management across teams and services.