- 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
- Prompt file examples
- Project setup and dependencies
- Server implementation (
server.js) - Using the MCP Inspector
- Demo harness (
simple-demo.js) - Sample output and best practices
Prompt files (examples)
Store each prompt as a separate JSON file under aprompts/ directory. This makes prompts easy to version and reuse.
Summary of the example prompts:
Example: greetings.json
Setup β node project and dependencies
Initialize the project and install the libraries used in this example:- Depending on your Node version,
fetchmay already be available globally. This guide usesnode-fetchto keep compatibility across Node releases. - References:
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.Server implementation (server.js)
This server does the following:- Registers three prompts (
greeting,explain-concept,code-review) with an MCP server - Sends prompt text to a local Ollama server using the Ollama HTTP
generateendpoint - Starts a STDIO transport for MCP message exchange (common for MCP workflows)
server.js and run it with node server.js.
- The server uses
sendToOllama()to POST tohttp://localhost:11434/api/generate. - Each
registerPromptcall gives a prompt ID, metadata (title/description), and a handler that formats the final prompt text and returns a message bag. - The server connects over STDIO via
StdioServerTransportso it can be inspected or proxied by MCP tools.
Using the MCP Inspector to test
The Model Context Protocol Inspector lets you inspect the prompts, tools, and resources your MCP server exposes. Install/run:greeting, explain-concept, and code-review prompts. You can invoke them interactively.
Simple demo harness (simple-demo.js)
This demo script spawnsserver.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:
Sample run output (trimmed)
Notes and best practices
- Store prompt templates as files in a Git repo to gain version history, rollbacks, and collaboration.
- Document each promptβs template and variable schema (e.g.,
variablesarray) so clients know what to pass. - For production servers, add:
- Robust error handling and retries for downstream calls (Ollama)
- Structured logging and metrics
- Input validation (e.g., use
zodor another validator) on prompt parameters - Rate limiting and authentication where appropriate
- If you hit Node module-type warnings, add
"type": "module"topackage.jsonto enable ESM.
Links and references
- MCP SDK: https://www.npmjs.com/package/@modelcontextprotocol/sdk
- MCP Inspector: https://www.npmjs.com/package/@modelcontextprotocol/inspector
- Ollama API docs: https://ollama.ai/docs/api
- Zod: https://www.npmjs.com/package/zod
- node-fetch: https://www.npmjs.com/package/node-fetch