MCP Server Ollama
Enables natural language management of blog posts and comments through a decoupled architecture using Ollama and JSON-RPC. Supports creating, updating, deleting posts and comments via AI chatbot or MCP clients.
README
MCP Server Ollama - Decoupled Architecture
This repository contains a small blog-style application with two working flows, both using decoupled architecture with JSON-RPC:
- AI Chatbot Flow (recommended for production): Natural language requests are converted to JSON-RPC by the AI, then executed through the MCP protocol.
- MCP Client Flow: An MCP-compatible client directly calls the MCP endpoint with JSON-RPC requests.
The project is split into two services:
- Main REST API server: server.js
- MCP server with Ollama integration: mcp-server/server.js
What the app does
The main API stores and manages posts and comments in MongoDB.
- Posts contain: title, author, category, body, createdAt
- Comments belong to a post and contain: postId, text, commenter, createdAt
The MCP server adds two higher-level interaction paths on top of that REST API.
Architecture: Decoupled via JSON-RPC
Flow 1: AI Chatbot -> JSON-RPC -> MCP -> REST API -> MongoDB
This is the decoupled, production-recommended flow used when a user talks to the chatbot interface or sends a request to the AI endpoint.
Why this architecture?
- AI Layer (Ollama): Focuses ONLY on understanding user intent and generating JSON-RPC requests. Does NOT know about backend details.
- MCP Layer: Acts as middleware to execute JSON-RPC requests using the standard MCP protocol.
- Backend Layer: REST API and database remain isolated from AI logic.
Flow Steps:
- A user sends a message such as "Create a new post..." to the chatbot UI or to the
/ai-chatbotendpoint. - The MCP server sends the message to Ollama.
- Ollama understands the intent and generates a JSON-RPC 2.0 request to call the appropriate MCP tool (e.g.,
create_post). - The MCP client executes that JSON-RPC request through the MCP protocol.
- The appropriate MCP tool is invoked, which calls the REST API.
- The REST API updates MongoDB and returns the result.
Separation of Concerns:
User Message
↓
[AI Layer] Ollama
→ Understands intent
→ Generates JSON-RPC request
↓
[MCP Layer] MCP Client
→ Sends JSON-RPC to MCP Server
→ Executes tool
↓
[Backend Layer] REST API
→ MongoDB
This path is used by:
- the chatbot page at
public/chatbot.html - the endpoint
POST /ai-chatboton the MCP server
Flow 2: MCP Client -> /mcp -> MCP Tools -> REST API -> MongoDB
This flow is used when an MCP-compatible client connects to the MCP server directly.
- The MCP client sends a JSON-RPC request to
POST /mcp. - The MCP server handles initialization and tool calls.
- The server invokes registered tools such as create_post, list_posts, update_post, delete_post, add_comment, and list_comments.
- Each tool calls the main REST API.
- The REST API performs the action in MongoDB.
This is the path used by MCP-compatible clients.
Key Differences: Tight Coupling vs. Decoupled
| Aspect | Before (Tight Coupling) | After (Decoupled) |
|---|---|---|
| AI Responsibility | Directly calls REST API endpoints | Only understands intent, generates JSON-RPC |
| Coupling | AI tightly bound to backend structure | AI and backend completely decoupled |
| Protocol | Direct HTTP calls | Standard JSON-RPC 2.0 protocol |
| Middleware | None | MCP layer acts as middleware |
| Scalability | Difficult to replace AI or backend | Easy to swap AI model or backend service |
| Production Ready | Not recommended ❌ | ✓ Production-ready ✓ |
| Standard Compliance | Proprietary | JSON-RPC 2.0 + MCP Standard |
How JSON-RPC Decoupling Works
Example: User says "Create a tech post about AI"
Step 1: AI generates JSON-RPC request (not direct execution)
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "create_post",
"arguments": {
"title": "Understanding AI",
"author": "John Doe",
"category": "tech",
"body": "Artificial Intelligence is transforming how we work and live..."
}
},
"id": 1
}
Key Point: Ollama ONLY generates this JSON-RPC request. It does NOT execute it directly.
Step 2: MCP Client sends this JSON-RPC to MCP Server
The MCP client (in the MCP server itself) sends this JSON-RPC request to the /mcp endpoint.
Step 3: MCP Server executes the tool
The MCP server routes the create_post tool call, which validates the input and calls the REST API.
Step 4: REST API persists to MongoDB
POST /posts → Validation → MongoDB.insert() → Returns created post
Step 5: Result flows back
MCP Server → MCP Client → Chatbot UI → User sees the created post
Benefits of This Architecture
1. Loose Coupling
You can independently:
- Replace Ollama with another AI model (GPT, Claude, etc.) without changing backend
- Switch backend from REST API to gRPC without changing AI
- Deploy AI and backend in different regions or cloud providers
- Use different programming languages for each layer
2. Scalability
- Load balance MCP layer independently from AI and backend
- Cache AI responses without affecting backend performance
- Implement retry logic and circuit breakers at MCP level
- Scale AI horizontally without scaling backend
3. Testability
- AI layer testable independently (mock MCP)
- MCP layer testable independently (mock REST API)
- Backend testable independently (mock MCP layer)
- Clear unit test boundaries
4. Standards Compliance
- Uses standard JSON-RPC 2.0 protocol (not proprietary)
- Compatible with any MCP-compliant client
- Follows Model Context Protocol specification
- Can integrate with other MCP servers
5. Production Ready
- Proper separation of concerns
- Clear error boundaries and logging
- Middleware pattern enables monitoring at MCP level
- Request tracing across layers
- No tight coupling risks
6. Maintainability
- Changes to backend don't affect AI logic
- Updates to AI model don't require backend changes
- Clear interfaces between layers (JSON-RPC)
- Easier debugging with layer isolation
Available MCP Tools
The MCP server exposes the following tools:
- create_post:
{title, author, category, body}- Creates a new post - list_posts:
{}- Lists all posts - get_post:
{postId}- Gets a single post by ID - update_post:
{postId, title, author, category, body}- Updates an existing post - delete_post:
{postId}- Deletes a post (WARNING: deletes post and ALL comments) - add_comment:
{postId, text, commenter}- Adds a comment to a post - list_comments:
{postId}- Lists all comments for a post
Implementation Details
AI Layer (processUserMessage)
- Receives user message and context
- Sends to Ollama with system prompt focused on intent understanding
- Ollama generates a JSON-RPC 2.0 request (not action plan)
- Returns JSON-RPC request WITHOUT executing it
MCP Layer (executeMcpToolViaJsonRpc)
- Receives JSON-RPC request from AI layer
- Validates tool name and arguments
- Executes appropriate tool logic
- Returns JSON-RPC 2.0 response
Backend Layer (/posts endpoints)
- Handles REST API requests from MCP layer
- Performs MongoDB operations
- Returns results to MCP layer
Endpoints
- POST /ai-chatbot: Accepts user message, returns AI-generated JSON-RPC + execution result
- POST /mcp: Standard MCP protocol endpoint for MCP clients
- GET /health: Health check endpoint
Response Format from /ai-chatbot
{
"success": true,
"jsonRpcRequest": {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "create_post",
"arguments": {...}
},
"id": 1
},
"jsonRpcResponse": {
"jsonrpc": "2.0",
"result": {...},
"id": 1
},
"executionTime": "245ms"
}
This response shows:
- The JSON-RPC request AI generated
- The JSON-RPC response from tool execution
- Execution time for monitoring
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。