Skip to main content
Glama
hwqlet

MCP Product Search Server

by hwqlet

MCP Product Search Server

一个基于 Model Context Protocol (MCP) 的产品搜索服务器,让 Claude 能够根据关键词检索产品目录并返回结构化数据。

功能

提供三个工具供 Claude 调用:

工具

说明

search

按关键词搜索产品,支持分类、价格、评分过滤

list_categories

列出所有产品分类及数量

get_product

按 ID 查询单个产品的完整信息

Related MCP server: MCP Merchant Scout

快速开始

1. 克隆项目

git clone <your-repo-url>
cd mcp-product-search

2. 创建虚拟环境并安装依赖

macOS / Linux:

python3 -m venv .venv
source .venv/bin/activate
pip install "mcp[cli]"

Windows:

python -m venv .venv
.venv\Scripts\activate
pip install "mcp[cli]"

需要 Python 3.10 及以上版本。可用 python3 --version 检查。

3. 在浏览器中测试

mcp dev server.py

浏览器会自动打开 MCP Inspector。如果没有自动打开,手动访问终端输出的地址(通常是 http://localhost:6274)。

连接步骤:

  1. 将左侧 Command 改为虚拟环境中 Python 的绝对路径:

    • macOS/Linux:/绝对路径/mcp-product-search/.venv/bin/python

    • Windows:C:\绝对路径\mcp-product-search\.venv\Scripts\python.exe

  2. Arguments 填 server.py

  3. 点击 Connect,左下角显示 Connected 即成功

  4. 点击顶部 Tools 标签,选择工具,填写参数,点击 Run Tool

MCP Inspector 连接成功示意

4. 接入 Claude Desktop

找到配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

添加以下内容(替换为实际的绝对路径):

{
  "mcpServers": {
    "product-search": {
      "command": "/绝对路径/mcp-product-search/.venv/bin/python",
      "args": ["/绝对路径/mcp-product-search/server.py"]
    }
  }
}

查看当前目录的绝对路径:

# macOS / Linux
pwd

# Windows
cd

保存配置文件后,完全退出并重启 Claude Desktop。

5. 接入 Claude Code(命令行)

claude mcp add product-search \
  /绝对路径/mcp-product-search/.venv/bin/python \
  /绝对路径/mcp-product-search/server.py

使用示例

接入 Claude 后,可以这样提问:

帮我搜索苹果品牌的笔记本电脑
找一款评分 4.8 以上、价格不超过 300 美元的耳机
列出所有产品分类
查询产品 P003 的详细信息

Claude 会自动判断调用哪个工具,并基于返回的结构化数据给出回答。

工具参数说明

参数

类型

必填

默认值

说明

keyword

string

是

—

匹配产品名称、描述、品牌、分类和标签

category

string

否

—

按分类过滤,如 "Laptops"、"Headphones"

max_price

float

否

—

最高价格(USD)

min_rating

float

否

—

最低评分(0–5)

limit

int

否

10

返回结果数量上限(最多 50)

返回结果按评分从高到低、价格从低到高排序。

返回示例:

{
  "keyword": "apple",
  "filters": { "category": "Laptops", "max_price": null, "min_rating": null },
  "total_results": 1,
  "products": [
    {
      "id": "P001",
      "name": "Apple MacBook Pro 14-inch M3",
      "category": "Laptops",
      "brand": "Apple",
      "price": 1999.0,
      "currency": "USD",
      "stock": 42,
      "rating": 4.8,
      "description": "14-inch Liquid Retina XDR display, M3 chip, 18GB RAM, 512GB SSD.",
      "tags": ["laptop", "apple", "macbook", "m3", "professional", "portable"]
    }
  ]
}

list_categories

无参数。返回所有分类名称及对应产品数量。

get_product

参数

类型

必填

说明

product_id

string

是

产品 ID,如 "P001"(不区分大小写)

项目结构

mcp-product-search/
├── server.py        # MCP 服务器,定义工具
├── products.py      # 产品目录与搜索逻辑
├── pyproject.toml   # 项目依赖
└── README.md

扩展产品数据

当前产品目录是写在 products.py 中的 12 条示例数据,替换为真实数据只需修改 search_products() 函数,server.py 无需改动。

数据来源

改法

本地 JSON/CSV

启动时读文件填充 CATALOG

SQLite / PostgreSQL

用 SQL 查询替换遍历逻辑

电商 API

函数内部发 HTTP 请求

Elasticsearch

调用 ES 全文搜索接口

Available Tools

3 tools
get_productA

Retrieve full details for a single product by its ID (e.g. "P001").

Args: product_id: The product's unique identifier.

ParametersJSON Schema
NameRequiredDescriptionDefault
product_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist; description implies read-only but fails to disclose any behavioral details beyond 'retrieve'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise, front-loading the core purpose and listing the parameter clearly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple single-parameter input and presence of an output schema, the description is sufficiently complete for the task.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaning to the product_id parameter with an example and context, compensating for 0% schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it retrieves full details for a single product by ID, distinguishing it from siblings like list_categories and search.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus siblings like search or list_categories is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_categoriesA

Return all available product categories and their item counts.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.7/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description only states the basic return value, omitting additional behavioral details such as ordering, limits, or side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, clear sentence with no unnecessary words, perfectly front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read operation with no parameters and an output schema present, the description sufficiently covers what the tool returns.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Since there are no parameters, the description does not need to add parameter information. Baseline 4 for 0 parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the verb 'Return' and resource 'all available product categories and their item counts', distinguishing it from sibling tools like 'get_product' and 'search'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'search' or 'get_product', leaving the agent to infer context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.1.0
    • First observedget_product
    • First observedlist_categories
    • First observedsearch

TDQS

A4.1/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a distinct purpose: get_product retrieves by ID, list_categories returns category overview, search does keyword-based filtering. No ambiguity in their roles.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (get_product, list_categories, search) using snake_case, making them predictable.

Tool Count5/5

With 3 tools, the server is well-scoped for a search-focused service. Each tool earns its place without bloat or deficiency.

Completeness4/5

The tool set covers core search and retrieval operations (get by ID, list categories, keyword search). Missing a general 'list all products' operation, but search likely covers this with an empty keyword, though not documented; minor gap.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables users to search for products, retrieve details, and manage their shopping cart on Amazon through the MCP framework. It also supports viewing order history and provides a demonstration of ordering capabilities within AI interfaces.
    21 npm
    54
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that wraps the Universal Commerce Protocol (UCP) Discovery and Catalog capabilities, letting you search and compare products across UCP merchants directly from Claude.
    4
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables product comparison and analysis for any MCP-compatible AI assistant, with tools like compare_products and list_products.
    -