MCP Server for Ollama Blog

MCP Server for Ollama Blog

Exposes a blog CRUD API (posts and comments) as MCP tools, with an integrated AI chatbot agent powered by Ollama Gemma2 for natural language interaction.

Category
访问服务器

README

MCP API with AI Chatbot Agent

Node.js Express API for Posts and Comments, backed by MongoDB (Mongoose). All responses are JSON.

There is also an MCP server in the mcp-server/ folder that exposes this API as MCP tools over Streamable HTTP at POST /mcp (no auth). See mcp-server/README.md for setup and tool list.

This project has been enhanced with an AI Chatbot Agent that can understand natural language commands and perform CRUD operations using the Ollama Gemma2 model.

Project structure

  • server.js: Backend REST API (Node.js + Express + MongoDB) for posts and comments.
  • public/: Frontend UI that talks to this backend (served by Express via express.static('public')).
  • mcp-server/: MCP server that wraps this backend and exposes it as MCP tools.
  • public/chatbot.html: AI chatbot interface for natural language interaction.

Setup

  1. Install backend dependencies

    npm install
    
  2. Set MongoDB connection for the backend

    # example
    export MONGO_URI="mongodb://localhost:27017/mcp-api"
    
  3. Install Ollama and the Gemma2 model

    # Install Ollama from https://ollama.com/
    # Then pull the Gemma2 model
    ollama pull gemma2:2b
    
  4. Start the backend server

    npm start
    

    Server runs on port 3002 (see PORT in server.js).

  5. Open the UI

    The UI is served from the public/ folder by Express. Once the backend is running, open:

    • http://localhost:3002/ in your browser for the main blog interface.
    • http://localhost:3002/chatbot.html for the AI chatbot interface.

Running the MCP server

The MCP server lives in the mcp-server/ folder and wraps this backend.

  1. Make sure the backend is running first

    From the project root:

    # in one terminal
    export MONGO_URI="mongodb://localhost:27017/mcp-api"
    npm start          # backend on http://localhost:3002
    
  2. Start the MCP server

    In a new terminal:

    cd mcp-server
    npm install        # first time only
    npm start
    

    By default:

    • Backend base URL: http://localhost:3002
    • MCP server port: 3001
    • MCP HTTP endpoint: POST http://localhost:3001/mcp
    • AI Chatbot endpoint: POST http://localhost:3001/ai-chatbot

AI Chatbot Agent

The AI Chatbot Agent is a new feature that allows users to interact with the blog system using natural language commands. It uses the Ollama Gemma2 model to understand user requests and map them to appropriate API actions.

Features

  1. Natural Language Processing: Understands user requests in plain English
  2. CRUD Operations: Can create, read, update, and delete posts and comments
  3. Context Awareness: Provides relevant context to the AI model
  4. Web Interface: User-friendly chat interface
  5. API Endpoint: Direct API access for integration

How It Works

  1. User sends a natural language request (e.g., "Create a new post about AI")
  2. The AI processes the request using the Ollama Gemma2 model
  3. The AI determines the appropriate action and parameters
  4. The system executes the corresponding API call
  5. Results are returned to the user in a conversational format

Example Commands

  • "Create a new post with title 'The Future of AI', author 'Tech Writer', category 'tech', and body 'Artificial intelligence is rapidly evolving...'"
  • "List all posts"
  • "Show me all posts in the tech category"
  • "Update post ID 12345 with a new title 'The Future of AI and Machine Learning'"
  • "Delete the post with ID 12345"
  • "Add a comment 'This is fascinating!' from 'Reader' to post ID 67890"
  • "List all comments for post ID 67890"

Web Interface

Navigate to http://localhost:3002/chatbot.html to access the AI chatbot interface. The interface includes:

  • Chat message display
  • Text input for commands
  • Example commands for quick access
  • Real-time responses from the AI

API Endpoint

You can also interact with the AI chatbot directly via the API:

curl -X POST http://localhost:3001/ai-chatbot \
  -H "Content-Type: application/json" \
  -d '{"message": "Create a new post about technology trends"}'

Response format:

{
  "action": "create_post",
  "explanation": "Creating a new post with the provided details",
  "result": {
    "_id": "67890",
    "title": "Technology Trends",
    "author": "AI Assistant",
    "category": "tech",
    "body": "This is a post about technology trends...",
    "createdAt": "2026-07-04T12:00:00.000Z"
  }
}

Validation

The API validates request bodies and returns clear error messages.

Post (create & update)

Field Rule Error (400)
title Required, min 5 characters "title is required" / "title must be at least 5 characters"
author Required, min 3 characters "author is required" / "author must be at least 3 characters"
category Required, one of: tech, finance, lifestyle "Invalid category"
body Required, min 50 characters "body is required" / "body must be at least 50 characters"
  • Missing required fields400 with a message describing what's wrong.
  • Invalid category400 with message "Invalid category".
  • Body shorter than 50 characters400.

Comment (create)

Field Rule Error (400)
text Required, min 10 characters "text is required" / "text must be at least 10 characters"
commenter Required "commenter is required"
  • Comment text shorter than 10 characters400.

Post not found

  • Invalid or non-existent post ID (e.g. for GET/PUT/DELETE /posts/:id or comment routes) → 404 with "Post not found".

All error responses use the shape: { "error": "<message>" }.


API Endpoints

Base URL: http://localhost:3002

Posts

Method Path Description Success
POST /posts Create a post (validated) 201 + created post
GET /posts List all posts 200 + array of posts
GET /posts/:id Get one post 200 + post, or 404
PUT /posts/:id Update a post (same validation) 200 + updated post, or 404
DELETE /posts/:id Delete a post (and its comments) 200 + { "message": "Post deleted" }, or 404

Comments

Method Path Description Success
POST /posts/:id/comments Add a comment to post 201 + created comment, or 404 if post not found
GET /posts/:id/comments List comments for post 200 + array of comments, or 404 if post not found

AI Chatbot

Method Path Description Success
POST /ai-chatbot Process natural language command 200 + action result

Request / Response Examples

Create a post

POST /posts
Content-Type: application/json

{
  "title": "Getting started with Node",
  "author": "Jane",
  "category": "tech",
  "body": "This is a longer body that meets the minimum length requirement of fifty characters."
}

201 + post object (includes _id, createdAt).

Create a comment

POST /posts/<postId>/comments
Content-Type: application/json

{
  "text": "Great post, very helpful!",
  "commenter": "Alex"
}

201 + comment object.

AI Chatbot Request

POST /ai-chatbot
Content-Type: application/json

{
  "message": "Create a new post about AI advancements"
}

200 + JSON response with action details.

Error response (validation)

{ "error": "Invalid category" }
{ "error": "body must be at least 50 characters" }

Error response (not found)

{ "error": "Post not found" }

Data Models (summary)

  • Post: title, author, category, body, createdAt (auto).
  • Comment: postId (reference to post), text, commenter, createdAt (auto).
  • IDs are MongoDB ObjectIds, auto-generated.

Use this README to walk through validation rules and the exposed API when explaining the project.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选